Skip to content

k

k #75

name: Build and Push Docker Image
on:
push:
branches:
- "**" # Triggers on all branches
tags:
- "v*.*.*" # Triggers on tag push for versioned tags (e.g., v1.0.0)
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to Quay.io (only if pushing)
if: startsWith(github.ref, 'refs/tags/')
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login quay.io -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
- name: Get tag or commit SHA
id: vars
run: |
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
echo "image_tag=${{ github.ref_name }}" >> $GITHUB_ENV
else
echo "image_tag=${{ github.sha }}" >> $GITHUB_ENV
fi
- name: Build Docker Image
run: docker build . -t fleet-telemetry-consumer:${{ env.image_tag }}
- name: Tag Docker Image (only if pushing)
if: startsWith(github.ref, 'refs/tags/')
run: docker tag fleet-telemetry-consumer:${{ env.image_tag }} quay.io/rajsinghcpre/fleet-telemetry-consumer:${{ env.image_tag }}
- name: Push Docker Image (only if pushing)
if: startsWith(github.ref, 'refs/tags/')
run: docker push quay.io/rajsinghcpre/fleet-telemetry-consumer:${{ env.image_tag }}
- name: Update Deployment Image Tag (only if pushing)
if: startsWith(github.ref, 'refs/tags/')
run: |
sed -i "s|quay.io/rajsinghcpre/fleet-telemetry-consumer:.*|quay.io/rajsinghcpre/fleet-telemetry-consumer:${{ env.image_tag }}|" kustomization/fleet-telemetry-consumer/deployment.yaml
- name: Commit and Push Changes (only if pushing)
if: startsWith(github.ref, 'refs/tags/')
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "Update image tag to ${{ env.image_tag }}"
file_pattern: kustomization/fleet-telemetry-consumer/deployment.yaml