Skip to content

Commit

Permalink
Merge pull request #34 from DeNA/arm
Browse files Browse the repository at this point in the history
Add builds for ARM64
  • Loading branch information
Kuniwak authored Apr 24, 2024
2 parents 39b60d9 + 23663ee commit 40e039e
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2
jobs:
go_get:
docker:
- image: cimg/go:1.19
- image: cimg/go:1.22.2
steps:
- run:
name: Test go get
Expand Down
11 changes: 2 additions & 9 deletions .circleci/images/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
# image-name: ghcr.io/dena/unity-meta-check/unity-meta-check-circleci
FROM golang:1.19-buster as builder
WORKDIR /go/src/unity-meta-check
COPY . .
RUN make out/unity-meta-check-linux-amd64 out/unity-meta-check-junit-linux-amd64 out/unity-meta-check-github-pr-comment-linux-amd64 out/unity-meta-autofix-linux-amd64 && \
mv ./out/unity-meta-check-linux-amd64 ./out/unity-meta-check && \
mv ./out/unity-meta-check-junit-linux-amd64 ./out/unity-meta-check-junit && \
mv ./out/unity-meta-check-github-pr-comment-linux-amd64 ./out/unity-meta-check-github-pr-comment && \
mv ./out/unity-meta-autofix-linux-amd64 ./out/unity-meta-autofix
FROM ghcr.io/dena/unity-meta-check/unity-meta-check-builder:latest as builder

FROM debian:buster-slim
FROM debian:bookworm-slim
# https://circleci.com/docs/2.0/custom-images/#required-tools-for-primary-containers
RUN apt-get update \
&& apt-get install --yes --no-install-recommends git openssh-server tar gzip ca-certificates \
Expand Down
9 changes: 3 additions & 6 deletions .github/images/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
# image-name: ghcr.io/dena/unity-meta-check/unity-meta-check-gh-action
FROM golang:1.19-buster as builder
WORKDIR /go/src/unity-meta-check
COPY . .
RUN make out/gh-action-linux-amd64 && mv ./out/gh-action-linux-amd64 ./out/gh-action
FROM ghcr.io/dena/unity-meta-check/unity-meta-check-builder:latest as builder

FROM debian:buster-slim
FROM debian:bookworm-slim
RUN apt-get update \
&& apt-get install --yes --no-install-recommends git ca-certificates \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
COPY --from=builder /go/src/unity-meta-check/out/* /usr/bin/
COPY --from=builder /go/src/unity-meta-check/out/gh-action /usr/bin/
ENTRYPOINT ["gh-action"]
CMD ["-help"]
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ jobs:
- windows-latest
- macos-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: actions/setup-go@v4
with:
go-version: 1.19
go-version: 1.22.2
- run: go test -v ./...
11 changes: 2 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
# image-name: ghcr.io/dena/unity-meta-check/unity-meta-check
FROM golang:1.19-buster as builder
WORKDIR /go/src/unity-meta-check
COPY . .
RUN make out/unity-meta-check-linux-amd64 out/unity-meta-check-junit-linux-amd64 out/unity-meta-check-github-pr-comment-linux-amd64 out/unity-meta-autofix-linux-amd64 && \
mv ./out/unity-meta-check-linux-amd64 ./out/unity-meta-check && \
mv ./out/unity-meta-check-junit-linux-amd64 ./out/unity-meta-check-junit && \
mv ./out/unity-meta-check-github-pr-comment-linux-amd64 ./out/unity-meta-check-github-pr-comment && \
mv ./out/unity-meta-autofix-linux-amd64 ./out/unity-meta-autofix
FROM ghcr.io/dena/unity-meta-check/unity-meta-check-builder:latest as builder

FROM debian:buster-slim
FROM debian:bookworm-slim
RUN apt-get update \
&& apt-get install --yes --no-install-recommends git \
&& apt-get clean \
Expand Down
78 changes: 76 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
all: darwin-amd64 linux-amd64 windows-amd64
all: darwin-amd64 linux-amd64 windows-amd64 darwin-arm64 linux-arm64 windows-arm64


clean:
Expand Down Expand Up @@ -38,6 +38,30 @@ out/gh-action-darwin-amd64: out
CGO_ENABLED=0 GOARCH=amd64 GOOS=darwin go build -v -o "$@" ./tool/gh-action


darwin-arm64: out/unity-meta-check-darwin-arm64 out/unity-meta-check-junit-darwin-arm64 out/unity-meta-check-github-pr-comment-darwin-arm64 out/unity-meta-autofix-darwin-arm64 out/gh-action-yaml-gen-darwin-arm64

out/unity-meta-check-darwin-arm64: out
CGO_ENABLED=0 GOARCH=arm64 GOOS=darwin go build -v -o "$@"

out/unity-meta-check-junit-darwin-arm64: out
CGO_ENABLED=0 GOARCH=arm64 GOOS=darwin go build -v -o "$@" ./tool/unity-meta-check-junit

out/unity-meta-check-github-pr-comment-darwin-arm64: out
GOARCH=arm64 GOOS=darwin go build -a -tags netgo -installsuffix netgo -v -o "$@" ./tool/unity-meta-check-github-pr-comment

out/unity-meta-check-meta-audit-darwin-arm64: out
CGO_ENABLED=0 GOARCH=arm64 GOOS=darwin go build -v -o "$@" ./tool/unity-meta-check-meta-audit

out/unity-meta-autofix-darwin-arm64: out
CGO_ENABLED=0 GOARCH=arm64 GOOS=darwin go build -v -o "$@" ./tool/unity-meta-autofix

out/gh-action-yaml-gen-darwin-arm64: out
CGO_ENABLED=0 GOARCH=arm64 GOOS=darwin go build -v -o "$@" ./tool/gh-action/action-yaml-gen

out/gh-action-darwin-arm64: out
CGO_ENABLED=0 GOARCH=arm64 GOOS=darwin go build -v -o "$@" ./tool/gh-action


# NOTE: meta-audit は Debug 用ツールなので必要になったら生成してください(生成されちゃうと Releases へあげるときに間引かないといけなくてめんどい)
linux-amd64: out/unity-meta-check-linux-amd64 out/unity-meta-check-junit-linux-amd64 out/unity-meta-check-github-pr-comment-linux-amd64 out/unity-meta-autofix-linux-amd64 out/gh-action-yaml-gen-linux-amd64 out/gh-action-linux-amd64

Expand All @@ -63,6 +87,31 @@ out/gh-action-linux-amd64: out
CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -v -o "$@" ./tool/gh-action


# NOTE: meta-audit は Debug 用ツールなので必要になったら生成してください(生成されちゃうと Releases へあげるときに間引かないといけなくてめんどい)
linux-arm64: out/unity-meta-check-linux-arm64 out/unity-meta-check-junit-linux-arm64 out/unity-meta-check-github-pr-comment-linux-arm64 out/unity-meta-autofix-linux-arm64 out/gh-action-yaml-gen-linux-arm64 out/gh-action-linux-arm64

out/unity-meta-check-linux-arm64: out
CGO_ENABLED=0 GOARCH=arm64 GOOS=linux go build -v -o "$@"

out/unity-meta-check-junit-linux-arm64: out
CGO_ENABLED=0 GOARCH=arm64 GOOS=linux go build -v -o "$@" ./tool/unity-meta-check-junit

out/unity-meta-check-github-pr-comment-linux-arm64: out
GOARCH=arm64 GOOS=linux go build -a -tags netgo -installsuffix netgo -v -o "$@" ./tool/unity-meta-check-github-pr-comment

out/unity-meta-check-meta-audit-linux-arm64: out
CGO_ENABLED=0 GOARCH=arm64 GOOS=linux go build -v -o "$@" ./tool/unity-meta-check-meta-audit

out/unity-meta-autofix-linux-arm64: out
CGO_ENABLED=0 GOARCH=arm64 GOOS=linux go build -v -o "$@" ./tool/unity-meta-autofix

out/gh-action-yaml-gen-linux-arm64: out
CGO_ENABLED=0 GOARCH=arm64 GOOS=linux go build -v -o "$@" ./tool/gh-action/action-yaml-gen

out/gh-action-linux-arm64: out
CGO_ENABLED=0 GOARCH=arm64 GOOS=linux go build -v -o "$@" ./tool/gh-action


# NOTE: meta-audit は Debug 用ツールなので必要になったら生成してください(生成されちゃうと Releases へあげるときに間引かないといけなくてめんどい)
windows-amd64: out/unity-meta-check-windows-amd64.exe out/unity-meta-check-junit-windows-amd64.exe out/unity-meta-check-github-pr-comment-windows-amd64.exe out/unity-meta-autofix-windows-amd64.exe out/gh-action-yaml-gen-windows-amd64.exe

Expand All @@ -88,4 +137,29 @@ out/gh-action-windows-amd64.exe: out
CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -v -o "$@" ./tool/gh-action


.PHONY: all test clean darwin-amd64 linux-amd64 windows-amd64
# NOTE: meta-audit は Debug 用ツールなので必要になったら生成してください(生成されちゃうと Releases へあげるときに間引かないといけなくてめんどい)
windows-arm64: out/unity-meta-check-windows-arm64.exe out/unity-meta-check-junit-windows-arm64.exe out/unity-meta-check-github-pr-comment-windows-arm64.exe out/unity-meta-autofix-windows-arm64.exe out/gh-action-yaml-gen-windows-arm64.exe

out/unity-meta-check-windows-arm64.exe: out
CGO_ENABLED=0 GOARCH=arm64 GOOS=windows go build -v -o "$@"

out/unity-meta-check-junit-windows-arm64.exe: out
CGO_ENABLED=0 GOARCH=arm64 GOOS=windows go build -v -o "$@" ./tool/unity-meta-check-junit

out/unity-meta-check-github-pr-comment-windows-arm64.exe: out
GOARCH=arm64 GOOS=windows go build -a -tags netgo -installsuffix netgo -v -o "$@" ./tool/unity-meta-check-github-pr-comment

out/unity-meta-check-meta-audit-windows-arm64.exe: out
CGO_ENABLED=0 GOARCH=arm64 GOOS=windows go build -v -o "$@" ./tool/unity-meta-check-meta-audit

out/unity-meta-autofix-windows-arm64.exe: out
CGO_ENABLED=0 GOARCH=arm64 GOOS=windows go build -v -o "$@" ./tool/unity-meta-autofix

out/gh-action-yaml-gen-windows-arm64.exe: out
CGO_ENABLED=0 GOARCH=arm64 GOOS=windows go build -v -o "$@" ./tool/gh-action/action-yaml-gen

out/gh-action-windows-arm64.exe: out
CGO_ENABLED=0 GOARCH=arm64 GOOS=linux go build -v -o "$@" ./tool/gh-action


.PHONY: all test clean darwin-amd64 linux-amd64 windows-amd64 darwin-arm64 linux-arm64 windows-arm64
15 changes: 15 additions & 0 deletions build.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# image-name: ghcr.io/dena/unity-meta-check/unity-meta-check-builder
FROM golang:1.22.2-bookworm as builder
ARG TARGETARCH
WORKDIR /go/src/unity-meta-check
COPY . .
RUN make -j$(nproc) out/unity-meta-check-linux-${TARGETARCH} \
out/unity-meta-check-junit-linux-${TARGETARCH} \
out/unity-meta-check-github-pr-comment-linux-${TARGETARCH} \
out/unity-meta-autofix-linux-${TARGETARCH} \
out/gh-action-linux-${TARGETARCH} && \
mv ./out/unity-meta-check-linux-${TARGETARCH} ./out/unity-meta-check && \
mv ./out/unity-meta-check-junit-linux-${TARGETARCH} ./out/unity-meta-check-junit && \
mv ./out/unity-meta-check-github-pr-comment-linux-${TARGETARCH} ./out/unity-meta-check-github-pr-comment && \
mv ./out/unity-meta-autofix-linux-${TARGETARCH} ./out/unity-meta-autofix && \
mv ./out/gh-action-linux-${TARGETARCH} ./out/gh-action
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/DeNA/unity-meta-check

go 1.18
go 1.22.2

require (
github.com/google/go-cmp v0.5.5
Expand Down
24 changes: 20 additions & 4 deletions scripts/build-image
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/bin/bash
set -euo pipefail
set -euox pipefail

BASE_DIR="$(cd "$(dirname "$0")/.."; pwd)"
BUILDER_DOCKERFILE="${BASE_DIR}/build.Dockerfile"
DOCKERFILE="${BASE_DIR}/Dockerfile"
GH_ACTION_DOCKERFILE="${BASE_DIR}/.github/images/Dockerfile"
CIRCLECI_DOCKERFILE="${BASE_DIR}/.circleci/images/Dockerfile"
Expand All @@ -25,6 +26,9 @@ main() {
local version
version="$("$BASE_DIR/scripts/print-version")"

local builder_image
builder_image="$("$BASE_DIR/scripts/print-image-name" < "$BUILDER_DOCKERFILE")"

local circleci_image
circleci_image="$("$BASE_DIR/scripts/print-image-name" < "$CIRCLECI_DOCKERFILE")"

Expand All @@ -34,17 +38,29 @@ main() {
local image
image="$("$BASE_DIR/scripts/print-image-name" < "$DOCKERFILE")"

docker build --platform linux/amd64 -t "$image:$version" -f "$DOCKERFILE" .
# NOTE: Create a docker-container driver to avoid the following error:
# > ERROR: Multi-platform build is not supported for the docker driver.
# > Switch to a different driver, or turn on the containerd image store, and try again.
# > Learn more at https://docs.docker.com/go/build-multi-platform/
if ! docker buildx inspect unity-meta-check-driver; then
docker run --privileged --rm tonistiigi/binfmt --install all
docker buildx create --name unity-meta-check-driver --driver docker-container --bootstrap
fi

# NOTE: --push is necessary, because --load is not supported for multi-platform build yet.
docker buildx build --builder unity-meta-check-driver --platform linux/arm64,linux/amd64 -t "$builder_image:latest" -f "$BUILDER_DOCKERFILE" . --push

docker buildx build --builder unity-meta-check-driver --platform linux/arm64,linux/amd64 -t "$image:$version" -f "$DOCKERFILE" .
if [[ "$arg" == "--latest" ]]; then
docker tag "$image:$version" "$image:latest"
fi

docker build --platform linux/amd64 -t "$gh_action_image:$version" -f "$GH_ACTION_DOCKERFILE" .
docker buildx build --builder unity-meta-check-driver --platform linux/arm64,linux/amd64 -t "$gh_action_image:$version" -f "$GH_ACTION_DOCKERFILE" .
if [[ "$arg" == "--latest" ]]; then
docker tag "$gh_action_image:$version" "$gh_action_image:latest"
fi

docker build --platform linux/amd64 -t "$circleci_image:$version" -f "$CIRCLECI_DOCKERFILE" .
docker buildx build --builder unity-meta-check-driver --platform linux/arm64,linux/amd64 -t "$circleci_image:$version" -f "$CIRCLECI_DOCKERFILE" .
if [[ "$arg" == "--latest" ]]; then
docker tag "$circleci_image:$version" "$circleci_image:latest"
fi
Expand Down
16 changes: 15 additions & 1 deletion scripts/deploy-gh-release
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ set -euo pipefail
BASE_DIR="$(cd "$(dirname "$0")/.."; pwd)"


has() {
local cmd="$1"
which "$cmd" >/dev/null 2>&1
}


echo-stderr() {
local message="$*"
printf "%s\n" "$message" 1>&2
Expand Down Expand Up @@ -42,6 +48,14 @@ main() {
gh --version || throw "gh must be available (see https://cli.github.com/)"
gh auth status

local nproc=1
if has sysctl; then
nproc="$(sysctl -n hw.logicalcpu)"
fi
if has nproc; then
nproc="$(nproc)"
fi

(cd "$BASE_DIR"
local title
title="$(git log -1 --format=%s HEAD)"
Expand Down Expand Up @@ -70,7 +84,7 @@ main() {
echo-stderr

echo-stderr "building executables..."
make clean all
make -j"$nproc" clean all
echo-stderr

[[ -d "./out" ]] || throw "cannot find the generated distribution dir: '${BASE_DIR}/out'"
Expand Down

0 comments on commit 40e039e

Please sign in to comment.