Skip to content

Commit

Permalink
Added: Multi-platform docker builds
Browse files Browse the repository at this point in the history
  • Loading branch information
danielunderwood committed Jan 7, 2022
1 parent da35aad commit be64672
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: Go

on: [push, pull_request]
env:
IMAGE_NAME: feed-parser

jobs:
CodeQL:
Expand Down Expand Up @@ -48,25 +46,31 @@ jobs:

steps:
- 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
with:
install: true

- name: Build image
run: docker build . --file Dockerfile --tag $IMAGE_NAME
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Log into registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin

- name: Push image
- name: Generate image tag
run: |
IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "main" ] && VERSION=latest
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
export VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,'
echo VERSION=$VERSION >> $GITHUB_ENV
- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: |
ghcr.io/danielunderwood/feed-ingress:latest
ghcr.io/danielunderwood/feed-ingress:${{ env.VERSION }}

0 comments on commit be64672

Please sign in to comment.