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 a makefile command to assist with multi-arch builds #68

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
76 changes: 76 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Release
on:
workflow_dispatch:
inputs:
bump-type:
type: choice
description: The position of the version to be bumped.
options:
- patch
- minor
- major
tag_to_move:
type: choice
description: The generic tag to be advanced.
options:
- v1
Comment on lines +5 to +16
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Options to select which part of the version to bump, and the generic tag to move on running this job.

jobs:

test-and-lint:
name: Test and Lint
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Lint
run: make lint
- name: Test
run: make test

multi-arch-build-and-push:
name: Build Multi Arch Containers
runs-on: ubuntu-latest
needs: [test-and-lint]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up QEMU
# Add support for more platforms with QEMU (optional)
# https://github.com/docker/setup-qemu-action
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Docker Login
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Bump version and push tag
id: tag_version
uses: mathieudutour/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
default_bump: ${{ github.event.inputs.bump-type }}
Comment on lines +50 to +55
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will select the new version and tag the repo

- name: Build Release Container
env:
VERSION: ${{ steps.tag_version.outputs.new_version }}
run: make buildx
Comment on lines +58 to +59
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use that new version for the multi-arch build

- name: Move Generic Tag Version

advance-generic-tag:
runs-on: ubuntu-latest
needs: [multi-arch-build-and-push]
Bwvolleyball marked this conversation as resolved.
Show resolved Hide resolved
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Git config
run: |
git config user.name "GitHub Action"
git config user.email "[email protected]"
- name: Tag new target
run: git tag -f ${{ github.event.inputs.tag_to_move }} ${{ github.event.inputs.target }}
- name: Push new tag
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will advance the v1 tag to this new version

run: git push origin ${{ github.event.inputs.tag_to_move }} --force
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
IMAGE_REPO=ghcr.io/trstringer/manual-approval

# Great for building a single architecture's image
.PHONY: build
build:
@if [ -z "$$VERSION" ]; then \
Expand All @@ -23,3 +24,14 @@ test:
.PHONY: lint
lint:
docker run --rm -v $$(pwd):/app -w /app golangci/golangci-lint:v1.46.2 golangci-lint run -v

# Builds multiple architectures at once.
# Requires docker buildx and QEMU to be configured.
# Because of how docker buildx works, in that it _must_ push when it builds, push is the default of this task.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand why a push is required. Why do we want our build command to automatically push the image?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nuance of how buildx works. It doesn't allow for building first, then pushing later, so, if you want to push the image that is produced by the multi-arch build, it has to be done at build time with this flag.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ultimately, this buildx tasks should be what is used for CI/CD to build and push multi-arch images, and the old build and push tasks can be used for testing / development things.

.PHONY: buildx
buildx:
@if [ -z "$$VERSION" ]; then \
echo "VERSION is required"; \
exit 1; \
fi
docker buildx build -t $(IMAGE_REPO):$$VERSION --platform linux/amd64,linux/arm64 --push .