-
Notifications
You must be signed in to change notification settings - Fork 592
Add container image support with multi-arch builds #2851
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
base: master
Are you sure you want to change the base?
Changes from all commits
ef3afe8
86c962f
6b8e128
a593fab
224544c
89d3541
ff8e6f4
c852393
9f8c939
7407512
9f605fd
ce0e6d4
173cbbe
c8e81ae
5ba73ed
2d60cd1
024d275
30844eb
bf820ad
db30ade
7941449
fc0b7d3
4d25179
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
name: Container Image | ||
|
||
on: | ||
|
||
# Manual trigger via GH Actions page, runs this workflow from a selected tag or branch, | ||
# which also affects the git clone for the `Dockerfile` used, and `github.ref_type` (branch / tag) | ||
workflow_dispatch: | ||
inputs: | ||
version: | ||
description: 'Version to build (e.g., 1.42.4)' | ||
required: true | ||
type: string | ||
|
||
# `release.yaml` calls this workflow after it has published a new release and attached files. | ||
# NOTE: As `release.yaml` is triggered via a tag being pushed, this workflow inherits | ||
# that push event context (github.{event_name, event, ref_type, ref_name, ...}) | ||
workflow_call: | ||
inputs: | ||
version: | ||
description: 'Version to build (e.g., 1.42.4)' | ||
required: true | ||
type: string | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
IMAGE_NAME: ${{ github.repository }} | ||
|
||
jobs: | ||
container: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
elasticdotventures marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
elasticdotventures marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- name: Log in to Container Registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Prepare image metadata | ||
id: metadata | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
# NOTE: The `semver` tag type below (with the default `flavor.latest=auto` action setting), | ||
# will implicitly append a `latest` tag to publish: | ||
# https://github.com/docker/metadata-action/issues/461#issuecomment-2680849083 | ||
tags: | | ||
type=semver,pattern={{major}},value=${{ inputs.version }} | ||
type=semver,pattern={{major}}.{{minor}},value=${{ inputs.version }} | ||
type=semver,pattern={{major}}.{{minor}}.{{patch}},value=${{ inputs.version }} | ||
|
||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v6 | ||
with: | ||
context: . | ||
platforms: linux/amd64,linux/arm64 | ||
push: true | ||
tags: ${{ steps.metadata.outputs.tags }} | ||
labels: ${{ steps.metadata.outputs.labels }} | ||
build-args: | | ||
JUST_VERSION=${{ inputs.version }} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -203,3 +203,14 @@ jobs: | |
github_token: ${{secrets.GITHUB_TOKEN}} | ||
publish_branch: gh-pages | ||
publish_dir: www | ||
|
||
container: | ||
uses: ./.github/workflows/container.yaml | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No action required, just informative for those unaware. For reference: This will run the
However if it was desirable to fix That said, in other contexts doing so can be problematic when other branches are used such as a PR update for a workflow that is triggered by PRs, or breaking changes affecting other long-lived branches or forks (if neither patched workflows that weren't restricted to the default branch to trigger). The alternative with a specific git ref would look like this (the owner + repo prefix is mandatory however and expressions cannot be used for the benefit of forks or copy/paste): container:
uses: casey/just/.github/workflows/container.yaml@master |
||
needs: | ||
- package | ||
- prerelease | ||
# Avoid publishing images for pre-releases (NOTE: `value` is a string, not a boolean) | ||
if: ${{ needs.prerelease.outputs.value == 'false' }} | ||
with: | ||
version: ${{ github.ref_name }} | ||
secrets: inherit |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,30 @@ | ||||||||||||||||||||||||||||||||||||||||||
# syntax=docker/dockerfile:1 | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
# NOTE: ARGs `BUILDPLATFORM` + `TARGETARCH` are implicitly defined by BuildKit: | ||||||||||||||||||||||||||||||||||||||||||
# https://docs.docker.com/reference/dockerfile/#automatic-platform-args-in-the-global-scope | ||||||||||||||||||||||||||||||||||||||||||
# NOTE: BuildKit supplied ARGs use convention amd64 / arm64 instead of the desired x86_64 / aarch64 | ||||||||||||||||||||||||||||||||||||||||||
# https://itsfoss.com/arm-aarch64-x86_64 | ||||||||||||||||||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||||||||||||||||||
# Map arch naming conventions from BuildKit to Rust (TARGETARCH => RUST_ARCH): | ||||||||||||||||||||||||||||||||||||||||||
FROM --platform=${BUILDPLATFORM} alpine AS downloader-amd64 | ||||||||||||||||||||||||||||||||||||||||||
ARG RUST_ARCH=x86_64 | ||||||||||||||||||||||||||||||||||||||||||
FROM --platform=${BUILDPLATFORM} alpine AS downloader-arm64 | ||||||||||||||||||||||||||||||||||||||||||
ARG RUST_ARCH=aarch64 | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
# Fetch the expected version of `just` via GH Releases: | ||||||||||||||||||||||||||||||||||||||||||
FROM downloader-${TARGETARCH} AS downloader | ||||||||||||||||||||||||||||||||||||||||||
SHELL ["/bin/ash", "-eux", "-o", "pipefail", "-c"] | ||||||||||||||||||||||||||||||||||||||||||
# This ARG will be set via GitHub Actions during release builds | ||||||||||||||||||||||||||||||||||||||||||
ARG JUST_VERSION | ||||||||||||||||||||||||||||||||||||||||||
ARG RELEASE_URL="https://github.com/casey/just/releases/download/${JUST_VERSION}/just-${JUST_VERSION}-${RUST_ARCH}-unknown-linux-musl.tar.gz" | ||||||||||||||||||||||||||||||||||||||||||
RUN wget -O - "${RELEASE_URL}" \ | ||||||||||||||||||||||||||||||||||||||||||
| tar --directory /usr/local/bin --extract --gzip --no-same-owner just | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
# Use scratch for minimal final image - no OS, just the binary | ||||||||||||||||||||||||||||||||||||||||||
# This results in a ~10MB image vs ~50MB+ with a full OS | ||||||||||||||||||||||||||||||||||||||||||
FROM scratch | ||||||||||||||||||||||||||||||||||||||||||
COPY --from=downloader /usr/local/bin/just /usr/local/bin/just | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
# Default to running just with help if no arguments provided | ||||||||||||||||||||||||||||||||||||||||||
ENTRYPOINT ["just"] | ||||||||||||||||||||||||||||||||||||||||||
CMD ["--help"] | ||||||||||||||||||||||||||||||||||||||||||
elasticdotventures marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+23
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assuming you agree with the prior
Suggested change
Otherwise update the README to inform users about the image not being intended for direct usage, so they don't burden the maintainer with support requests.
Comment on lines
+23
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As previously detailed in feedback. 5MB => 13MB increase, but the image can be used directly.
Suggested change
No need to update README to mention the lack of a shell if adopting this change. |
Uh oh!
There was an error while loading. Please reload this page.