Build and Publish Docker image #16
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: | |
workflow_dispatch: | |
push: | |
branches: [ master ] | |
paths: | |
- 'Dockerfile' | |
env: | |
DOCKER_HUB_TAG: ${{ secrets.DOCKER_HUB_USERNAME }}/qemu-ga | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
# Login against a Docker registry | |
# https://github.com/docker/login-action | |
- name: Log into Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | |
# Build and to Docker | |
# https://github.com/docker/build-push-action | |
- name: Build docker image | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
load: true | |
tags: ${{ env.DOCKER_HUB_TAG }}:getversion | |
# Get version of qemu-ga in built container | |
- name: Get qemu-ga version | |
run: > | |
echo "QEMU_GA_VERSION=$( | |
docker run --rm | |
${{ env.DOCKER_HUB_TAG }}:getversion | |
qemu-ga --version | | |
grep -Po --color=never '\d+\.*\d*\.*\d*$')" >> $GITHUB_ENV | |
- name: Docker meta tags | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.DOCKER_HUB_TAG }} | |
tags: | | |
type=raw,value=${{ env.QEMU_GA_VERSION }} | |
flavor: | | |
latest=true | |
# Build and push image using qemu-ga version as tag | |
- name: Build and push | |
uses: docker/build-push-action@v6 | |
with: | |
platforms: linux/amd64,linux/arm64 | |
context: . | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} |