diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 39c74e1f..140268e5 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -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 @@ -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 - diff --git a/.gitignore b/.gitignore index f2a02fdf..001aeac3 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -scripts/envbuilder \ No newline at end of file +scripts/envbuilder-* diff --git a/scripts/Dockerfile b/scripts/Dockerfile index 8490f027..8bcf7538 100644 --- a/scripts/Dockerfile +++ b/scripts/Dockerfile @@ -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 diff --git a/scripts/build.sh b/scripts/build.sh index 6f9a048a..f847c656 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -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