Skip to content

Commit

Permalink
chore: build for multiple architectures on release (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
kylecarbs authored Oct 2, 2023
1 parent 1e03bc8 commit 426696c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
go-version: "~1.20"

- name: Build
run: ./scripts/build.sh
run: ./scripts/build.sh --arch=amd64 --arch=arm64 --arch=arm

- name: Docker Login
uses: docker/login-action@v2
Expand All @@ -52,8 +52,8 @@ jobs:
VERSION=$(./scripts/version.sh)
BASE=ghcr.io/coder/envbuilder
IMAGE=$BASE:$VERSION
docker tag envbuilder:latest $IMAGE
docker tag envbuilder:latest $BASE:latest
docker push $IMAGE
for arch in ( amd64 arm64 arm ); do
docker tag envbuilder:$arch $IMAGE-$arch
docker push $IMAGE-$arch
done
docker push $BASE:latest
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
scripts/envbuilder
scripts/envbuilder-*
3 changes: 2 additions & 1 deletion scripts/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM scratch
ARG PLATFORM

COPY envbuilder /.envbuilder/bin/envbuilder
COPY envbuilder-${PLATFORM} /.envbuilder/bin/envbuilder

ENV KANIKO_DIR /.envbuilder
# Kaniko looks for the Docker config at $DOCKER_CONFIG/config.json
Expand Down
32 changes: 29 additions & 3 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,33 @@
#!/usr/bin/env bash

cd $(dirname "${BASH_SOURCE[0]}")
set -euxo pipefail
set -euo pipefail

CGO_ENABLED=0 go build -o ./envbuilder ../cmd/envbuilder
docker build -t envbuilder:latest .
archs=()
for arg in "$@"; do
if [[ $arg == --arch=* ]]; then
arch="${arg#*=}"
archs+=( "$arch" )
else
echo "Unknown argument: $arg"
exit 1
fi
done

current=$(go env GOARCH)
if [ ${#archs[@]} -eq 0 ]; then
echo "No architectures specified. Defaulting to $current..."
archs=( "$current" )
fi

for arch in "${archs[@]}"; do
GOARCH=$arch CGO_ENABLED=0 go build -o ./envbuilder-$arch ../cmd/envbuilder && \
docker build --build-arg PLATFORM=$arch -t envbuilder:${arch} -f Dockerfile . &
done
wait

# Check if archs contains the current. If so, then output a message!
if [[ " ${archs[@]} " =~ " ${current} " ]]; then
docker tag envbuilder:${arch} envbuilder:latest
echo "Tagged $current as envbuilder:latest!"
fi

0 comments on commit 426696c

Please sign in to comment.