Skip to content

Commit

Permalink
ci.sh/GHA: Add docker-build-push step/action
Browse files Browse the repository at this point in the history
A major maintainability issue for years has been that the CI assumes
that a docker image for the implementation exists in Docker's registry
(named kanaka/mal-test-IMPL). This means the upstream maintainers have
to be involved in the PR loop to build the implementation Dockerfile,
push to the docker registry and then have the PR submitter re-run CI.

To address this, in ci.sh, the docker-build-push action will try to pull
the image and then continue as normal. If the pull fails then it will
build the image and push it (if the build is running in the context of
the upstream repo's main branch) and then continue.

Also, this switches to using ghcr.io as the default repo for images
which will make image transfer more local (during CI) and hopefully
a fair bit faster (and avoid potential docker pull limits).

Add a steps to the GHA main workflow that do a docker login to ghcr.io
and then call `ci.sh docker-build-push ${IMPL}`.
  • Loading branch information
kanaka committed Aug 2, 2024
1 parent 78d6dab commit 8f8608a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 14 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ jobs:
- uses: actions/checkout@v2
with:
fetch-depth: 0 # Need full history for voom like versions
- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker Build/Push
run: |
export ${{ matrix.IMPL }}
./ci.sh docker-build-push ${IMPL}
- name: Build
run: |
export ${{ matrix.IMPL }}
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ STEP_TEST_FILES = $(strip $(wildcard \

# DOCKERIZE utility functions
lc = $(subst A,a,$(subst B,b,$(subst C,c,$(subst D,d,$(subst E,e,$(subst F,f,$(subst G,g,$(subst H,h,$(subst I,i,$(subst J,j,$(subst K,k,$(subst L,l,$(subst M,m,$(subst N,n,$(subst O,o,$(subst P,p,$(subst Q,q,$(subst R,r,$(subst S,s,$(subst T,t,$(subst U,u,$(subst V,v,$(subst W,w,$(subst X,x,$(subst Y,y,$(subst Z,z,$1))))))))))))))))))))))))))
impl_to_image = kanaka/mal-test-$(call lc,$(1)):$(shell ./voom-like-version.sh impls/$(1)/Dockerfile)
impl_to_image = ghcr.io/kanaka/mal-test-$(call lc,$(1)):$(shell ./voom-like-version.sh impls/$(1)/Dockerfile)

actual_impl = $(if $(filter mal,$(1)),$(patsubst %-mal,%,$(MAL_IMPL)),$(1))

Expand Down
38 changes: 25 additions & 13 deletions ci.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

set -ex

Expand All @@ -24,11 +24,23 @@ mode_var=${raw_mode_var/-/__}
mode_var=${mode_var/./__}
mode_val=${!mode_var}

MAKE="make ${mode_val:+${mode_var}=${mode_val}}"

log_prefix="${ACTION}${REGRESS:+-regress}-${IMPL}${mode_val:+-${mode_val}}${MAL_IMPL:+-${MAL_IMPL}}"
TEST_OPTS="${TEST_OPTS} --debug-file ../../${log_prefix}.debug"

img_base="${MAL_IMPL:-${IMPL}}"
img_impl="${img_base%%-mal}"
img_name="mal-test-${img_impl,,}"
img_ver=$(./voom-like-version.sh impls/${img_impl}/Dockerfile)
IMAGE="ghcr.io/kanaka/${img_name}:${img_ver}"

# If NO_DOCKER is blank then run make in a docker image
MAKE="make ${mode_val:+${mode_var}=${mode_val}}"
if [ -z "${NO_DOCKER}" ]; then
# We could just use make DOCKERIZE=1 instead but that does add
# non-trivial startup overhead for each step.
MAKE="docker run -i -u $(id -u) -v `pwd`:/mal ${IMAGE} ${MAKE}"
fi

# Log everything below this point:
exec &> >(tee ./${log_prefix}.log)

Expand All @@ -47,18 +59,18 @@ echo "IMPL: ${IMPL}"
echo "BUILD_IMPL: ${BUILD_IMPL}"
echo "MAL_IMPL: ${MAL_IMPL}"
echo "TEST_OPTS: ${TEST_OPTS}"

# If NO_DOCKER is blank then launch use a docker image, otherwise use
# the Travis/Github Actions image/tools directly.
if [ -z "${NO_DOCKER}" ]; then
img_impl=$(echo "${MAL_IMPL:-${IMPL}}" | tr '[:upper:]' '[:lower:]')
img_ver=$(./voom-like-version.sh impls/${img_impl}/Dockerfile)
# We could just use make DOCKERIZE=1 instead but that does add
# non-trivial startup overhead for each step.
MAKE="docker run -i -u $(id -u) -v `pwd`:/mal kanaka/mal-test-${img_impl%%-mal}:${img_ver} ${MAKE}"
fi
echo "IMAGE: ${IMAGE}"
echo "MAKE: ${MAKE}"

case "${ACTION}" in
docker-build-push)
if ! docker pull ${IMAGE}; then
make "docker-build^${MAL_IMPL:-${IMPL}}"
if [ "${GITHUB_REF}" = "refs/heads/main" ]; then
docker push ${IMAGE}
fi
fi
;;
build)
# rpython often fails on step9 in compute_vars_longevity
# so build step9, then continue with the full build
Expand Down

0 comments on commit 8f8608a

Please sign in to comment.