Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multi-arch build #162

Merged
merged 3 commits into from
Sep 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 89 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ jobs:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up QEMU
uses: docker/setup-qemu-action@master
with:
platforms: all

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

Expand Down Expand Up @@ -75,6 +80,7 @@ jobs:
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
target: production
platforms: linux/amd64,linux/arm64,linux/arm/v7

- name: Build and push (testing image)
uses: docker/build-push-action@v2
Expand All @@ -91,23 +97,91 @@ jobs:
tags: ${{ steps.docker_meta_testing.outputs.tags }}
labels: ${{ steps.docker_meta_testing.outputs.labels }}
target: testing
platforms: linux/amd64,linux/arm64,linux/arm/v7

build-e2e:
runs-on: ubuntu-20.04

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Docker meta (e2e)
id: docker_meta_testing
uses: docker/metadata-action@v3
with:
images: mormahr/pdf-service
flavor: |
latest=false
suffix=-e2e
tags: |
type=ref,event=branch
type=ref,event=pr
type=edge,branch=main
type=sha,format=long
labels: |
org.opencontainers.image.vendor=Moritz Mahringer

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Extract branch name
shell: bash
run: |
BRANCH=${GITHUB_REF#refs/heads/}
SAFE_BRANCH=${BRANCH//\//_}
echo "##[set-output name=branch;]$(echo $SAFE_BRANCH)"
id: extract_branch

- name: Build and push (e2e image)
uses: docker/build-push-action@v2
with:
context: e2e
push: ${{ github.event_name != 'pull_request' }}
build-args: GITHUB_SHA=${{ github.sha }}
cache-from: |
type=registry,ref=mormahr/pdf-service:main-e2e
type=registry,ref=mormahr/pdf-service:${{ steps.extract_branch.outputs.branch }}-e2e
cache-to: type=inline
tags: ${{ steps.docker_meta_testing.outputs.tags }}
labels: ${{ steps.docker_meta_testing.outputs.labels }}

test:
runs-on: ubuntu-20.04
needs:
- build

strategy:
matrix:
platform:
- "linux/amd64"
- "linux/arm64"
- "linux/arm/v7"

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up QEMU
uses: docker/setup-qemu-action@master
with:
platforms: ${{ matrix.platform }}
if: ${{ matrix.platform != 'linux/amd64' }}

- name: Run tests
run: |
mkdir coverage
chown 1001 coverage

docker run \
--rm \
--platform=${{ matrix.platform }} \
--user pdf_service_user \
-v "$(pwd)/coverage:/usr/src/app/coverage/" \
mormahr/pdf-service:sha-${{ github.sha }}-testing \
Expand All @@ -133,16 +207,30 @@ jobs:
runs-on: ubuntu-20.04
needs:
- build
- build-e2e

strategy:
matrix:
platform:
- "linux/amd64"
- "linux/arm64"
- "linux/arm/v7"

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up QEMU
uses: docker/setup-qemu-action@master
with:
platforms: ${{ matrix.platform }}
if: ${{ matrix.platform != 'linux/amd64' }}

- name: Run visual tests
run: |
cd e2e
export TAG="sha-$GITHUB_SHA"
docker-compose build test
export PLATFORM="${{ matrix.platform }}"
docker-compose run --rm test

tag:
Expand Down
4 changes: 3 additions & 1 deletion e2e/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ version: "3.8"
services:
pdf:
image: "mormahr/pdf-service:${TAG}"
platform: ${PLATFORM}

test:
build: .
image: "mormahr/pdf-service:${TAG}-e2e"
links:
- "pdf:pdf"