Introduce multi-arch builds with Docker buildx

multi-arch-builds
Tim de Pater 2021-10-07 13:26:36 +02:00
parent 70b353a097
commit 1bf1f811ff
No known key found for this signature in database
GPG Key ID: BFE5D809439C9723
2 changed files with 25 additions and 8 deletions

View File

@ -8,19 +8,26 @@ on:
env:
IMAGE_NAME: trafex/php-nginx
IMAGE_TAG: ${{ github.sha }}
jobs:
deploy:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
- name: Build image
run: |-
docker build -t $IMAGE_NAME .
docker tag $IMAGE_NAME:latest $IMAGE_NAME:${{ github.sha }}
docker build -t $IMAGE_NAME:$IMAGE_TAG .
- name: Smoke test image
run: |-
@ -47,17 +54,26 @@ jobs:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Push latest image
- name: Build multi-arch image and push latest tag
if: github.ref == 'refs/heads/master' && github.event_name == 'push'
run: |-
docker push $IMAGE_NAME:latest
docker buildx build \
--cache-from=$IMAGE_NAME:latest
--push \
-t $IMAGE_NAME:latest \
--platform linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6 \
.
- name: Set tag in environment
if: contains(github.ref, 'refs/tags/')
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Push tagged image
- name: Build multi-arch image and push release tag
if: contains(github.ref, 'refs/tags/')
run: |-
docker tag $IMAGE_NAME:${{ github.sha }} $IMAGE_NAME:$RELEASE_VERSION
docker push $IMAGE_NAME:$RELEASE_VERSION
docker buildx build \
--cache-from=$IMAGE_NAME:latest
--push \
-t $IMAGE_NAME:$RELEASE_VERSION \
--platform linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6 \
.

View File

@ -1,6 +1,7 @@
version: '3.5'
services:
app:
image: ${IMAGE_NAME}:${IMAGE_TAG}
build: .
sut:
image: alpine:3.13