Build and Push Docker image to Docker Hub #10
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
# Builds a docker image. | |
# Tag pattern | |
# 'main' - latest | |
name: Build and Push Docker image to Docker Hub | |
on: | |
workflow_dispatch: | |
# release: | |
# types: [published] | |
# push: | |
# branches: | |
# - main | |
env: | |
DOCKER_PLATFORMS: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64 | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set DACQUERY_BRANCH env. | |
run: echo "DACQUERY_BRANCH=${GITHUB_REF##*/}" >> $GITHUB_ENV | |
- name: Is branch "main"? | |
if: ${{ env.DACQUERY_BRANCH == 'main' }} | |
run: | | |
echo "IMAGE_TAG_BASE=latest" >> $GITHUB_ENV | |
- name: Is branch "experimental"? | |
if: ${{ env.DACQUERY_BRANCH == 'experimental' }} | |
run: | | |
echo "IMAGE_TAG_BASE=experimental" >> $GITHUB_ENV | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to Docker Registry | |
uses: docker/[email protected] | |
with: | |
username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
password: ${{ secrets.DOCKER_HUB_PERSONAL_ACCESS_TOKEN }} | |
- name: Docker Build and Push | |
uses: docker/build-push-action@v6 | |
with: | |
context: ./ | |
file: ./Dockerfile | |
platforms: ${{ env.DOCKER_PLATFORMS }} | |
push: ${{ env.IMAGE_TAG_BASE != '' }} | |
tags: ${{ 'mikebrady/dacquery' }}:${{ env.IMAGE_TAG_BASE }} | |
build-args: | | |
DACQUERY_BRANCH=${{ env.DACQUERY_BRANCH }} |