Skip to content

Commit

Permalink
Merge branch 'lukas/gh/maint-base-images' into maint
Browse files Browse the repository at this point in the history
* lukas/gh/maint-base-images:
  Push versions of all branches
  • Loading branch information
garazdawi committed Oct 17, 2022
2 parents ff05b93 + 7241bbd commit dd5fcc4
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 19 deletions.
23 changes: 17 additions & 6 deletions .github/scripts/build-base-image.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
#!/bin/bash

BASE_BRANCH="$1"

case "${BASE_BRANCH}" in
master|maint|maint-*)
;;
*)
BASE_BRANCH="master"
;;
esac

if [ -z "${BASE_TAG}" ]; then
BASE_TAG=$(grep "ARG BASE=" ".github/dockerfiles/Dockerfile.${1}" | head -1 | tr '=' ' ' | awk '{print $3}')
BASE_TAG=$(grep "ARG BASE=" ".github/dockerfiles/Dockerfile.${2}" | head -1 | tr '=' ' ' | awk '{print $3}')
fi

case "${BASE_TAG}" in
Expand Down Expand Up @@ -31,25 +41,26 @@ elif [ -f "otp_docker_base/otp_docker_base.tar" ]; then
echo "::set-output name=BASE_BUILD::loaded"
else
if [ "${BASE_USE_CACHE}" != "false" ]; then
docker pull "${BASE_TAG}"
docker pull "${BASE_TAG}:${BASE_BRANCH}"
docker tag "${BASE_TAG}:${BASE_BRANCH}" "${BASE_TAG}:latest"
BASE_CACHE="--cache-from ${BASE_TAG}"
fi

BASE_IMAGE_ID=$(docker images -q "${BASE_TAG}")
BASE_IMAGE_ID=$(docker images -q "${BASE_TAG}:latest")

docker build --pull --tag "${BASE_TAG}" \
docker build --pull --tag "${BASE_TAG}:latest" \
${BASE_CACHE} \
--file ".github/dockerfiles/Dockerfile.${BASE_TYPE}" \
--build-arg MAKEFLAGS=-j$(($(nproc) + 2)) \
--build-arg USER=otptest --build-arg GROUP=uucp \
--build-arg uid="$(id -u)" \
--build-arg BASE="${BASE}" .github/

NEW_BASE_IMAGE_ID=$(docker images -q "${BASE_TAG}")
NEW_BASE_IMAGE_ID=$(docker images -q "${BASE_TAG}:latest")
if [ "${BASE_IMAGE_ID}" = "${NEW_BASE_IMAGE_ID}" ]; then
echo "::set-output name=BASE_BUILD::cached"
else
echo "::set-output name=BASE_BUILD::re-built"
docker save "${BASE_TAG}" > "otp_docker_base.tar"
docker save "${BASE_TAG}:latest" > "otp_docker_base.tar"
fi
fi
3 changes: 2 additions & 1 deletion .github/scripts/restore-otp-image.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/bin/bash

BASE_BRANCH="$1"
BASE_TAG=$(grep "ARG BASE=" ".github/dockerfiles/Dockerfile.64-bit" | head -1 | tr '=' ' ' | awk '{print $3}')

BASE_TAG="$BASE_TAG" .github/scripts/build-base-image.sh
BASE_TAG="$BASE_TAG" .github/scripts/build-base-image.sh "${BASE_BRANCH}"

cat > Dockerfile <<EOF
FROM ${BASE_TAG}
Expand Down
15 changes: 9 additions & 6 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ on:
push:
pull_request:

env:
BASE_BRANCH: ${{ github.event_name == 'pull_request' && github.base_ref || github.ref_name }}

jobs:

pack:
Expand All @@ -44,7 +47,7 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build BASE image
id: base-build
run: .github/scripts/build-base-image.sh 64-bit
run: .github/scripts/build-base-image.sh "${BASE_BRANCH}" 64-bit
- name: Save BASE image
if: steps.base-build.outputs.BASE_BUILD == 're-built'
uses: actions/upload-artifact@v2
Expand Down Expand Up @@ -297,7 +300,7 @@ jobs:
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build base image
run: .github/scripts/build-base-image.sh ${{ matrix.type }}
run: .github/scripts/build-base-image.sh "${BASE_BRANCH}" ${{ matrix.type }}
- name: Build ${{ matrix.type }} image
run: |
mv otp_src.tar.gz .github/otp.tar.gz
Expand Down Expand Up @@ -327,7 +330,7 @@ jobs:
with:
name: otp-ubuntu-20.04
- name: Restore docker image
run: .github/scripts/restore-otp-image.sh
run: .github/scripts/restore-otp-image.sh "${BASE_BRANCH}"

## Build pre-built tar with chunks
- name: Build doc chunks
Expand Down Expand Up @@ -400,7 +403,7 @@ jobs:
with:
name: otp-ubuntu-20.04
- name: Restore docker image
run: .github/scripts/restore-otp-image.sh
run: .github/scripts/restore-otp-image.sh "${BASE_BRANCH}"
- name: Install clang-format
run: |
docker build -t otp - <<EOF
Expand Down Expand Up @@ -444,7 +447,7 @@ jobs:
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Restore docker image
run: .github/scripts/restore-otp-image.sh
run: .github/scripts/restore-otp-image.sh "${BASE_BRANCH}"
- name: Run tests
id: run-tests
run: |
Expand Down Expand Up @@ -499,7 +502,7 @@ jobs:
uses: actions/download-artifact@v2
- run: mv otp-ubuntu-20.04/otp-ubuntu-20.04.tar.gz .
- name: Restore docker image
run: .github/scripts/restore-otp-image.sh
run: .github/scripts/restore-otp-image.sh "${BASE_BRANCH}"
- name: Merge test results
run: |
shopt -s nullglob
Expand Down
21 changes: 15 additions & 6 deletions .github/workflows/update-base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,29 @@ jobs:
strategy:
matrix:
type: [debian-base,ubuntu-base,i386-debian-base]
branch: [master, maint, maint-25]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
ref: ${{ matrix.branch }}
- name: Docker login
uses: docker/login-action@v1
uses: docker/login-action@v2
with:
registry: docker.pkg.github.com
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build base image
id: base
run: >-
BASE_TAG=docker.pkg.github.com/erlang/otp/${{ matrix.type }}
BASE_TAG=docker.pkg.github.com/${{ github.repository_owner }}/otp/${{ matrix.type }}
BASE_USE_CACHE=false
.github/scripts/build-base-image.sh
- name: Push base image
run: docker push ${{ steps.base.outputs.BASE_TAG }}
.github/scripts/build-base-image.sh "${{ matrix.branch }}"
- name: Push master image
if: matrix.branch == 'master'
run: docker push ${{ steps.base.outputs.BASE_TAG }}:latest
- name: Tag and push base image
run: |
docker tag ${{ steps.base.outputs.BASE_TAG }}:latest \
${{ steps.base.outputs.BASE_TAG }}:${{ matrix.branch }}
docker push ${{ steps.base.outputs.BASE_TAG }}:${{ matrix.branch }}

0 comments on commit dd5fcc4

Please sign in to comment.