Skip to content

Commit

Permalink
Make faster
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuniwak committed Apr 23, 2024
1 parent bcd8be2 commit add353b
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 29 deletions.
10 changes: 1 addition & 9 deletions .circleci/images/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
# image-name: ghcr.io/dena/unity-meta-check/unity-meta-check-circleci
FROM golang:1.22-bookworm as builder
ARG TARGETARCH
WORKDIR /go/src/unity-meta-check
COPY . .
RUN make 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} && \
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
FROM ghcr.io/dena/unity-meta-check/unity-meta-check-builder:latest as builder

FROM debian:bookworm-slim
# https://circleci.com/docs/2.0/custom-images/#required-tools-for-primary-containers
Expand Down
8 changes: 2 additions & 6 deletions .github/images/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
# image-name: ghcr.io/dena/unity-meta-check/unity-meta-check-gh-action
FROM golang:1.22-bookworm as builder
ARG TARGETARCH
WORKDIR /go/src/unity-meta-check
COPY . .
RUN make out/gh-action-linux-${TARGETARCH} && mv ./out/gh-action-linux-${TARGETARCH} ./out/gh-action
FROM ghcr.io/dena/unity-meta-check/unity-meta-check-builder:latest as builder

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"]
13 changes: 1 addition & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
# image-name: ghcr.io/dena/unity-meta-check/unity-meta-check
FROM golang:1.22-bookworm as builder
ARG TARGETARCH
WORKDIR /go/src/unity-meta-check
COPY . .
RUN make 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} && \
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
FROM ghcr.io/dena/unity-meta-check/unity-meta-check-builder:latest as builder

FROM debian:bookworm-slim
RUN apt-get update \
Expand Down
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
9 changes: 8 additions & 1 deletion 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 @@ -39,6 +43,9 @@ main() {
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"
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 add353b

Please sign in to comment.