Skip to content

Commit

Permalink
chore(pact_mock_server_cli): Create Multi-platform image
Browse files Browse the repository at this point in the history
  • Loading branch information
rholshausen committed Mar 15, 2024
1 parent d00e2ad commit 0d70738
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
22 changes: 9 additions & 13 deletions rust/pact_mock_server_cli/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
ARG ARCH=
FROM rust:1-alpine3.15 AS builder
ARG BIN_ARCH=x86_64
ARG VERSION=1.0.5

# Add our source code.
ADD . /build
RUN apk --no-cache add wget
RUN wget -O pact_mock_server_cli.gz https://github.com/pact-foundation/pact-reference/releases/download/pact_mock_server_cli-v${VERSION}/pact_mock_server_cli-linux-${BIN_ARCH}.gz
RUN gunzip pact_mock_server_cli.gz
RUN chmod +x pact_mock_server_cli

RUN apk --no-cache add gcc musl-dev protobuf protobuf-dev
RUN rustup component add rustfmt

# Fix the cargo manifest so it can be built standalone
RUN sed -i -e 's/pact_matching = {\s*version\s*=\s*"\([^"]*\).*/pact_matching = "\1"/' /build/Cargo.toml
RUN sed -i -e 's/pact_mock_server = {\s*version\s*=\s*"\([^"]*\).*/pact_mock_server = "\1"/' /build/Cargo.toml

# Build our application.
RUN cd build && cargo build --release

# Now, we need to build our _real_ Docker container, copying in the executable.
FROM alpine:3.16
FROM ${ARCH}alpine:3.16
RUN apk --no-cache add ca-certificates
COPY --from=builder \
/build/target/release/pact_mock_server_cli \
/pact_mock_server_cli \
/usr/local/bin/

EXPOSE 8080 9000-9020
Expand Down
23 changes: 19 additions & 4 deletions rust/pact_mock_server_cli/release-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,22 @@ if [ "" = "$1" ]; then
exit 1
fi

docker build . -t pactfoundation/pact-ref-mock-server:$1
docker push pactfoundation/pact-ref-mock-server:$1
docker tag pactfoundation/pact-ref-mock-server:$1 pactfoundation/pact-ref-mock-server:latest
docker push pactfoundation/pact-ref-mock-server:latest
# AMD64
docker build . -t pactfoundation/pact-ref-mock-server:$1-amd64 --platform linux/amd64 \
--build-arg ARCH=amd64/ --build-arg BIN_ARCH=x86_64 --build-arg VERSION=$1
docker push pactfoundation/pact-ref-mock-server:$1-amd64

# ARM64V8
docker build . -t pactfoundation/pact-ref-mock-server:$1-arm64v8 --platform linux/arm64 \
--build-arg ARCH=arm64v8/ --build-arg BIN_ARCH=aarch64 --build-arg VERSION=$1
docker push pactfoundation/pact-ref-mock-server:$1-arm64v8

# Create Manifest
docker manifest create pactfoundation/pact-ref-mock-server:$1 \
--amend pactfoundation/pact-ref-mock-server:$1-amd64 \
--amend pactfoundation/pact-ref-mock-server:$1-arm64v8
docker manifest push pactfoundation/pact-ref-mock-server:$1
docker manifest create pactfoundation/pact-ref-mock-server:latest \
--amend pactfoundation/pact-ref-mock-server:$1-amd64 \
--amend pactfoundation/pact-ref-mock-server:$1-arm64v8
docker manifest push pactfoundation/pact-ref-mock-server:latest

3 comments on commit 0d70738

@YOU54F
Copy link
Member

@YOU54F YOU54F commented on 0d70738 Mar 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one @rholshausen, this has been on my want list for a while

How are these being built/pushed to Dockerhub? Is it part of CI or via DockerHubs auto builder?

I've been tracking the various images we build/push here

pact-foundation/roadmap#29

and would like to ensure for each relevant image we

  • publish multi-arch images for at least amd64/arm64
  • additionally publish to ghcr.io (albeit with pact-foundation as the image owner, rather than pactfoundation ala dockerhub )

@rholshausen
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's manual, Mate! Whenever I remember to run the script.

@YOU54F
Copy link
Member

@YOU54F YOU54F commented on 0d70738 Mar 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought so! No worries, I'll look at adding a docker build/push step to take another thing off your plate

added one to pact stub server on my fork

Please sign in to comment.