From 3f202be09a605da64aa7a23f53a89558185e51a5 Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Sun, 22 Jan 2023 09:53:42 -0500 Subject: [PATCH] docker build dependent on event type (#812) --- .github/workflows/ci-docker.yml | 19 +++++++++++++++++-- docker/debian-bullseye.dockerfile | 2 ++ docker/fedora-36.dockerfile | 2 ++ docker/fedora-37.dockerfile | 2 ++ docker/ubuntu-18.04.dockerfile-todo | 2 ++ docker/ubuntu-20.04.dockerfile | 2 ++ docker/ubuntu-22.04.dockerfile | 2 ++ 7 files changed, 29 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-docker.yml b/.github/workflows/ci-docker.yml index f67f312a..48f9c8cb 100644 --- a/.github/workflows/ci-docker.yml +++ b/.github/workflows/ci-docker.yml @@ -11,6 +11,9 @@ # `# platforms: ` # Comma separated list of platforms, i.e. `# platforms: linux/386,linux/amd64`. Docker platforms can alternatively # be listed in a file named `.docker_platforms`. +# `# platforms_pr: ` +# Comma separated list of platforms to run for PR events, i.e. `# platforms_pr: linux/amd64`. This will take +# precedence over the `# platforms: ` directive. # `# artifacts: ` # `true` to build in two steps, stopping at `artifacts` build stage and extracting the image from there to the # GitHub runner. @@ -202,8 +205,7 @@ jobs: # get branch name BRANCH=${GITHUB_HEAD_REF} - if [ -z "$BRANCH" ] - then + if [ -z "$BRANCH" ]; then echo "This is a PUSH event" BRANCH=${{ github.ref_name }} fi @@ -237,6 +239,19 @@ jobs: # parse custom directives out of dockerfile # try to get the platforms from the dockerfile custom directive, i.e. `# platforms: xxx,yyy` + # directives for PR event, i.e. not push event + if [[ ${PUSH} == "false" ]]; then + while read -r line; do + if [[ $line == "# platforms_pr: "* && $PLATFORMS == "" ]]; then + # echo the line and use `sed` to remove the custom directive + PLATFORMS=$(echo -e "$line" | sed 's/# platforms_pr: //') + elif [[ $PLATFORMS != "" ]]; then + # break while loop once all custom "PR" event directives are found + break + fi + done <"${{ matrix.dockerfile }}" + fi + # directives for all events... above directives will not be parsed if they were already found while read -r line; do if [[ $line == "# platforms: "* && $PLATFORMS == "" ]]; then # echo the line and use `sed` to remove the custom directive diff --git a/docker/debian-bullseye.dockerfile b/docker/debian-bullseye.dockerfile index fd0c3753..893409f8 100644 --- a/docker/debian-bullseye.dockerfile +++ b/docker/debian-bullseye.dockerfile @@ -1,5 +1,7 @@ +# syntax=docker/dockerfile:1.4 # artifacts: true # platforms: linux/amd64,linux/arm64/v8 +# platforms_pr: linux/amd64 ARG BASE=debian ARG TAG=bullseye FROM ${BASE}:${TAG} AS sunshine-base diff --git a/docker/fedora-36.dockerfile b/docker/fedora-36.dockerfile index f566db75..30c215f8 100644 --- a/docker/fedora-36.dockerfile +++ b/docker/fedora-36.dockerfile @@ -1,5 +1,7 @@ +# syntax=docker/dockerfile:1.4 # artifacts: true # platforms: linux/amd64,linux/arm64/v8 +# platforms_pr: linux/amd64 ARG BASE=fedora ARG TAG=36 FROM ${BASE}:${TAG} AS sunshine-base diff --git a/docker/fedora-37.dockerfile b/docker/fedora-37.dockerfile index 7312e95f..f71837a1 100644 --- a/docker/fedora-37.dockerfile +++ b/docker/fedora-37.dockerfile @@ -1,5 +1,7 @@ +# syntax=docker/dockerfile:1.4 # artifacts: true # platforms: linux/amd64,linux/arm64/v8 +# platforms_pr: linux/amd64 ARG BASE=fedora ARG TAG=37 FROM ${BASE}:${TAG} AS sunshine-base diff --git a/docker/ubuntu-18.04.dockerfile-todo b/docker/ubuntu-18.04.dockerfile-todo index 2425aaac..5e905fbd 100644 --- a/docker/ubuntu-18.04.dockerfile-todo +++ b/docker/ubuntu-18.04.dockerfile-todo @@ -1,5 +1,7 @@ +# syntax=docker/dockerfile:1.4 # artifacts: true # platforms: linux/amd64,linux/arm64/v8 +# platforms_pr: linux/amd64 ARG BASE=ubuntu ARG TAG=18.04 FROM ${BASE}:${TAG} AS sunshine-base diff --git a/docker/ubuntu-20.04.dockerfile b/docker/ubuntu-20.04.dockerfile index 8aeca6dd..0a5d0907 100644 --- a/docker/ubuntu-20.04.dockerfile +++ b/docker/ubuntu-20.04.dockerfile @@ -1,5 +1,7 @@ +# syntax=docker/dockerfile:1.4 # artifacts: true # platforms: linux/amd64,linux/arm64/v8 +# platforms_pr: linux/amd64 ARG BASE=ubuntu ARG TAG=20.04 FROM ${BASE}:${TAG} AS sunshine-base diff --git a/docker/ubuntu-22.04.dockerfile b/docker/ubuntu-22.04.dockerfile index 18053816..d2a85be4 100644 --- a/docker/ubuntu-22.04.dockerfile +++ b/docker/ubuntu-22.04.dockerfile @@ -1,5 +1,7 @@ +# syntax=docker/dockerfile:1.4 # artifacts: true # platforms: linux/amd64,linux/arm64/v8 +# platforms_pr: linux/amd64 ARG BASE=ubuntu ARG TAG=22.04 FROM ${BASE}:${TAG} AS sunshine-base