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