Skip to content

Commit

Permalink
Improve docker multiarch builds.
Browse files Browse the repository at this point in the history
  • Loading branch information
viferga committed Nov 7, 2024
1 parent 2ea2907 commit 25eeb0a
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 57 deletions.
62 changes: 33 additions & 29 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "MetaCall Distributable Linux Release"
name: MetaCall Distributable Linux

on:
workflow_dispatch:
Expand All @@ -18,7 +18,6 @@ jobs:
build:
name: Build and Package
runs-on: ubuntu-latest
timeout-minutes: 360

strategy:
matrix:
Expand All @@ -36,38 +35,48 @@ jobs:
- name: Check out the repo
uses: actions/checkout@v4

- name: Set asset name
run: echo "ASSET_NAME=metacall-tarball-linux-${{ matrix.arch }}.tar.gz" >> $GITHUB_ENV

- name: Build the Docker image for ${{ matrix.arch }}
- name: Build the base image for ${{ matrix.arch }}
run: |
docker buildx build \
--platform linux/${{ matrix.arch }} \
-t metacall/distributable_linux:${{ matrix.arch }} \
--load \
-t metacall/distributable_linux \
-f Dockerfile .
- name: Install additional channels and pull for ${{ matrix.arch }}
run: |
docker run --privileged --name tmp metacall/distributable_linux:${{ matrix.arch }} sh -c 'guix pull'
docker commit tmp metacall/distributable_linux:${{ matrix.arch }}
docker run \
--platform linux/${{ matrix.arch }} \
--privileged \
--name tmp \
metacall/distributable_linux sh -c 'guix pull'
docker commit tmp metacall/distributable_linux
docker rm -f tmp
- name: Build dependencies for ${{ matrix.arch }}
run: |
docker run -d --privileged --name tmp metacall/distributable_linux:${{ matrix.arch }} /metacall/scripts/deps.sh
docker commit tmp metacall/distributable_linux:${{ matrix.arch }}
docker run \
--platform linux/${{ matrix.arch }} \
--privileged \
--name tmp \
metacall/distributable_linux /metacall/scripts/deps.sh
docker commit tmp metacall/distributable_linux
docker rm -f tmp
- name: Build tarball for ${{ matrix.arch }}
run: |
docker run --rm -e ARCH=${{ matrix.arch }} -v $PWD/out:/metacall/pack --privileged metacall/distributable_linux:${{ matrix.arch }} /metacall/scripts/build.sh
docker run \
--platform linux/${{ matrix.arch }} \
--rm \
-v `pwd`/out:/metacall/pack \
--privileged \
metacall/distributable_linux /metacall/scripts/build.sh
mv out/tarball.tar.gz out/metacall-tarball-linux-${{ matrix.arch }}.tar.gz
- name: Upload tarball artifact for ${{ matrix.arch }}
uses: actions/upload-artifact@v4
with:
name: built-tarball-${{ matrix.arch }}
path: out/${{ env.ASSET_NAME }}
path: out/metacall-tarball-linux-${{ matrix.arch }}.tar.gz

test:
name: Test
Expand All @@ -87,62 +96,57 @@ jobs:
name: built-tarball-${{ matrix.arch }}
path: out/

- name: Prepare tarball for ${{ matrix.arch }}
run: mv out/metacall-tarball-linux-${{ matrix.arch }}.tar.gz out/tarball.tar.gz

- name: Generate a unique ID for invalidating the cache of test layers
run: echo "CACHE_INVALIDATE=$(date +%s)" >> $GITHUB_ENV

- name: Test CLI for ${{ matrix.arch }}
run: |
docker buildx build \
--platform linux/${{ matrix.arch }} \
--build-arg ARCH=${{ matrix.arch }} \
--build-arg CACHE_INVALIDATE=${{ env.CACHE_INVALIDATE }} \
-t metacall/distributable_linux_test:cli-${{ matrix.arch }} \
-t metacall/distributable_linux_test:cli \
-f tests/cli/Dockerfile .
- name: Test C for ${{ matrix.arch }}
run: |
docker buildx build \
--platform linux/${{ matrix.arch }} \
--build-arg ARCH=${{ matrix.arch }} \
--build-arg CACHE_INVALIDATE=${{ env.CACHE_INVALIDATE }} \
-t metacall/distributable_linux_test:c-${{ matrix.arch }} \
-t metacall/distributable_linux_test:c \
-f tests/c/Dockerfile .
- name: Test Python for ${{ matrix.arch }}
run: |
docker buildx build \
--platform linux/${{ matrix.arch }} \
--build-arg ARCH=${{ matrix.arch }} \
--build-arg CACHE_INVALIDATE=${{ env.CACHE_INVALIDATE }} \
-t metacall/distributable_linux_test:python-${{ matrix.arch }} \
-t metacall/distributable_linux_test:python \
-f tests/python/Dockerfile .
- name: Test Node for ${{ matrix.arch }}
run: |
docker buildx build \
--platform linux/${{ matrix.arch }} \
--build-arg ARCH=${{ matrix.arch }} \
--build-arg CACHE_INVALIDATE=${{ env.CACHE_INVALIDATE }} \
-t metacall/distributable_linux_test:node-${{ matrix.arch }} \
-t metacall/distributable_linux_test:node \
-f tests/node/Dockerfile .
- name: Test TypeScript for ${{ matrix.arch }}
run: |
docker buildx build \
--platform linux/${{ matrix.arch }} \
--build-arg ARCH=${{ matrix.arch }} \
--build-arg CACHE_INVALIDATE=${{ env.CACHE_INVALIDATE }} \
-t metacall/distributable_linux_test:typescript-${{ matrix.arch }} \
-t metacall/distributable_linux_test:typescript \
-f tests/typescript/Dockerfile .
publish-github:
name: Publish on GitHub
runs-on: ubuntu-latest
needs: test
if: startsWith(github.ref, 'refs/tags/v')
strategy:
matrix:
arch: [amd64, 386]

steps:
- name: Check out the repo
Expand All @@ -153,7 +157,7 @@ jobs:
- name: Download tarball artifacts for all architectures
uses: actions/download-artifact@v4
with:
name: built-tarball-${{ matrix.arch }}
merge-multiple: true
path: out/

- name: Load GHR binary
Expand All @@ -178,7 +182,7 @@ jobs:
export CI_COMMIT_TAG="${{ github.ref_name }}"
export RELEASE_DATE=$(date '+%Y-%m-%d')
echo "MetaCall Distributable Linux ${CI_COMMIT_TAG} [${RELEASE_DATE}] - ${GH_REPO_OWNER}/${GH_REPO_NAME}:${CI_COMMIT_SHA}" && echo "${GIT_HISTORY}"
ghr -t "${{ secrets.GITHUB_TOKEN }}" -u "${GH_REPO_OWNER}" -r "${GH_REPO_NAME}" -c "${CI_COMMIT_SHA}" -n "MetaCall Distributable Linux ${CI_COMMIT_TAG} [${RELEASE_DATE}]" -b "${GIT_HISTORY}" -replace "${CI_COMMIT_TAG}" ${PWD}/out/${{ env.ASSET_NAME }}
ghr -t "${{ secrets.GITHUB_TOKEN }}" -u "${GH_REPO_OWNER}" -r "${GH_REPO_NAME}" -c "${CI_COMMIT_SHA}" -n "MetaCall Distributable Linux ${CI_COMMIT_TAG} [${RELEASE_DATE}]" -b "${GIT_HISTORY}" -replace "${CI_COMMIT_TAG}" `pwd`/out/*
install-test:
name: Trigger Install Test Workflow
Expand Down
4 changes: 1 addition & 3 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

export GUILE_WARN_DEPRECATED='detailed'

ASSET_NAME="metacall-tarball-linux-${ARCH}.tar.gz"
PACK_DIR="/metacall/pack"
# Generate a portable package tarball
# Uses --no-grafts option in order to avoid conflicts between duplicated versions

Expand All @@ -34,5 +32,5 @@ PACK_DIR="/metacall/pack"
-S /gnu/bin=bin -S /gnu/etc=etc -S /gnu/lib=lib -S /gnu/include=include -S /gnu/share=share \
-RR metacall nss-certs \
-L /metacall/nonguix -L /metacall/source | tee build.log \
`# Copy` && mv "$(grep 'tarball-pack.tar.gz$' build.log)" "$PACK_DIR/$ASSET_NAME" \
`# Copy` && mv `grep 'tarball-pack.tar.gz$' build.log` /metacall/pack/tarball.tar.gz \
`# Exit` && exit 0 || exit 1
8 changes: 3 additions & 5 deletions tests/c/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

FROM gcc:13-bookworm AS c_test

ARG ARCH

# Image descriptor
LABEL copyright.name="Vicente Eduardo Ferrer Garcia" \
copyright.address="[email protected]" \
Expand All @@ -31,11 +29,11 @@ LABEL copyright.name="Vicente Eduardo Ferrer Garcia" \

SHELL ["/bin/bash", "-c"]

COPY out/metacall-tarball-linux-${ARCH}.tar.gz /
COPY out/tarball.tar.gz /

RUN cd / \
&& tar --no-same-owner --no-same-permissions -xzf metacall-tarball-linux-${ARCH}.tar.gz \
&& rm metacall-tarball-linux-${ARCH}.tar.gz
&& tar --no-same-owner --no-same-permissions -xzf tarball.tar.gz \
&& rm tarball.tar.gz

COPY tests/c/test.c /

Expand Down
8 changes: 3 additions & 5 deletions tests/cli/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

FROM busybox:1.31.1 AS cli_test

ARG ARCH

# Image descriptor
LABEL copyright.name="Vicente Eduardo Ferrer Garcia" \
copyright.address="[email protected]" \
Expand All @@ -29,11 +27,11 @@ LABEL copyright.name="Vicente Eduardo Ferrer Garcia" \
vendor="MetaCall Inc." \
version="0.1"

COPY out/metacall-tarball-linux-${ARCH}.tar.gz /
COPY out/tarball.tar.gz /

RUN cd / \
&& tar --no-same-owner --no-same-permissions -xzf metacall-tarball-linux-${ARCH}.tar.gz \
&& rm metacall-tarball-linux-${ARCH}.tar.gz
&& tar --no-same-owner --no-same-permissions -xzf tarball.tar.gz \
&& rm tarball.tar.gz

COPY tests/scripts/ /scripts/

Expand Down
8 changes: 3 additions & 5 deletions tests/node/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

FROM busybox:1.31.1 AS node_test

ARG ARCH

# Image descriptor
LABEL copyright.name="Vicente Eduardo Ferrer Garcia" \
copyright.address="[email protected]" \
Expand All @@ -29,11 +27,11 @@ LABEL copyright.name="Vicente Eduardo Ferrer Garcia" \
vendor="MetaCall Inc." \
version="0.1"

COPY out/metacall-tarball-linux-${ARCH}.tar.gz /
COPY out/tarball.tar.gz /

RUN cd / \
&& tar --no-same-owner --no-same-permissions -xzf metacall-tarball-linux-${ARCH}.tar.gz \
&& rm metacall-tarball-linux-${ARCH}.tar.gz
&& tar --no-same-owner --no-same-permissions -xzf tarball.tar.gz \
&& rm tarball.tar.gz

COPY tests/scripts/ /scripts/

Expand Down
8 changes: 3 additions & 5 deletions tests/python/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

FROM busybox:1.31.1 AS python_test

ARG ARCH

# Image descriptor
LABEL copyright.name="Vicente Eduardo Ferrer Garcia" \
copyright.address="[email protected]" \
Expand All @@ -29,11 +27,11 @@ LABEL copyright.name="Vicente Eduardo Ferrer Garcia" \
vendor="MetaCall Inc." \
version="0.1"

COPY out/metacall-tarball-linux-${ARCH}.tar.gz /
COPY out/tarball.tar.gz /

RUN cd / \
&& tar --no-same-owner --no-same-permissions -xzf metacall-tarball-linux-${ARCH}.tar.gz \
&& rm metacall-tarball-linux-${ARCH}.tar.gz
&& tar --no-same-owner --no-same-permissions -xzf tarball.tar.gz \
&& rm tarball.tar.gz

COPY tests/scripts/ /scripts/

Expand Down
8 changes: 3 additions & 5 deletions tests/typescript/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

FROM busybox:1.31.1 AS ts_test

ARG ARCH

# Image descriptor
LABEL copyright.name="Vicente Eduardo Ferrer Garcia" \
copyright.address="[email protected]" \
Expand All @@ -29,11 +27,11 @@ LABEL copyright.name="Vicente Eduardo Ferrer Garcia" \
vendor="MetaCall Inc." \
version="0.1"

COPY out/metacall-tarball-linux-${ARCH}.tar.gz /
COPY out/tarball.tar.gz /

RUN cd / \
&& tar --no-same-owner --no-same-permissions -xzf metacall-tarball-linux-${ARCH}.tar.gz \
&& rm metacall-tarball-linux-${ARCH}.tar.gz
&& tar --no-same-owner --no-same-permissions -xzf tarball.tar.gz \
&& rm tarball.tar.gz

COPY tests/scripts/fib.ts /scripts/

Expand Down

0 comments on commit 25eeb0a

Please sign in to comment.