name: Build and Publish Docker Image on: push: branches: - main tags: - "v*" env: REGISTRY: git.home.db123.ir NAMESPACE: db1234719 IMAGE_NAME: nginx-alpine jobs: build-and-push: runs-on: ubuntu-24.04 steps: - name: Checkout code uses: actions/checkout@v4 with: fetch-depth: 1 fetch-tags: true - name: Determine version id: version shell: bash run: | if [[ "${GITHUB_REF}" =~ ^refs/tags/v(.+) ]]; then VERSION="${BASH_REMATCH[1]}" else VERSION="latest" fi echo "VERSION=$VERSION" >> $GITHUB_OUTPUT - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Login to registry uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ env.NAMESPACE }} password: ${{ secrets.CICD_PASSWORD }} - name: Build & push Docker image id: build uses: docker/build-push-action@v6 with: context: . file: ./Dockerfile push: true platforms: linux/amd64 tags: | ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}:latest ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.VERSION }} cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}:cache cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}:cache,mode=max - name: Notify build result if: always() run: | if [ "${{ steps.build.outcome }}" = "success" ]; then curl -s -S -u "server:VKbpgw75KB0biM" \ -d "build & push succeeded ✅" \ https://ntfy.home.db123.ir/build else curl -s -S -u "server:VKbpgw75KB0biM" \ -d "build & push FAILED ❌" \ https://ntfy.home.db123.ir/build fi