Skip to content

Commit dc2b4da

Browse files
authored
buildbox-ng: Add node et al to build web UI and Teleport Connect (#57295)
Add node and other required tools to buildbox-ng so it can be used to build the web UI and Teleport Connect. This allows buildbox-ng to replace buildbox-node - one fewer buildboxes in the end. Note that Teleport connect must be built via the top-level Makefile target `release-connect` as the Makefile sets up the environment for cross-compiling properly, which is needed by `node-gyp` for building native code for the target. `python3` is installed for `node-gyp`. `binaryen` is installed for `wasm-opt` as `wasm-pack` 0.12.1 cannot install it on ARM64, so we just install it globally. `fpm` (via `ruby` `gem`) is installed as `electron-builder` tries to install a amd64 version on an arm64 host, which fails for obvious reasons. We set the `USE_SYSTEM_FPM` env var so `electron-builder` uses this version. Set `HOME` as node and associated tooling wants to create stuff in there for caching. We point it to `/tmp/build` as that is already set up as the base cache directory for the buildbox for when you want to be able to persist caches across invocations.
1 parent 1a0b371 commit dc2b4da

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

build.assets/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ buildbox-ng:
159159
--build-arg THIRDPARTY_IMAGE=$(BUILDBOX_THIRDPARTY) \
160160
--build-arg GOLANG_VERSION=$(GOLANG_VERSION) \
161161
--build-arg RUST_VERSION=$(RUST_VERSION) \
162+
--build-arg NODE_VERSION=$(NODE_VERSION) \
162163
--cache-from $(BUILDBOX_NG) \
163164
--cache-to type=inline \
164165
$(if $(PUSH),--push,--load) \

build.assets/buildbox/Dockerfile

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,30 @@ RUN curl --proto =https --tlsv1.2 -fsSL https://sh.rustup.rs | \
100100
arm-unknown-linux-gnueabihf \
101101
wasm32-unknown-unknown
102102

103+
# ----------------------------------------------------------------------------
104+
# Install node
105+
106+
FROM base AS node
107+
108+
RUN apt-get update \
109+
&& apt-get install -y xz-utils \
110+
&& rm -rf /var/lib/apt/lists/*
111+
112+
RUN install -d -m 0775 -o buildbox -g buildbox /opt/node
113+
USER buildbox
114+
115+
ARG NODE_VERSION
116+
RUN \
117+
case "$(uname -m)" in \
118+
aarch64|arm64) NARCH=arm64 ;; \
119+
x86_64|amd64) NARCH=x64 ;; \
120+
*) echo "Unsupported architecture for node: $(uname -m)" >&2; exit 1 ;; \
121+
esac; \
122+
curl -fsSL "https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-${NARCH}.tar.xz" | \
123+
tar -C /opt/node -xJ --strip-components=1 && \
124+
/opt/node/bin/node --version
125+
RUN PATH=/opt/node/bin corepack enable yarn pnpm
126+
103127
# ----------------------------------------------------------------------------
104128
# Clang 12.0.0 for FIPS builds of boring-rs
105129

@@ -138,6 +162,7 @@ RUN apt-get update && apt-get install -y \
138162
automake \
139163
autopoint \
140164
bison \
165+
binaryen \
141166
cmake \
142167
flex \
143168
gettext \
@@ -147,6 +172,11 @@ RUN apt-get update && apt-get install -y \
147172
make \
148173
ninja-build \
149174
pkg-config \
175+
python3-pip \
176+
python3-setuptools \
177+
python3-wheel \
178+
ruby \
179+
rpm \
150180
sed \
151181
w3m \
152182
wget \
@@ -156,6 +186,14 @@ RUN apt-get update && apt-get install -y \
156186

157187
RUN install -d -m 1777 -o teleport -g teleport /tmp/build
158188

189+
# Install the FPM ruby gem as electron-builder only uses x86{,_64} versions
190+
# which do not work on arm64. We set USE_SYSTEM_FPM to ensure it uses this
191+
# version.
192+
# TODO(camscale): Change build.assets/build-package.sh to use this FPM instead
193+
# of the docker image we produce.
194+
RUN gem install fpm
195+
ENV USE_SYSTEM_FPM=true
196+
159197
# The boring-rs build wants llvm-{ar,ranlib}-12 in /usr/bin. The
160198
# clang install has /opt/clang/bin/llvm-{ar,ranlib}. Create /usr/bin
161199
# symlinks while we're still root
@@ -170,6 +208,7 @@ ARG THIRDPARTY_DIR=/opt/thirdparty
170208
COPY --from=thirdparty ${THIRDPARTY_DIR} ${THIRDPARTY_DIR}
171209
COPY --from=rust /opt/rust /opt/rust
172210
COPY --from=go /opt/go /opt/go
211+
COPY --from=node /opt/node /opt/node
173212
COPY --from=clang /opt/clang /opt/clang
174213

175214
# The boring-rs build uses cmake which wants clang++ to be called clang++-12.
@@ -187,9 +226,9 @@ RUN \
187226
# Set RUSTUP_HOME so cargo does not warn/error about not finding it at ~/.cargo
188227
ENV RUSTUP_HOME=/opt/rust
189228

190-
ENV PATH=/opt/go/bin:/opt/rust/bin:${THIRDPARTY_DIR}/host/bin:${PATH}
229+
ENV PATH=/opt/go/bin:/opt/rust/bin:/opt/node/bin:${THIRDPARTY_DIR}/host/bin:${PATH}
191230

192-
# Ensure THIRDPARTY_DIR gets propagated to the makefiles if the provided arg
231+
# Ensure THIRDPARTY_DIR gets propagated to the makefiles in case the provided arg
193232
# is not the default value.
194233
ENV THIRDPARTY_DIR=${THIRDPARTY_DIR}
195234

@@ -211,6 +250,8 @@ ENV CARGO_TARGET_ARM_UNKNOWN_LINUX_GNUEABIHF_LINKER=arm-unknown-linux-gnueabihf-
211250
ENV CARGO_HOME=/tmp/build/rust
212251
ENV GOPATH=/tmp/build/go
213252
ENV GOCACHE=/tmp/build/go/build
253+
ENV COREPACK_HOME=/tmp/build/node
254+
ENV HOME=/tmp/build
214255

215256
# Add the writable cargo and go bin directories to the path so we will find
216257
# binaries build with `cargo install` and `go install` during a build.

0 commit comments

Comments
 (0)