Skip to content

Commit 14987e3

Browse files
authored
feat: Multi manifest build - arm64/arm (new) + amd64 (current) (#123)
* feat: Multi manifest build - arm64/arm (new) + amd64 (current) * chore(test): test latest-${ARCH} image * chore(docs): add workflow & docker badges * chore(docs): add multiplatform image info
1 parent a74d3e3 commit 14987e3

File tree

12 files changed

+131
-48
lines changed

12 files changed

+131
-48
lines changed

Diff for: .github/workflows/audit.yml

+2-17
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88

99
jobs:
1010
audit:
11-
name: 💥 cross-audit
11+
name: 👮 cross-audit
1212
strategy:
1313
fail-fast: false
1414
matrix:
@@ -23,19 +23,4 @@ jobs:
2323
if: ${{ matrix.DOCKER_TARGET_PLATFORM }} == 'linux/arm' || 'linux/arm64'
2424
run: ./script/release-workflow/docker-prepare.sh
2525
- name: Audit Docker image for ${{ matrix.DOCKER_TARGET_PLATFORM }}
26-
run: ./script/release-workflow/audit.sh
27-
# # We could also run via a trivy action and publish results back to GitHub :)
28-
# - name: Run Trivy vulnerability scanner for ${{ matrix.DOCKER_TARGET_PLATFORM }}
29-
# uses: aquasecurity/trivy-action@master
30-
# with:
31-
# image-ref: 'pactfoundation/pact-broker:audit'
32-
# exit-code: '1'
33-
# format: 'sarif'
34-
# output: 'trivy-results.sarif'
35-
# ignore-unfixed: true
36-
# vuln-type: 'os,library'
37-
# severity: 'CRITICAL,HIGH'
38-
# - name: Upload Trivy scan results to GitHub Security tab
39-
# uses: github/codeql-action/upload-sarif@v2
40-
# with:
41-
# sarif_file: 'trivy-results.sarif'
26+
run: ./script/release-workflow/audit.sh

Diff for: .github/workflows/test.yml

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
name: Test
22

33
on: [push, pull_request]
4-
env:
5-
DOCKER_TARGET_PLATFORM: "linux/amd64"
64

75
jobs:
86
test:
@@ -13,8 +11,19 @@ jobs:
1311
- run: "bundle install"
1412
- run: "bundle exec rake"
1513

16-
- name: Build Docker image
17-
run: docker buildx build --platform=${DOCKER_TARGET_PLATFORM} -t pactfoundation/pact-broker:latest .
14+
- name: Setup Docker builder
15+
run: ./script/release-workflow/docker-prepare.sh
16+
17+
- name: Build Docker image for single platform
18+
run: ./script/release-workflow/docker-build.sh
19+
20+
- uses: KengoTODA/actions-setup-docker-compose@v1
21+
if: ${{ env.ACT }}
22+
name: Install `docker-compose` for use with https://github.com/nektos/act
23+
with:
24+
version: '2.15.1'
1825

1926
- name: Integration tests
2027
run: script/test.sh
28+
env:
29+
TAG: latest-amd64

Diff for: Dockerfile

+21-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
1-
FROM ruby:3.2.1-alpine3.17
1+
FROM ruby:3.2.1-alpine3.17 as base
22

3-
ARG SUPERCRONIC_PLATFORM=amd64
4-
ARG SUPERCRONIC_SHA1SUM=6817299e04457e5d6ec4809c72ee13a43e95ba41
3+
# 1. Install target specfic dependencies
4+
# - gcompat required for arm/arm64 (otherwise nokogiri breaks when viewing network graph)
5+
# - https://github.com/sparklemotion/nokogiri/issues/2414
6+
# 2. Supercronic - setup sha1sum for each supported architecture
7+
FROM base AS base-amd64
8+
ENV SUPERCRONIC_SHA1SUM=6817299e04457e5d6ec4809c72ee13a43e95ba41
9+
FROM base AS base-arm64
10+
ENV SUPERCRONIC_SHA1SUM=fce407a3d7d144120e97cfc0420f16a18f4637d9
11+
RUN apk add --update --no-cache gcompat
12+
FROM base AS base-arm
13+
ENV SUPERCRONIC_SHA1SUM=fad9380ed30b9eae61a5b1089f93bd7ee8eb1a9c
14+
RUN apk add --update --no-cache gcompat
515

6-
ENV SUPERCRONIC_URL=https://github.com/aptible/supercronic/releases/download/v0.2.24/supercronic-linux-${SUPERCRONIC_PLATFORM} \
7-
SUPERCRONIC=supercronic-linux-${SUPERCRONIC_PLATFORM}
16+
# Supercronic - use base-$TARGETARCH to select correct base image SUPERCRONIC_SHA1SUM
17+
ARG TARGETARCH
18+
FROM base-$TARGETARCH AS pb-dev
819

20+
# Install Supercronic
21+
ARG TARGETARCH
22+
ENV SUPERCRONIC_URL=https://github.com/aptible/supercronic/releases/download/v0.2.24/supercronic-linux-${TARGETARCH} \
23+
SUPERCRONIC=supercronic-linux-${TARGETARCH}
924
RUN wget "$SUPERCRONIC_URL" \
1025
&& echo "${SUPERCRONIC_SHA1SUM} ${SUPERCRONIC}" | sha1sum -c - \
1126
&& chmod +x "$SUPERCRONIC" \
@@ -59,4 +74,4 @@ ENV PACT_BROKER_DATABASE_CLEAN_OVERWRITTEN_DATA_MAX_AGE=7
5974
ENV PACT_BROKER_DATABASE_CLEAN_DRY_RUN=false
6075
USER ruby
6176
ENTRYPOINT ["sh", "./entrypoint.sh"]
62-
CMD ["config.ru"]
77+
CMD ["config.ru"]

Diff for: README.md

+41-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
11
# Dockerised Pact Broker
22

3-
[![Release Docker image](https://github.com/pact-foundation/pact-broker-docker/actions/workflows/release_image.yml/badge.svg)](https://github.com/pact-foundation/pact-broker-docker/actions/workflows/release_image.yml)
4-
53
This repository contains a Dockerized version of the [Pact Broker][pact-broker]. You can pull the `pactfoundation/pact-broker` image from [Dockerhub][pact-broker-docker]. If you're viewing these docs on Dockerhub, here is a link to the [github repository][github].
64

75
> Note: On 3 May 2023, the format of the docker tag changed from starting with the Pact Broker gem version (`2.107.0.1`), to ending with the Pact Broker gem version (`2.107.1-pactbroker2.107.1`). Read about the new versioning scheme [here](#versioning).
86
7+
[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://GitHub.com/pact-foundation/pact-msw-adapter/graphs/commit-activity)
8+
9+
[![Linux](https://svgshare.com/i/Zhy.svg)](https://svgshare.com/i/Zhy.svg)
10+
[![macOS](https://svgshare.com/i/ZjP.svg)](https://svgshare.com/i/ZjP.svg)
11+
[![Windows](https://svgshare.com/i/ZhY.svg)](https://svgshare.com/i/ZhY.svg)
12+
13+
[![Build and test](https://github.com/pact-foundation/pact-broker-docker/actions/workflows/test.yml/badge.svg)](https://github.com/pact-foundation/pact-broker-docker/actions/workflows/test.yml)
14+
[![Audit](https://github.com/pact-foundation/pact-broker-docker/actions/workflows/audit.yml/badge.svg)](https://github.com/pact-foundation/pact-broker-docker/actions/workflows/audit.yml)
15+
[![Release](https://github.com/pact-foundation/pact-broker-docker/actions/workflows/release_image.yml/badge.svg)](https://github.com/pact-foundation/pact-broker-docker/actions/workflows/release_image.yml)
16+
17+
[![pulls](https://badgen.net/docker/pulls/pactfoundation/pact-broker?icon=docker&label=pulls)](https://hub.docker.com/r/pactfoundation/pact-broker)
18+
[![stars](https://badgen.net/docker/stars/pactfoundation/pact-broker?icon=docker&label=stars)](https://hub.docker.com/r/pactfoundation/pact-broker)
19+
20+
[![size: amd64](https://badgen.net/docker/size/pactfoundation/pact-broker/latest-multi/amd64?icon=docker&label=size%3Aamd64)](https://hub.docker.com/r/pactfoundation/pact-broker)
21+
[![size: arm64](https://badgen.net/docker/size/pactfoundation/pact-broker/latest-multi/arm64?icon=docker&label=size%3Aarm64)](https://hub.docker.com/r/pactfoundation/pact-broker)
22+
[![size: arm](https://badgen.net/docker/size/pactfoundation/pact-broker/latest-multi/arm?icon=docker&label=size%3Aarm)](https://hub.docker.com/r/pactfoundation/pact-broker)
23+
924
## In a hurry?
1025

1126
If you want to try out a Pact Broker that can be accessed by all your teams, without having to fill in requisition forms and wait for 3 months, you can get a free trial at <a href="https://pactflow.io/?utm_source=github&utm_campaign=pact_foundation_pact_broker_docker">pactflow.io</a>. Built by a group of core Pact maintainers, PactFlow is a fork of the OSS Pact Broker with extra goodies like an improved UI, user and team management, secrets, field level verification results and federated login. It's also fully supported, and that means when something goes wrong, *someone else* gets woken up in the middle of the afternoon to fix it...
@@ -22,6 +37,30 @@ Please read https://github.com/phusion/passenger/wiki/Puma-vs-Phusion-Passenger
2237

2338
If you want to run the container as a standalone instance, then the `dius/pact-broker` image which uses Phusion Passenger may serve you better, as Passenger will restart any crashed processes.
2439

40+
## Platforms
41+
42+
### Single platform images
43+
44+
By default, vanilla tags, are built only for `amd64`
45+
46+
- `--platform=linux/amd64`
47+
48+
```sh
49+
docker run --rm -it --entrypoint /bin/sh pactfoundation/pact-broker:latest -c 'uname -sm'
50+
```
51+
52+
### Multi-manifest image
53+
54+
Multi-platform images are available, by appending `-multi` to any release tag
55+
56+
- `--platform=linux/amd64`
57+
- `--platform=linux/arm/v7`
58+
- `--platform=linux/arm64`
59+
60+
```sh
61+
docker run --rm -it --entrypoint /bin/sh pactfoundation/pact-broker:latest-multi -c 'uname -sm'
62+
```
63+
2564
## Prerequisites
2665

2766
* A running Postgresql database (v9.4 or later) and the ability to connect to it (see [POSTGRESQL.md][postgres]).

Diff for: script/release-workflow/docker-build.sh

+11-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
set -euo >/dev/null
44

5-
DOCKER_TARGET_PLATFORM=${DOCKER_TARGET_PLATFORM:-"linux/amd64"}
6-
7-
docker buildx build --platform=${DOCKER_TARGET_PLATFORM} -t ${DOCKER_IMAGE_ORG_AND_NAME}:latest . --load
5+
## This will allow for local use for testing or scanning with trivy (multi-manifest builds cannot be imported)
6+
## we will build a multi-manifest build during ./docker-push.sh
7+
ARCHES=${ARCHES:-'amd64'}
8+
DOCKER_IMAGE_ORG_AND_NAME="${DOCKER_REPOSITORY:-pactfoundation}/pact-broker"
9+
for arch in $ARCHES; do
10+
docker buildx build \
11+
--platform linux/$arch \
12+
--output type=docker \
13+
--tag ${DOCKER_IMAGE_ORG_AND_NAME}:latest-${arch} \
14+
.
15+
done

Diff for: script/release-workflow/docker-push.sh

+21-6
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,29 @@
22

33
set -euo >/dev/null
44

5+
## Publish a multi arch build with -multi added to the tag
6+
## ($TAG||$MAJOR_TAG||$LATEST)-multi
7+
push_multi() {
8+
## These will use cached builds, so wont build every time.
9+
docker buildx build --platform=linux/amd64,linux/arm64,linux/arm \
10+
--output=type=image,push=true \
11+
-t ${DOCKER_IMAGE_ORG_AND_NAME}:$1-multi .
12+
}
13+
push() {
14+
docker buildx build --platform=linux/amd64 \
15+
--output=type=image,push=true \
16+
-t ${DOCKER_IMAGE_ORG_AND_NAME}:$1 .
17+
}
18+
519
if [ -n "${MAJOR_TAG:-}" ]; then
6-
docker tag ${DOCKER_IMAGE_ORG_AND_NAME}:latest ${DOCKER_IMAGE_ORG_AND_NAME}:${MAJOR_TAG}
7-
docker push ${DOCKER_IMAGE_ORG_AND_NAME}:${MAJOR_TAG}
20+
push ${MAJOR_TAG}
21+
push_multi ${MAJOR_TAG}
822
fi
923

10-
docker tag ${DOCKER_IMAGE_ORG_AND_NAME}:latest ${DOCKER_IMAGE_ORG_AND_NAME}:${TAG}
11-
docker push ${DOCKER_IMAGE_ORG_AND_NAME}:${TAG}
24+
push ${TAG}
25+
push_multi ${TAG}
1226

1327
if [ "${PUSH_TO_LATEST}" != "false" ]; then
14-
docker push ${DOCKER_IMAGE_ORG_AND_NAME}:latest
15-
fi
28+
push latest
29+
push_multi latest
30+
fi

Diff for: script/release-workflow/docker-scan.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ set -euo >/dev/null
44

55
script_dir=$(cd "$(dirname $0)" && pwd)
66

7-
${script_dir}/../scan.sh ${DOCKER_IMAGE_ORG_AND_NAME}:latest
7+
ARCH=${ARCH:-'amd64'}
8+
${script_dir}/../scan.sh ${DOCKER_IMAGE_ORG_AND_NAME}:latest-${ARCH}

Diff for: script/release-workflow/run.sh

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ fi
1212
. ${workflow_dir}/set-env-vars.sh
1313

1414
${workflow_dir}/validate.sh
15+
${workflow_dir}/docker-prepare.sh
1516
${workflow_dir}/docker-build.sh
1617
${workflow_dir}/docker-scan.sh
1718
${workflow_dir}/prepare-release.sh

Diff for: script/release-workflow/set-env-vars.sh

+8-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77
set -e
88

99
export DOCKER_IMAGE_ORG_AND_NAME="${DOCKER_REPOSITORY:-pactfoundation}/pact-broker"
10+
if [ -n "${DOCKER_TARGET_PLATFORM:-}" ]; then
11+
export ARCH=$(echo "$DOCKER_TARGET_PLATFORM" | sed 's/linux\///' | sed 's/\/v.*//')
12+
export ARCHES=$ARCH
13+
else
14+
export ARCHES='amd64 arm64 arm'
15+
export ARCH=amd64
16+
fi
1017

1118
if [ -z "$TAG" ]; then
1219
if [ -n "$VERSION" ] && [ -z "$INCREMENT" ]; then
@@ -31,4 +38,4 @@ if [ -z "$TAG" ]; then
3138
echo "MAJOR_TAG=$MAJOR_TAG"
3239
else
3340
echo "TAG=$TAG"
34-
fi
41+
fi

Diff for: script/scan.sh

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ set -eu
77
SCRIPT_DIR=$(cd "$(dirname $0)" && pwd)
88

99
docker run --rm \
10+
--platform=linux/${ARCH} \
1011
-v ${SCRIPT_DIR}/.trivyignore:/pact_broker/.trivyignore \
1112
-v ${PWD}/script/scan-inside-docker-container.sh:/pact_broker/scan-inside-docker-container.sh \
1213
-u root \

Diff for: script/test.sh

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
set -e
44

5+
docker_compose_files=$(find . -name "docker-compose-test*.yml")
6+
7+
for file in $docker_compose_files; do
8+
cat $file | sed -e "s~image: pactfoundation/pact-broker:.*~image: pactfoundation/pact-broker:${TAG}~g" > dc-tmp
9+
mv dc-tmp $file
10+
done
11+
512
cleanup() {
613
docker-compose -f docker-compose-tests.yml rm -fv || true
714
docker-compose -f docker-compose-test-different-env-var-names.yml rm -fv || true

Diff for: test/Dockerfile

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
FROM bash:5.0.17
1+
FROM powerman/dockerize
22

3-
RUN apk add --no-cache openssl curl
3+
RUN apk add --no-cache openssl curl bash
44

5-
ENV DOCKERIZE_VERSION v0.6.1
6-
RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
7-
&& tar -C /usr/local/bin -xzvf dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
8-
&& rm dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz
9-
10-
Add test.sh /home/test.sh
5+
ADD test.sh /home/test.sh
116
ADD foo-bar.json /home/foo-bar.json

0 commit comments

Comments
 (0)