Skip to content

Commit

Permalink
Add ARCH env variable and simplify third_party Makefiles
Browse files Browse the repository at this point in the history
  • Loading branch information
cleardevice committed Sep 13, 2023
1 parent fd4aa51 commit 938d921
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 31 deletions.
5 changes: 4 additions & 1 deletion src/shadowbox/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ COPY scripts scripts/
COPY src src/
COPY tsconfig.json ./
COPY third_party third_party
RUN ROOT_DIR=/ npm run action shadowbox/server/build

ARG ARCH

RUN ARCH=${ARCH} ROOT_DIR=/ npm run action shadowbox/server/build

# shadowbox image
FROM ${NODE_IMAGE}
Expand Down
8 changes: 6 additions & 2 deletions src/shadowbox/docker/build.action.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ export DOCKER_CONTENT_TRUST="${DOCKER_CONTENT_TRUST:-1}"
# Enable Docker BuildKit (https://docs.docker.com/develop/develop-images/build_enhancements)
export DOCKER_BUILDKIT=1

# Docker image build architecture. Supported architectures: x86_64, arm64
export ARCH=${ARCH:-x86_64}

# Newer node images have no valid content trust data.
# Pin the image node:16.18.0-alpine3.16 by hash.
# See image at https://hub.docker.com/_/node/tags?page=1&name=16.18.0-alpine3.16
readonly NODE_IMAGE=$(
if [[ "$(uname -m)" == "x86_64" ]]; then
if [[ "${ARCH}" == "x86_64" ]]; then
echo "node@sha256:264861cd2f785a2b727e9f908065e8d9e9358fcc1308da3cb207d9cba69afee2"
elif [[ "$(uname -m)" == "aarch64" ]]; then
elif [[ "${ARCH}" == "arm64" ]]; then
echo "node@sha256:e2aff82eea79469af43ddd121f1c8f8c91a501e838534bd3991e225401b2c38d"
else
echo "Unsupported architecture"
Expand All @@ -37,6 +40,7 @@ readonly NODE_IMAGE=$(
# https://github.com/moby/buildkit/issues/606 and https://github.com/moby/buildkit/issues/1397
docker pull "${NODE_IMAGE}"
docker build --force-rm \
--build-arg ARCH="${ARCH}" \
--build-arg NODE_IMAGE="${NODE_IMAGE}" \
--build-arg GITHUB_RELEASE="${TRAVIS_TAG:-none}" \
-f src/shadowbox/docker/Dockerfile \
Expand Down
8 changes: 4 additions & 4 deletions src/shadowbox/server/build.action.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ readonly BIN_DIR="${OUT_DIR}/bin"
mkdir -p "${BIN_DIR}"
{
cd "${ROOT_DIR}/third_party/prometheus"
make "bin/${OS}/prometheus"
cp "bin/${OS}/prometheus" "${BIN_DIR}/"
make "bin/${OS}-${ARCH}/prometheus"
cp "bin/${OS}-${ARCH}/prometheus" "${BIN_DIR}/"
}
{
cd "${ROOT_DIR}/third_party/outline-ss-server"
make "bin/${OS}/outline-ss-server"
cp "bin/${OS}/outline-ss-server" "${BIN_DIR}/"
make "bin/${OS}-${ARCH}/outline-ss-server"
cp "bin/${OS}-${ARCH}/outline-ss-server" "${BIN_DIR}/"
}

# Copy shadowbox package.json
Expand Down
24 changes: 12 additions & 12 deletions third_party/outline-ss-server/Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
VERSION=1.4.0
SHA256_linux_x86_64=f51bcb6391cca0ae828620c429e698a3b7c409de2374c52f113ca9a525e021a8
SHA256_linux_aarch64=14ae581414c9aab04253a385ef1854c003d09f545f6f8a3a55aa987f0c6d3859
APP_ARCH_linux_x86_64=x86_64
APP_ARCH_linux_aarch64=arm64

.PHONY: all
all: bin/linux/outline-ss-server bin/macos/outline-ss-server
all: bin/linux-x84_64/outline-ss-server bin/linux-arm64/outline-ss-server bin/macos-x84_64/outline-ss-server bin/macos-arm64/outline-ss-server

bin/linux/outline-ss-server: OS=linux
bin/linux/outline-ss-server: SHA256=$(shell echo $(SHA256_linux_$(shell uname -m)))
bin/linux/outline-ss-server: APP_ARCH=$(shell echo $(APP_ARCH_linux_$(shell uname -m)))
bin/linux-x86_64/outline-ss-server: OS=linux
bin/linux-x86_64/outline-ss-server: SHA256=f51bcb6391cca0ae828620c429e698a3b7c409de2374c52f113ca9a525e021a8

bin/macos/outline-ss-server: OS=macos
bin/macos/outline-ss-server: SHA256=c85b2e8ae2d48482cbc101e54dcb7eed074a22c14a3a7301993e5f786b34081d
bin/macos/outline-ss-server: APP_ARCH=$(APP_ARCH_linux_x86_64)
bin/linux-arm64/outline-ss-server: OS=linux
bin/linux-arm64/outline-ss-server: SHA256=14ae581414c9aab04253a385ef1854c003d09f545f6f8a3a55aa987f0c6d3859

bin/macos-x86_64/outline-ss-server: OS=macos
bin/macos-x86_64/outline-ss-server: SHA256=c85b2e8ae2d48482cbc101e54dcb7eed074a22c14a3a7301993e5f786b34081d

bin/macos-arm64/outline-ss-server: OS=macos
bin/macos-arm64/outline-ss-server: SHA256=9647712a7c732184f98b1e2e7f74281855afed2245ec922c4a24b54f0eb0ce72

TEMPFILE := $(shell mktemp)
bin/%/outline-ss-server:
node ../../src/build/download_file.mjs --url="https://github.com/Jigsaw-Code/outline-ss-server/releases/download/v$(VERSION)/outline-ss-server_$(VERSION)_$(OS)_$(APP_ARCH).tar.gz" --out="$(TEMPFILE)" --sha256=$(SHA256)
node ../../src/build/download_file.mjs --url="https://github.com/Jigsaw-Code/outline-ss-server/releases/download/v$(VERSION)/outline-ss-server_$(VERSION)_$(OS)_$(ARCH).tar.gz" --out="$(TEMPFILE)" --sha256=$(SHA256)
mkdir -p "$(dir $@)"
tar -zx -f "$(TEMPFILE)" -C "$(dir $@)" "$(notdir $@)"
chmod +x "$@"
Expand Down
29 changes: 17 additions & 12 deletions third_party/prometheus/Makefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
VERSION=2.37.1
SHA256_linux_x86_64=753f66437597cf52ada98c2f459aa8c03745475c249c9f2b40ac7b3919131ba6
SHA256_linux_aarch64=b59a66fb5c7ec5acf6bf426793528a5789a1478a0dad8c64edc2843caf31b1b8
APP_ARCH_linux_x86_64=amd64
APP_ARCH_linux_aarch64=arm64

ifeq ($(ARCH),x84_64)
APP_ARCH=amd64
else
APP_ARCH=arm64
endif

.PHONY: all
all: bin/linux/prometheus bin/macos/prometheus
all: bin/linux-x86_64/prometheus bin/linux-arm64/prometheus bin/macos-x86_64/prometheus bin/macos-arm64/prometheus

bin/linux-x86_64/prometheus: OS=linux
bin/linux-x86_64/prometheus: SHA256=753f66437597cf52ada98c2f459aa8c03745475c249c9f2b40ac7b3919131ba6

bin/linux-arm64/prometheus: OS=linux
bin/linux-arm64/prometheus: SHA256=b59a66fb5c7ec5acf6bf426793528a5789a1478a0dad8c64edc2843caf31b1b8

bin/linux/prometheus: OS=linux
bin/linux/prometheus: ARCH=$(shell uname -m)
bin/linux/prometheus: SHA256=$(shell echo $(SHA256_linux_$(ARCH)))
bin/linux/prometheus: APP_ARCH=$(shell echo $(APP_ARCH_linux_$(ARCH)))
bin/macos-x86_64/prometheus: OS=darwin
bin/macos-x86_64/prometheus: SHA256=e03a43d98955ac3500f57353ea74b5df829074205f195ea6b3b88f55c4575c79

bin/macos/prometheus: OS=darwin
bin/macos/prometheus: SHA256=e03a43d98955ac3500f57353ea74b5df829074205f195ea6b3b88f55c4575c79
bin/macos/prometheus: APP_ARCH=$(APP_ARCH_linux_x86_64)
bin/macos-arm64/prometheus: OS=darwin
bin/macos-arm64/prometheus: SHA256=eb8a174c82a0fb6c84e81d9a73214318fb4a605115ad61505d7883d02e5a6f52

bin/%/prometheus: TEMPFILE := $(shell mktemp)
bin/%/prometheus:
Expand Down

0 comments on commit 938d921

Please sign in to comment.