-
Notifications
You must be signed in to change notification settings - Fork 6
feat: build and publish multiarch image #46
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
Changes from all commits
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 |
---|---|---|
|
@@ -19,47 +19,29 @@ jobs: | |
name: Build and publish | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Echo Go Cache Paths | ||
id: go-cache-paths | ||
run: | | ||
echo "GOCACHE=$(go env GOCACHE)" >> ${{ runner.os == 'Windows' && '$env:' || '$' }}GITHUB_OUTPUT | ||
echo "GOMODCACHE=$(go env GOMODCACHE)" >> ${{ runner.os == 'Windows' && '$env:' || '$' }}GITHUB_OUTPUT | ||
|
||
- name: Go Build Cache | ||
uses: actions/cache@v3 | ||
with: | ||
path: ${{ steps.go-cache-paths.outputs.GOCACHE }} | ||
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.**', '**.go') }} | ||
|
||
- uses: actions/setup-go@v5 | ||
Comment on lines
-24
to
-36
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. setup-go has a built-in cache that works as expected. |
||
- name: Setup Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: "~1.22" | ||
|
||
- name: Get Version | ||
run: echo "version=$(./scripts/version.sh)" >> $GITHUB_OUTPUT | ||
id: version | ||
|
||
- name: Build | ||
run: ./scripts/build.sh | ||
|
||
- name: Docker Login | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Push Image | ||
run: | | ||
VERSION=$(./scripts/version.sh) | ||
BASE=ghcr.io/coder/coder-logstream-kube | ||
IMAGE=$BASE:$VERSION | ||
docker tag coder-logstream-kube:latest $IMAGE | ||
docker tag coder-logstream-kube:latest $BASE:latest | ||
docker push $IMAGE | ||
docker push $BASE:latest | ||
Comment on lines
-54
to
-62
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. moved pushing and building to the |
||
- name: Build and Push Docker Image | ||
run: ./scripts/build.sh | ||
env: | ||
CI: true | ||
|
||
- name: Authenticate to Google Cloud | ||
uses: google-github-actions/auth@v2 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
coder-logstream-kube | ||
coder-logstream-kube-* | ||
build |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
FROM scratch | ||
|
||
COPY ./coder-logstream-kube /coder-logstream-kube | ||
|
||
ENTRYPOINT ["/coder-logstream-kube"] | ||
FROM --platform=$BUILDPLATFORM scratch AS base | ||
ARG TARGETARCH | ||
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. reviewer note: this comes from ref: https://docs.docker.com/build/guide/multi-platform/#platform-build-arguments |
||
COPY ./coder-logstream-kube-${TARGETARCH} /coder-logstream-kube | ||
ENTRYPOINT ["/coder-logstream-kube"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,44 @@ | ||
#!/usr/bin/env bash | ||
|
||
cd $(dirname "${BASH_SOURCE[0]}") | ||
cd "$(dirname "${BASH_SOURCE[0]}")" | ||
set -euxo pipefail | ||
|
||
CGO_ENABLED=0 go build -ldflags "-s -w" -o ./coder-logstream-kube ../ | ||
docker build -t coder-logstream-kube:latest . | ||
# Set CI to false if not set | ||
CI=${CI:-false} | ||
|
||
# Get current architecture | ||
current=$(go env GOARCH) | ||
# Arhcitectures to build for | ||
archs=(amd64 arm64 arm) | ||
matifali marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# build for all architectures | ||
for arch in "${archs[@]}"; do | ||
echo "Building for $arch" | ||
GOARCH=$arch GOOS=linux CGO_ENABLED=0 go build -ldflags "-s -w" -o ./coder-logstream-kube-"$arch" ../ | ||
done | ||
|
||
# We have to use docker buildx to tag multiple images with | ||
# platforms tragically, so we have to create a builder. | ||
BUILDER_NAME="coder-logstream-kube" | ||
BUILDER_EXISTS=$(docker buildx ls | grep $BUILDER_NAME || true) | ||
|
||
# If builder doesn't exist, create it | ||
if [ -z "$BUILDER_EXISTS" ]; then | ||
echo "Creating dockerx builder $BUILDER_NAME..." | ||
docker buildx create --use --platform=linux/arm64,linux/amd64,linux/arm/v7 --name $BUILDER_NAME | ||
else | ||
echo "Builder $BUILDER_NAME already exists. Using it." | ||
fi | ||
|
||
# Ensure the builder is bootstrapped and ready to use | ||
docker buildx inspect --bootstrap &>/dev/null | ||
|
||
# Build | ||
if [ "$CI" = "false" ]; then | ||
docker buildx build --platform linux/"$current" -t coder-logstream-kube --load . | ||
else | ||
VERSION=$(../scripts/version.sh) | ||
BASE=ghcr.io/coder/coder-logstream-kube | ||
IMAGE=$BASE:$VERSION | ||
docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t "$IMAGE" -t $BASE:latest --push. | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setup-go has a built-in cache that works as expected.