made the workflow cleaner
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
name: Build and Push Docker Image
|
||||
name: Build and Publish Docker Image
|
||||
|
||||
on:
|
||||
push:
|
||||
@@ -7,44 +7,49 @@ on:
|
||||
tags:
|
||||
- 'v*'
|
||||
|
||||
env:
|
||||
REGISTRY: git.home.db123.ir
|
||||
NAMESPACE: db1234719
|
||||
IMAGE_NAME: nginx-alpine
|
||||
|
||||
jobs:
|
||||
build:
|
||||
build-and-push:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
fetch-tags: true
|
||||
|
||||
- name: Set version
|
||||
id: vars
|
||||
- name: Determine version
|
||||
id: version
|
||||
shell: bash
|
||||
run: |
|
||||
if [ -n "$GIT_TAG" ]; then
|
||||
VERSION="$GIT_TAG"
|
||||
if [[ "${GITHUB_REF}" =~ ^refs/tags/v(.+) ]]; then
|
||||
VERSION="${BASH_REMATCH[1]}"
|
||||
else
|
||||
VERSION="latest"
|
||||
fi
|
||||
echo "version=$VERSION" >> $GITHUB_OUTPUT
|
||||
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Build image
|
||||
run: docker build -t zxc .
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Login to Gitea registry
|
||||
run: |
|
||||
echo "${{ secrets.CICD_PASSWORD }}" | docker login git.home.db123.ir -u username --password-stdin
|
||||
- name: Login to registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ env.NAMESPACE }}
|
||||
password: ${{ secrets.CICD_TOKEN }}
|
||||
|
||||
|
||||
- name: Tag image
|
||||
run: |
|
||||
docker tag zxc git.home.db123.ir/username/zxc:latest
|
||||
if [ "$VERSION" != "latest" ]; then
|
||||
docker tag zxc git.home.db123.ir/username/zxc:$VERSION
|
||||
fi
|
||||
|
||||
- name: Push images
|
||||
run: |
|
||||
docker push git.home.db123.ir/username/zxc:latest
|
||||
if [ "$VERSION" != "latest" ]; then
|
||||
docker push git.home.db123.ir/username/zxc:$VERSION
|
||||
fi
|
||||
- name: Build & push Docker image
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: .
|
||||
file: ./Dockerfile
|
||||
push: true
|
||||
tags: |
|
||||
${{ env.REGISTRY }}/${{ env.NAMESPACE }}/{{ env.IMAGE_NAME }}:latest
|
||||
${{ env.REGISTRY }}/${{ env.NAMESPACE }}/{{ env.IMAGE_NAME }}:${{ steps.version.outputs.VERSION }}
|
||||
|
||||
Reference in New Issue
Block a user