Skip to content

Commit

Permalink
Add multi-platform support and restructure CI job generation (#3)
Browse files Browse the repository at this point in the history
* generate-jobs.sh

* Use generate-jobs.sh and test multi-platform build

* Download libraries for generate-jobs

* Generate-jobs still needs bashbrew

* Test filtering out arm32v5

* Specify command to run for test-image

* Transform arches to add linux prefix

* Don't need to download bashbrew sources anymore

* Transform v to /v in arches

* Download jq-template.awk from bashbrew

* Fix apply-template.sh

* Repalce "arm32" with "arm" in arches

* Remove redundant test CI steps, move multi-platform build to main branch CI

* Delete version-ci-json.lock no longer needed
  • Loading branch information
AaronMcHale authored Dec 17, 2023
1 parent a34953d commit 5392906
Show file tree
Hide file tree
Showing 8 changed files with 308 additions and 73 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: docker-library/bashbrew@HEAD
- name: Download libraries
run: ./download-libs.sh
- id: generate-jobs
name: Generate Jobs
run: |
strategy="$(cat versions-ci-json.lock)"
strategy="$(./generate-jobs.sh)"
echo "strategy=$strategy" >> "$GITHUB_OUTPUT"
jq . <<<"$strategy" # sanity check / debugging aid
27 changes: 12 additions & 15 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,23 @@ jobs:
needs: common
strategy: ${{ fromJson(needs.common.outputs.strategy) }}
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
runs-on: ubuntu-latest
environment: publishing
steps:
- uses: actions/checkout@v3
- name: Prepare Environment
run: ${{ matrix.runs.prepare }}
- name: Pull Dependencies
run: ${{ matrix.runs.pull }}
- name: Build ${{ matrix.name }}
run: ${{ matrix.runs.build }}
- name: History ${{ matrix.name }}
run: ${{ matrix.runs.history }}
- name: Test ${{ matrix.name }}
run: ${{ matrix.runs.test }}
- name: '"docker images"'
run: ${{ matrix.runs.images }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Push ${{ matrix.name }}
run: docker push --all-tags aaronmchale/drupal-php
- name: Build and push
uses: docker/build-push-action@v5
with:
context: ${{ matrix.dir }}
platforms: ${{ matrix.arches }}
push: true
tags: ${{ matrix.tags }}
21 changes: 8 additions & 13 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,13 @@ jobs:
needs: common
strategy: ${{ fromJson(needs.common.outputs.strategy) }}
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Prepare Environment
run: ${{ matrix.runs.prepare }}
- name: Pull Dependencies
run: ${{ matrix.runs.pull }}
- name: Build ${{ matrix.name }}
run: ${{ matrix.runs.build }}
- name: History ${{ matrix.name }}
run: ${{ matrix.runs.history }}
- name: Test ${{ matrix.name }}
run: ${{ matrix.runs.test }}
- name: '"docker images"'
run: ${{ matrix.runs.images }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build image
uses: docker/build-push-action@v5
with:
context: ${{ matrix.dir }}
tags: ${{ matrix.tags }}
35 changes: 8 additions & 27 deletions apply-templates.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@
# Based on apply-templates.sh in lib/php
set -Eeuo pipefail

if [ ! -f lib/php/versions.json ] || [ ! -f lib/bashbrew/scripts/jq-template.awk ]; then
if [ ! -f lib/php/versions.json ]; then
echo "Cannot find library files to copy from, run ./download-libs.sh"
exit 1
fi

# Get the latest files from lib
cp -f lib/php/versions.json .
cp -f lib/bashbrew/scripts/jq-template.awk .jq-template.awk

jqt='.jq-template.awk'
if [ -n "${BASHBREW_SCRIPTS:-}" ]; then
jqt="$BASHBREW_SCRIPTS/jq-template.awk"
elif [ "$BASH_SOURCE" -nt "$jqt" ]; then
# https://github.com/docker-library/bashbrew/blob/master/scripts/jq-template.awk
wget -qO "$jqt" 'https://github.com/docker-library/bashbrew/raw/9f6a35772ac863a0241f147c820354e4008edf38/scripts/jq-template.awk'
fi

if [ "$#" -eq 0 ]; then
versions="$(jq -r 'keys | map(@sh) | join(" ")' versions.json)"
Expand Down Expand Up @@ -66,28 +72,3 @@ for version; do
} > "$version/$dir/Dockerfile"
done
done

# Generate JSON for CI jobs using upstream generate.sh script. We use the
# upstream php library to generate the JSON. We need to ensure that the
# GITHUB_REPOSITORY environment variable is set appropriately, then re-set
# it once we're done.
echo "Generate JSON structure for CI jobs..."
cd lib/php
if env | grep -q "GITHUB_REPOSITORY="; then
temp_GITHUB_REPOSITORY="$GITHUB_REPOSITORY"
export GITHUB_REPOSITORY="docker-library/php"
strategy="$("../bashbrew/scripts/github-actions/generate.sh")"
export GITHUB_REPOSITORY="$temp_GITHUB_REPOSITORY"
else
export GITHUB_REPOSITORY="docker-library/php"
strategy="$("../bashbrew/scripts/github-actions/generate.sh")"
unset GITHUB_REPOSITORY
fi
cd ../..

# Replace "php" with "drupal-php" in generated JSON
strategy="$(echo "$strategy" | sed -e "s/php/aaronmchale\/drupal-php/g")"

# The CI job picks up the output from this script and uses it to generate jobs
echo "$strategy" > "versions-ci-json.lock"
echo "JSON for CI jobs saved to versions-ci-json.lock"
15 changes: 0 additions & 15 deletions download-libs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,3 @@ else
echo "$(git rev-parse HEAD)" > ../.php-known-hash
fi
cd ..

# Clone bashbrew if it doesn't exist
if [ ! -d bashbrew ]; then
echo "Downloading docker-library/bashbrew..."
git clone https://github.com/docker-library/bashbrew.git
fi
cd bashbrew && git fetch
if [ -f ../.bashbrew-known-hash ]; then
echo "Checking out known version of docker-library/bashbrew..."
git checkout -d "$(cat ../.bashbrew-known-hash)"
else
echo "Known version for docker-library/bashbrew not stored, storing latest commit as known version..."
echo "$(git rev-parse HEAD)" > ../.bashbrew-known-hash
fi
cd ..
Loading

0 comments on commit 5392906

Please sign in to comment.