Build and push Docker images #54
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 push Docker images | |
on: | |
workflow_dispatch: | |
inputs: | |
language: | |
description: The image language | |
required: true | |
default: php | |
type: | |
description: The image type | |
required: true | |
default: 8.3-unit | |
version: | |
description: The version in semver format (e.g. "1.2.3") | |
required: true | |
jobs: | |
build: | |
name: Build Docker images 68publishers/${{ github.event.inputs.language }}:${{ github.event.inputs.type }} for platform ${{ matrix.platform }} | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
platform: | |
- linux/amd64 | |
- linux/arm64/v8 | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Create build arguments | |
run: > | |
echo "BUILD_ARGS=$(jq --null-input -c | |
--arg username "$DOCKERHUB_USERNAME" | |
--arg token "$DOCKERHUB_TOKEN" | |
--arg context "$BUILD_CONTEXT" | |
--arg dockerfile "$BUILD_DOCKERFILE" | |
--arg platform "$BUILD_PLATFORM" | |
--arg version "$BUILD_VERSION" | |
--arg image "$BUILD_IMAGE" | |
'{ | |
"dockerhub-username": $username, | |
"dockerhub-token": $token, | |
"build-context": $context, | |
"build-dockerfile": $dockerfile, | |
"build-platform": $platform, | |
"build-version": $version, | |
"build-image": $image | |
}')" >> $GITHUB_ENV | |
env: | |
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} | |
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} | |
BUILD_CONTEXT: ./${{ github.event.inputs.language }}/${{ github.event.inputs.type }}/ | |
BUILD_DOCKERFILE: ./${{ github.event.inputs.language }}/${{ github.event.inputs.type }}/Dockerfile | |
BUILD_PLATFORM: ${{ matrix.platform }} | |
BUILD_VERSION: ${{ github.event.inputs.version }} | |
BUILD_IMAGE: 68publishers/${{ github.event.inputs.language }} | |
- name: Build Docker images | |
if: ${{ 'php' == github.event.inputs.language && '7.4-unit' == github.event.inputs.type}} | |
uses: ./.github/actions/build-php-7.4-unit | |
with: ${{ fromJson(env.BUILD_ARGS) }} | |
- name: Build Docker images | |
if: ${{ 'php' == github.event.inputs.language && '8.1-unit' == github.event.inputs.type}} | |
uses: ./.github/actions/build-php-8.1-unit | |
with: ${{ fromJson(env.BUILD_ARGS) }} | |
- name: Build Docker images | |
if: ${{ 'php' == github.event.inputs.language && '8.1-cli' == github.event.inputs.type}} | |
uses: ./.github/actions/build-php-8.1-cli | |
with: ${{ fromJson(env.BUILD_ARGS) }} | |
- name: Build Docker images | |
if: ${{ 'php' == github.event.inputs.language && '8.3-unit' == github.event.inputs.type}} | |
uses: ./.github/actions/build-php-8.3-unit | |
with: ${{ fromJson(env.BUILD_ARGS) }} | |
- name: Build Docker images | |
if: ${{ 'php' == github.event.inputs.language && '8.3-cli' == github.event.inputs.type}} | |
uses: ./.github/actions/build-php-8.3-cli | |
with: ${{ fromJson(env.BUILD_ARGS) }} | |
merge: | |
runs-on: ubuntu-latest | |
needs: | |
- build | |
steps: | |
- name: Download digests | |
uses: actions/download-artifact@v3 | |
with: | |
name: digests | |
path: /tmp/digests | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Create manifest list and push | |
working-directory: /tmp/digests/images | |
run: > | |
for DIR in *; | |
do | |
cd "$DIR" && docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< cat "/tmp/digests/outputs/$DIR") $(printf "$IMAGE@sha256:%s " *) && cd .. | |
done | |
env: | |
IMAGE: 68publishers/${{ github.event.inputs.language }} |