Skip to content

Commit

Permalink
fix: properly define architectures in release script
Browse files Browse the repository at this point in the history
  • Loading branch information
kylecarbs committed Oct 2, 2023
1 parent 426696c commit 8e56e29
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 14 deletions.
19 changes: 9 additions & 10 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,22 @@ jobs:
with:
go-version: "~1.20"

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

- name: Docker Login
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Push
- name: Build and Push
run: |
VERSION=$(./scripts/version.sh)
BASE=ghcr.io/coder/envbuilder
IMAGE=$BASE:$VERSION
for arch in ( amd64 arm64 arm ); do
docker tag envbuilder:$arch $IMAGE-$arch
docker push $IMAGE-$arch
done
docker push $BASE:latest
./scripts/build.sh \
--arch=amd64 \
--arch=arm64 \
--arch=arm \
--base=$BASE \
--tag=$VERSION
--push
4 changes: 2 additions & 2 deletions scripts/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM scratch
ARG PLATFORM
ARG TARGETARCH

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

ENV KANIKO_DIR /.envbuilder
# Kaniko looks for the Docker config at $DOCKER_CONFIG/config.json
Expand Down
43 changes: 41 additions & 2 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,20 @@ cd $(dirname "${BASH_SOURCE[0]}")
set -euo pipefail

archs=()
push=false
base="envbuilder"
tag="latest"

for arg in "$@"; do
if [[ $arg == --arch=* ]]; then
arch="${arg#*=}"
archs+=( "$arch" )
elif [[ $arg == --push ]]; then
push=true
elif [[ $arg == --base=* ]]; then
base="${arg#*=}"
elif [[ $arg == --tag=* ]]; then
tag="${arg#*=}"
else
echo "Unknown argument: $arg"
exit 1
Expand All @@ -20,12 +30,41 @@ if [ ${#archs[@]} -eq 0 ]; then
archs=( "$current" )
fi

# We have to use docker buildx to tag multiple images with
# platforms tragically, so we have to create a builder.
BUILDER_NAME="envbuilder"
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."
docker buildx use $BUILDER_NAME
fi

# Ensure the builder is bootstrapped and ready to use
docker buildx inspect --bootstrap

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 . &
echo "Building for $arch..."
GOARCH=$arch CGO_ENABLED=0 go build -o ./envbuilder-$arch ../cmd/envbuilder &
done
wait

args=()
for arch in "${archs[@]}"; do
args+=( --platform linux/$arch )
done
if [ "$push" = true ]; then
args+=( --push )
else
args+=( --load )
fi

docker buildx build "${args[@]}" -t $base:$tag -t $base:latest -f Dockerfile .

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

0 comments on commit 8e56e29

Please sign in to comment.