Build and Publish Docker Image #51
This file contains 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 Publish Docker Image | |
on: | |
push: | |
branches: | |
- main | |
workflow_dispatch: | |
inputs: | |
ref: | |
description: 'Git reference to checkout (branch, tag, or SHA)' | |
required: true | |
default: 'main' | |
stable_release: | |
description: 'Mark this build as a stable release' | |
required: false | |
default: 'false' | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event.inputs.ref || github.ref }} | |
- name: Get current commit SHA | |
id: current_sha | |
run: echo "::set-output name=sha::$(git rev-parse HEAD)" | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ vars.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
- name: Set Docker image tags | |
id: tags | |
run: | | |
TAGS="${{ vars.DOCKERHUB_USERNAME }}/${{ vars.DOCKERHUB_REPOSITORY }}:${{ steps.current_sha.outputs.sha }}" | |
if [[ "${{ github.ref }}" == "refs/heads/main" || "${{ github.event.inputs.ref }}" == "main" ]]; then | |
TAGS="$TAGS,${{ vars.DOCKERHUB_USERNAME }}/${{ vars.DOCKERHUB_REPOSITORY }}:latest" | |
fi | |
if [[ "${{ github.event.inputs.stable_release }}" == "true" ]]; then | |
TAGS="$TAGS,${{ vars.DOCKERHUB_USERNAME }}/${{ vars.DOCKERHUB_REPOSITORY }}:stable" | |
fi | |
echo "::set-output name=tags::$TAGS" | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: Dockerfile.validator | |
push: true | |
tags: ${{ steps.tags.outputs.tags }} |