Skip to content

Build & Push Docker Images #20

Build & Push Docker Images

Build & Push Docker Images #20

Workflow file for this run

name: docker-deploy
run-name: Build & Push Docker Images
on:
workflow_dispatch:
inputs:
gradle_debug_params:
description: 'Gradle debug parameters'
default: ''
required: false
type: string
image_tag:
description: 'Docker Image Tag'
default: 'latest'
required: true
type: string
platforms:
description: 'Build platforms (architectures)'
default: 'linux/amd64,linux/arm64'
required: true
type: choice
options:
- linux/amd64,linux/arm64
- linux/amd64
- linux/arm64
workflow_call:
inputs:
image_tag:
description: 'Docker Image Tag'
default: 'latest'
required: true
type: string
permissions:
contents: read
jobs:
detect-version:
runs-on: 'ubuntu-latest'
steps:
- uses: actions/checkout@v3
- name: Detect Version
id: detect-version
run: |
appVersion="$(grep -E '^[0-9]+\.[0-9]+\.[0-9]+' .VERSION)"
echo "Application version: ${appVersion}"
echo "app_version=$(echo "${appVersion}")" >> "$GITHUB_OUTPUT"
outputs:
app_version: ${{ steps.detect-version.outputs.app_version }}
set-matrix:
runs-on: ubuntu-latest
outputs:
arch-matrix: ${{ steps.set-matrix.outputs.arch-matrix }}
steps:
- name: Set matrix based on input
id: set-matrix
shell: bash
run: |
platforms="${{ github.event.inputs.platforms }}"
archs=$(echo '["'${platforms//,/\",\"}'"]')
echo "arch-matrix=$archs" >> "$GITHUB_OUTPUT"
build-docker-images:
needs:
- detect-version
- set-matrix
strategy:
matrix:
os:
- "ubuntu-latest"
docker-container:
- "ubuntu"
- "fedora"
- "centos"
- "alpine"
arch: ${{ fromJSON(needs.set-matrix.outputs.arch-matrix) }}
runs-on: ${{ matrix.os }}
environment: homesetup
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
IMAGE_TAG: ${{ inputs.image_tag || needs.detect-version.outputs.app_version }}
steps:
- name: Print matrix
run: |
echo "Building for OS: ${{ matrix.os }}, Docker: ${{ matrix.docker-container }}, Arch: ${{ matrix.arch }}"
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
with:
python-version: ${{ vars.PYTHON_VERSION }}
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ env.DOCKERHUB_USERNAME }}
password: ${{ env.DOCKERHUB_TOKEN }}
- name: Set up Architecture tag
run: |
arch="${{ matrix.arch }}"
arch_tag="${arch#*/}"
echo "ARCH=$arch_tag" >> "$GITHUB_ENV"
- name: Build and Push
uses: docker/setup-buildx-action@v2
with:
platforms: "${{ inputs.platforms }}"
context: "docker/${{ matrix.docker-container }}"
file: "docker/${{ matrix.docker-container }}/Dockerfile"
push: true
tags: "${{ env.DOCKERHUB_USERNAME }}/hhs-${{ matrix.docker-container }}:${{ env.ARCH }}-${{ env.IMAGE_TAG }}"