- Notifications
You must be signed in to change notification settings - Fork6
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -30,20 +30,8 @@ jobs: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
Comment on lines -33 to -45 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" | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -19,47 +19,29 @@ jobs: | ||
name: Build and publish | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
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: Docker Login | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
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-* | ||
build |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
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]}")" | ||
set -euxo pipefail | ||
# 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 resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
# 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 |