Build and Publish Docker Images #22
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 Images | |
on: | |
workflow_dispatch: | |
inputs: | |
build_all: | |
description: 'Build all steps (includes main build unless skipped)' | |
type: boolean | |
default: false | |
build_base: | |
description: 'Build base image' | |
type: boolean | |
default: false | |
build_build: | |
description: 'Build build image' | |
type: boolean | |
default: false | |
build_sm: | |
description: 'Build SM image' | |
type: boolean | |
default: false | |
skip_release_main_build: | |
description: 'Skip release of a main build' | |
type: boolean | |
default: false | |
release_as_latest: | |
description: 'Release as latest' | |
type: boolean | |
default: false | |
permissions: | |
contents: read | |
packages: write | |
env: | |
REGISTRY: ghcr.io | |
BASE_IMAGE_NAME: ${{ github.repository_owner }}/streammaster-builds | |
FINAL_IMAGE_NAME: ${{ github.repository_owner }}/streammaster | |
jobs: | |
setup: | |
runs-on: ubuntu-latest | |
outputs: | |
version: ${{ steps.gitversion.outputs.semVer }} | |
branchName: ${{ steps.gitversion.outputs.branchName }} | |
buildMeta: ${{ steps.gitversion.outputs.buildMetadata }} | |
build_base: ${{ inputs.build_base || inputs.build_all }} | |
build_build: ${{ inputs.build_build || inputs.build_all }} | |
build_sm: ${{ inputs.build_sm || inputs.build_all }} | |
skip_main_build: ${{ inputs.skip_main_build }} | |
release_as_latest: ${{ inputs.release_as_latest }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Install GitVersion | |
uses: gittools/actions/gitversion/setup@v0 | |
with: | |
versionSpec: "5.x" | |
- name: Determine Version | |
id: gitversion | |
uses: gittools/actions/gitversion/execute@v0 | |
build: | |
needs: setup | |
runs-on: ubuntu-latest | |
env: | |
VERSION: ${{ needs.setup.outputs.version }} | |
BRANCH_NAME: ${{ needs.setup.outputs.branchName }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Login to GHCR | |
uses: docker/login-action@v2 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Base - Build and Push | |
if: ${{ needs.setup.outputs.build_base == 'true' }} | |
run: | | |
docker buildx build --platform linux/amd64,linux/arm64 -t ${{ env.REGISTRY }}/${{ env.BASE_IMAGE_NAME }}:${{ env.VERSION }}-base -f Dockerfile.base --push . | |
echo "${{ env.VERSION }}" > basever | |
uses: actions/upload-artifact@v4 | |
with: | |
name: basever | |
path: basever | |
- name: Build - Build and Push | |
if: ${{ needs.setup.outputs.build_build == 'true' }} | |
run: | | |
docker buildx build --platform linux/amd64,linux/arm64 -t ${{ env.REGISTRY }}/${{ env.BASE_IMAGE_NAME }}:${{ env.VERSION }}-build -f Dockerfile.build --push . | |
echo "${{ env.VERSION }}" > buildver | |
uses: actions/upload-artifact@v4 | |
with: | |
name: buildver | |
path: buildver | |
- name: SM -Build and Push | |
if: ${{ needs.setup.outputs.build_sm == 'true' }} | |
run: | | |
set -e | |
echo "FROM --platform=\$BUILDPLATFORM ${{ env.REGISTRY }}/${{ env.BASE_IMAGE_NAME }}:${{ env.VERSION }}-build AS build" > Dockerfile.sm | |
cat Dockerfile.sm.template >> Dockerfile.sm | |
docker buildx build --platform linux/amd64,linux/arm64 -t ${{ env.REGISTRY }}/${{ env.BASE_IMAGE_NAME }}:${{ env.VERSION }}-sm -f Dockerfile.sm --push . | |
echo "${{ env.VERSION }}" > smver | |
uses: actions/upload-artifact@v4 | |
with: | |
name: smver | |
path: smver | |
- name: Final - Build and Push | |
if: ${{ needs.setup.outputs.skip_release_main_build != 'true' }} | |
run: | | |
set -e | |
echo "FROM ${{ env.REGISTRY }}/${{ env.BASE_IMAGE_NAME }}:${{ env.VERSION }}-sm AS sm" > Dockerfile | |
echo "FROM ${{ env.REGISTRY }}/${{ env.BASE_IMAGE_NAME }}:${{ env.VERSION }}-base AS base" >> Dockerfile | |
cat Dockerfile.template >> Dockerfile | |
docker buildx build --platform linux/amd64,linux/arm64 -t ${{ env.REGISTRY }}/${{ env.FINAL_IMAGE_NAME }}:${{ env.VERSION }} -t ${{ env.REGISTRY }}/${{ env.FINAL_IMAGE_NAME }}:${{ needs.setup.outputs.release_as_latest == 'true' && 'latest' || env.BRANCH_NAME }} -f Dockerfile --push . |