Skip to content

Commit 2fae97e

Browse files
committed
feat: add multiarch image and simplify ci
1 parent b9d65a1 commit 2fae97e

File tree

5 files changed

+55
-48
lines changed

5 files changed

+55
-48
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,8 @@ jobs:
3030
- name: Checkout
3131
uses: actions/checkout@v4
3232

33-
- name: Echo Go Cache Paths
34-
id: go-cache-paths
35-
run: |
36-
echo "GOCACHE=$(go env GOCACHE)" >> ${{ runner.os == 'Windows' && '$env:' || '$' }}GITHUB_OUTPUT
37-
echo "GOMODCACHE=$(go env GOMODCACHE)" >> ${{ runner.os == 'Windows' && '$env:' || '$' }}GITHUB_OUTPUT
38-
39-
- name: Go Build Cache
40-
uses: actions/cache@v3
41-
with:
42-
path: ${{ steps.go-cache-paths.outputs.GOCACHE }}
43-
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.**', '**.go') }}
44-
45-
# Install Go!
46-
- uses: actions/setup-go@v5
33+
- name: Setup Go
34+
uses: actions/setup-go@v5
4735
with:
4836
go-version: "~1.22"
4937

.github/workflows/release.yaml

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,47 +19,29 @@ jobs:
1919
name: Build and publish
2020
runs-on: ubuntu-latest
2121
steps:
22-
- uses: actions/checkout@v4
22+
- name: Checkout
23+
uses: actions/checkout@v4
2324

24-
- name: Echo Go Cache Paths
25-
id: go-cache-paths
26-
run: |
27-
echo "GOCACHE=$(go env GOCACHE)" >> ${{ runner.os == 'Windows' && '$env:' || '$' }}GITHUB_OUTPUT
28-
echo "GOMODCACHE=$(go env GOMODCACHE)" >> ${{ runner.os == 'Windows' && '$env:' || '$' }}GITHUB_OUTPUT
29-
30-
- name: Go Build Cache
31-
uses: actions/cache@v3
32-
with:
33-
path: ${{ steps.go-cache-paths.outputs.GOCACHE }}
34-
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.**', '**.go') }}
35-
36-
- uses: actions/setup-go@v5
25+
- name: Setup Go
26+
uses: actions/setup-go@v5
3727
with:
3828
go-version: "~1.22"
3929

4030
- name: Get Version
4131
run: echo "version=$(./scripts/version.sh)" >> $GITHUB_OUTPUT
4232
id: version
4333

44-
- name: Build
45-
run: ./scripts/build.sh
46-
4734
- name: Docker Login
4835
uses: docker/login-action@v3
4936
with:
5037
registry: ghcr.io
5138
username: ${{ github.actor }}
5239
password: ${{ secrets.GITHUB_TOKEN }}
5340

54-
- name: Push Image
55-
run: |
56-
VERSION=$(./scripts/version.sh)
57-
BASE=ghcr.io/coder/coder-logstream-kube
58-
IMAGE=$BASE:$VERSION
59-
docker tag coder-logstream-kube:latest $IMAGE
60-
docker tag coder-logstream-kube:latest $BASE:latest
61-
docker push $IMAGE
62-
docker push $BASE:latest
41+
- name: Build and Push Docker Image
42+
run: ./scripts/build.sh
43+
env:
44+
CI: true
6345

6446
- name: Authenticate to Google Cloud
6547
uses: google-github-actions/auth@v2

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
coder-logstream-kube
1+
coder-logstream-kube-*
22
build

scripts/Dockerfile

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
FROM scratch
2-
3-
COPY ./coder-logstream-kube /coder-logstream-kube
4-
5-
ENTRYPOINT ["/coder-logstream-kube"]
1+
FROM --platform=$BUILDPLATFORM scratch AS base
2+
ARG TARGETARCH
3+
COPY ./coder-logstream-kube-${TARGETARCH} /coder-logstream-kube
4+
ENTRYPOINT ["/coder-logstream-kube"]

scripts/build.sh

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,43 @@
33
cd $(dirname "${BASH_SOURCE[0]}")
44
set -euxo pipefail
55

6-
CGO_ENABLED=0 go build -ldflags "-s -w" -o ./coder-logstream-kube ../
7-
docker build -t coder-logstream-kube:latest .
6+
# Set CI to false if not set
7+
CI=${CI:-false}
8+
9+
10+
# Get current architecture
11+
current=$(go env GOARCH)
12+
# Arhcitectures to build for
13+
archs=(amd64 arm64 arm)
14+
15+
# build for all architectures
16+
for arch in "${archs[@]}"; do
17+
echo "Building for $arch"
18+
GOARCH=$arch GOOS=linux CGO_ENABLED=0 go build -ldflags "-s -w" -o ./coder-logstream-kube-$arch ../
19+
done
20+
21+
# We have to use docker buildx to tag multiple images with
22+
# platforms tragically, so we have to create a builder.
23+
BUILDER_NAME="coder-logstream-kube"
24+
BUILDER_EXISTS=$(docker buildx ls | grep $BUILDER_NAME || true)
25+
26+
# If builder doesn't exist, create it
27+
if [ -z "$BUILDER_EXISTS" ]; then
28+
echo "Creating dockerx builder $BUILDER_NAME..."
29+
docker buildx create --use --platform=linux/arm64,linux/amd64,linux/arm/v7 --name $BUILDER_NAME
30+
else
31+
echo "Builder $BUILDER_NAME already exists. Using it."
32+
fi
33+
34+
# Ensure the builder is bootstrapped and ready to use
35+
docker buildx inspect --bootstrap &> /dev/null
36+
37+
# Build
38+
if [ "$CI" = "false" ]; then
39+
docker buildx build --platform linux/$current -t coder-logstream-kube --load .
40+
else
41+
VERSION=$(../scripts/version.sh)
42+
BASE=ghcr.io/coder/coder-logstream-kube
43+
IMAGE=$BASE:$VERSION
44+
docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t $IMAGE -t $BASE:latest --push.
45+
fi

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy