try this #114
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login quay.io -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin | |
- name: Get tag or branch name | |
id: vars | |
run: | | |
if [[ "${{ github.ref }}" == refs/tags/* ]]; then | |
echo "image_tag=${{ github.ref_name }}" >> $GITHUB_ENV | |
else | |
# Get branch name and replace / with - for Docker tag compatibility | |
BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/} | sed 's/\//-/g') | |
echo "image_tag=${BRANCH_NAME}" >> $GITHUB_ENV | |
fi | |
- name: Build and Push Docker Image | |
run: | | |
docker build . -t fleet-telemetry-consumer:${{ env.image_tag }} | |
docker tag fleet-telemetry-consumer:${{ env.image_tag }} quay.io/rajsinghcpre/fleet-telemetry-consumer:${{ env.image_tag }} | |
docker push quay.io/rajsinghcpre/fleet-telemetry-consumer:${{ env.image_tag }} |