Skip to content

Commit

Permalink
refactor: add arch to base image tag and reuse base in test workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
thalesmg committed Oct 19, 2023
1 parent ec4a162 commit 380676d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 71 deletions.
14 changes: 10 additions & 4 deletions .github/workflows/base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,14 @@ jobs:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_DEFAULT_REGION }}
- name: define base tag
id: base_tag
run: |
PLATFORM=${{ matrix.platform[1] }}
ARCH=${PLATFORM#linux/}
echo "tag=${{ matrix.platform[0] }}-${ARCH}" | tee -a $GITHUB_OUTPUT
- name: Get cache
run: aws s3 sync s3://docker-buildx-cache/emqx-builder/${{ matrix.platform[0] }} /tmp/.docker-buildx-cache
run: aws s3 sync s3://docker-buildx-cache/emqx-builder/${{ steps.base_tag.outputs.tag }} /tmp/.docker-buildx-cache
- uses: docker/setup-buildx-action@v3
- uses: docker/setup-qemu-action@v3
- uses: docker/login-action@v3
Expand All @@ -70,18 +76,18 @@ jobs:
id: base_meta
with:
images: ${{ env.REGISTRY_IMAGE }}
tags: type=raw,value=${{ matrix.platform[0] }}
tags: type=raw,value=${{ steps.base_tag.outputs.tag }}
- name: Build base image
uses: docker/build-push-action@v5
with:
push: true
pull: true
cache-from: type=local,src=/tmp/.docker-buildx-cache,mode=max
cache-to: type=local,dest=/tmp/.docker-buildx-cache-new,mode=max
platforms: ${{ matrix.platform[1] }}
tags: ${{ steps.base_meta.outputs.tags }}
labels: ${{ steps.base_meta.outputs.labels }}
file: ${{ matrix.platform[0] }}/Dockerfile
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=false
context: .
- name: Update cache
run: aws s3 sync --delete /tmp/.docker-buildx-cache-new s3://docker-buildx-cache/emqx-builder/${{ matrix.platform[0] }}
run: aws s3 sync --delete /tmp/.docker-buildx-cache-new s3://docker-buildx-cache/emqx-builder/${{ steps.base_tag.outputs.tag }}
76 changes: 19 additions & 57 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,14 @@ jobs:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_DEFAULT_REGION }}
- name: define base tag
id: base_tag
run: |
PLATFORM=${{ matrix.platform[1] }}
ARCH=${PLATFORM#linux/}
echo "tag=${{ matrix.platform[0] }}-${ARCH}" | tee -a $GITHUB_OUTPUT
- name: Get cache
run: aws s3 sync s3://docker-buildx-cache/emqx-builder/${{ matrix.platform[0] }} /tmp/.docker-buildx-cache
run: aws s3 sync s3://docker-buildx-cache/emqx-builder/${{ steps.base_tag.outputs.tag }} /tmp/.docker-buildx-cache
- uses: docker/setup-buildx-action@v3
- uses: docker/setup-qemu-action@v3
- uses: docker/login-action@v3
Expand All @@ -89,80 +95,28 @@ jobs:
id: base_meta
with:
images: ${{ env.REGISTRY_IMAGE }}
tags: type=raw,value=${{ matrix.platform[0] }}
tags: type=raw,value=${{ steps.base_tag.outputs.tag }}
- name: Build base image
id: build
uses: docker/build-push-action@v5
with:
pull: true
push: true
cache-from: type=local,src=/tmp/.docker-buildx-cache,mode=max
cache-to: type=local,dest=/tmp/.docker-buildx-cache-new,mode=max
platforms: ${{ matrix.platform[1] }}
tags: ${{ steps.base_meta.outputs.tags }}
labels: ${{ steps.base_meta.outputs.labels }}
file: ${{ matrix.platform[0] }}/Dockerfile
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
context: .
- name: Update cache
run: aws s3 sync --delete /tmp/.docker-buildx-cache-new s3://docker-buildx-cache/emqx-builder/${{ matrix.platform[0] }}
- name: Export digests
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v3
with:
name: digests
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1

merge-base:
runs-on: ubuntu-latest
needs:
- base
strategy:
fail-fast: false
matrix:
base_image_vsn:
- "5.0"
env:
REGISTRY_IMAGE: ghcr.io/${{ github.repository }}/base-${{ matrix.base_image_vsn }}
steps:
- name: Download digests
uses: actions/download-artifact@v3
with:
name: digests
path: /tmp/digests
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY_IMAGE }}
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}
- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
run: aws s3 sync --delete /tmp/.docker-buildx-cache-new s3://docker-buildx-cache/emqx-builder/${{ steps.base_tag.outputs.tag }}

build:
runs-on: ${{ github.repository_owner == 'emqx' && matrix.platform[2] || '["ubuntu-latest"]' }}
needs:
- prepare
- base
- merge-base

strategy:
fail-fast: false
Expand Down Expand Up @@ -223,6 +177,14 @@ jobs:
images: ${{ steps.registry.outputs.image }}
tags: |
type=raw,value=${{ matrix.elixir }}-${{ matrix.otp }}-${{ matrix.platform[0] }}
- name: define base tag
id: base_tag
run: |
PLATFORM=${{ matrix.platform[1] }}
ARCH="${PLATFORM#linux/}"
TAG="${{ matrix.platform[0] }}-${ARCH}"
echo "tag=${TAG}" | tee -a $GITHUB_OUTPUT
echo "image=ghcr.io/${{ github.repository }}/base-${{ matrix.base_image_vsn }}:${TAG}" | tee -a $GITHUB_OUTPUT
- uses: docker/build-push-action@v5
id: build
with:
Expand All @@ -232,7 +194,7 @@ jobs:
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
BUILD_FROM=ghcr.io/${{ github.repository }}/base-${{ matrix.base_image_vsn }}:${{ matrix.platform[0] }}
BUILD_FROM=${{ steps.base_tag.outputs.image }}
OTP_VERSION=${{ matrix.otp }}
ELIXIR_VERSION=${{ matrix.elixir }}
file: ./Dockerfile
Expand Down
27 changes: 17 additions & 10 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,40 +84,47 @@ jobs:
- [alpine3.15.1, linux/amd64, [self-hosted, linux, x64, ephemeral]]
- [alpine3.15.1, linux/arm64, [self-hosted, linux, arm64, ephemeral]]

services:
registry:
image: registry:2
ports:
- 5000:5000

steps:
- uses: actions/checkout@v3
- uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_DEFAULT_REGION }}
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}
- name: define base tag
id: base_tag
run: |
PLATFORM=${{ matrix.platform[1] }}
ARCH="${PLATFORM#linux/}"
TAG="${{ matrix.platform[0] }}-${ARCH}"
echo "tag=${TAG}" | tee -a $GITHUB_OUTPUT
echo "image=ghcr.io/${{ github.repository }}/base-${{ matrix.base_image_vsn }}:${TAG}" | tee -a $GITHUB_OUTPUT
- name: Get cache
run: aws s3 sync s3://docker-buildx-cache/emqx-builder/${{ matrix.platform[0] }} /tmp/.docker-buildx-cache
run: aws s3 sync s3://docker-buildx-cache/emqx-builder/${{ steps.base_tag.outputs.tag }} /tmp/.docker-buildx-cache
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
with:
driver-opts: network=host
- name: Build base image
uses: docker/build-push-action@v5
with:
push: true
push: false
cache-from: type=local,src=/tmp/.docker-buildx-cache,mode=max
platforms: ${{ matrix.platform[1] }}
tags: localhost:5000/${{ github.repository }}/base-${{ matrix.base_image_vsn }}:${{ matrix.platform[0] }}
tags: ${{ steps.base_tag.outputs.image }}
file: ${{ matrix.platform[0] }}/Dockerfile
context: .
- uses: docker/build-push-action@v5
with:
platforms: ${{ matrix.platform[1] }}
cache-from: type=local,src=/tmp/.docker-buildx-cache,mode=max
build-args: |
BUILD_FROM=localhost:5000/${{ github.repository }}/base-${{ matrix.base_image_vsn }}:${{ matrix.platform[0] }}
BUILD_FROM=${{ steps.base_tag.outputs.image }}
OTP_VERSION=${{ matrix.otp }}
ELIXIR_VERSION=${{ matrix.elixir }}
file: ./Dockerfile
Expand Down

0 comments on commit 380676d

Please sign in to comment.