2021-10-19 04:06:08 +00:00
|
|
|
ARG ARCH=%%BALENA_ARCH%%
|
2022-11-11 16:28:45 +00:00
|
|
|
ARG FATRW_VERSION=0.2.9
|
2021-10-19 04:06:08 +00:00
|
|
|
|
2023-03-10 00:16:49 +00:00
|
|
|
|
|
|
|
FROM arm32v6/alpine:3.16 as alpine-rpi
|
|
|
|
FROM arm32v7/alpine:3.16 as alpine-armv7hf
|
|
|
|
FROM arm64v8/alpine:3.16 as alpine-aarch64
|
|
|
|
FROM amd64/alpine:3.16 as alpine-amd64
|
|
|
|
FROM i386/alpine:3.16 as alpine-i386
|
|
|
|
|
|
|
|
FROM arm32v6/alpine:3.11 as procmail-rpi
|
|
|
|
FROM arm32v7/alpine:3.11 as procmail-armv7hf
|
|
|
|
FROM arm64v8/alpine:3.11 as procmail-aarch64
|
|
|
|
FROM amd64/alpine:3.11 as procmail-amd64
|
|
|
|
FROM i386/alpine:3.11 as procmail-i386
|
|
|
|
|
2022-07-06 19:51:49 +00:00
|
|
|
###################################################
|
|
|
|
# Build the supervisor dependencies
|
|
|
|
###################################################
|
2022-09-16 15:59:38 +00:00
|
|
|
FROM balenalib/${ARCH}-alpine-node:16-run as build-base
|
2022-07-06 19:51:49 +00:00
|
|
|
|
2022-11-11 16:28:45 +00:00
|
|
|
ARG ARCH
|
|
|
|
ARG FATRW_VERSION
|
|
|
|
ARG FATRW_ARCHIVE="fatrw-${ARCH}.tar.gz"
|
|
|
|
ARG FATRW_LOCATION="https://github.com/balena-os/fatrw/releases/download/v${FATRW_VERSION}/${FATRW_ARCHIVE}"
|
2021-10-19 04:06:08 +00:00
|
|
|
|
|
|
|
WORKDIR /usr/src/app
|
|
|
|
|
|
|
|
RUN apk add --no-cache \
|
|
|
|
g++ \
|
|
|
|
make \
|
2022-07-06 19:51:49 +00:00
|
|
|
python3 \
|
2021-10-19 04:06:08 +00:00
|
|
|
libgcc \
|
|
|
|
libuv \
|
|
|
|
sqlite-dev \
|
2022-07-06 19:51:49 +00:00
|
|
|
dbus-dev
|
|
|
|
|
|
|
|
COPY package*.json ./
|
|
|
|
|
|
|
|
RUN strip /usr/local/bin/node
|
|
|
|
|
2022-11-11 16:28:45 +00:00
|
|
|
# Install fatrw
|
|
|
|
RUN curl -SLO "${FATRW_LOCATION}" && \
|
|
|
|
ls -la "${FATRW_ARCHIVE}" && \
|
|
|
|
tar -xzf "${FATRW_ARCHIVE}" -C /usr/local/bin && \
|
|
|
|
rm -f "${FATRW_ARCHIVE}"
|
|
|
|
|
2022-07-06 19:51:49 +00:00
|
|
|
# Just install dev dependencies first
|
|
|
|
RUN npm ci --build-from-source --sqlite=/usr/lib
|
|
|
|
|
2022-12-05 19:24:11 +00:00
|
|
|
###################################################################
|
|
|
|
# Journal access.
|
|
|
|
# The supervisor is built on an alpine image but still needs
|
|
|
|
# to use journalctl (from systemd) which cannot be built for
|
|
|
|
# musl. We hack around this by copying the binary and its library
|
|
|
|
# dependencies to the final image
|
|
|
|
###################################################################
|
|
|
|
FROM balenalib/${ARCH}-debian:bullseye-run as journal
|
|
|
|
|
|
|
|
RUN apt-get update && apt-get install -y --no-install-recommends systemd
|
|
|
|
|
|
|
|
COPY ./build-utils/setup-journal.sh /
|
|
|
|
RUN /setup-journal.sh
|
|
|
|
|
|
|
|
|
2022-07-06 19:51:49 +00:00
|
|
|
###################################################
|
|
|
|
# Extra dependencies. This uses alpine 3.11 as the
|
|
|
|
# procmail package was removed on 3.12
|
|
|
|
###################################################
|
2023-03-10 00:16:49 +00:00
|
|
|
FROM procmail-${ARCH} as extra
|
2022-07-06 19:51:49 +00:00
|
|
|
|
|
|
|
RUN apk add --update --no-cache procmail
|
|
|
|
|
|
|
|
###################################################
|
|
|
|
# Image with the final production dependencies.
|
|
|
|
# This image will also be be used for testing
|
|
|
|
###################################################
|
2023-03-10 00:16:49 +00:00
|
|
|
FROM alpine-${ARCH} as runtime-base
|
2022-07-06 19:51:49 +00:00
|
|
|
|
|
|
|
WORKDIR /usr/src/app
|
|
|
|
|
|
|
|
# We just need the node binary in the final image
|
|
|
|
COPY --from=build-base /usr/local/bin/node /usr/local/bin/node
|
|
|
|
|
2022-11-11 16:28:45 +00:00
|
|
|
# Also copy the fatrw binary
|
|
|
|
COPY --from=build-base /usr/local/bin/fatrw /usr/local/bin/fatrw
|
|
|
|
|
2022-07-06 19:51:49 +00:00
|
|
|
# Similarly, from the procmail package we just need the lockfile binary
|
|
|
|
COPY --from=extra /usr/bin/lockfile /usr/bin/lockfile
|
|
|
|
|
2022-12-05 19:24:11 +00:00
|
|
|
# Copy journalctl and library dependecies to the final image
|
|
|
|
COPY --from=journal /sysroot /
|
|
|
|
|
2022-07-06 19:51:49 +00:00
|
|
|
# Runtime dependencies
|
|
|
|
RUN apk add --no-cache \
|
|
|
|
ca-certificates \
|
|
|
|
iptables \
|
|
|
|
ip6tables \
|
|
|
|
rsync \
|
|
|
|
dbus \
|
|
|
|
libstdc++ \
|
2022-01-06 20:32:50 +00:00
|
|
|
dmidecode \
|
2022-07-06 19:51:49 +00:00
|
|
|
sqlite-libs
|
2021-10-19 04:06:08 +00:00
|
|
|
|
2022-07-06 19:51:49 +00:00
|
|
|
ARG ARCH
|
|
|
|
ARG VERSION=master
|
|
|
|
ENV CONFIG_MOUNT_POINT=/boot/config.json \
|
|
|
|
LED_FILE=/dev/null \
|
|
|
|
SUPERVISOR_IMAGE=balena/$ARCH-supervisor \
|
2022-09-20 14:16:58 +00:00
|
|
|
VERSION=$VERSION
|
2021-10-19 04:06:08 +00:00
|
|
|
|
2022-08-19 20:07:33 +00:00
|
|
|
###############################################################
|
|
|
|
# Use the base image to run integration tests and for livepush
|
|
|
|
###############################################################
|
2022-07-06 19:51:49 +00:00
|
|
|
FROM runtime-base as test
|
2021-10-19 04:06:08 +00:00
|
|
|
|
2022-07-06 19:51:49 +00:00
|
|
|
WORKDIR /usr/src/app
|
2021-10-19 04:06:08 +00:00
|
|
|
|
2022-07-06 19:51:49 +00:00
|
|
|
# Copy node install from the build folder
|
|
|
|
COPY --from=build-base /usr/local/bin /usr/local/bin
|
|
|
|
COPY --from=build-base /usr/local/lib/node_modules /usr/local/lib/node_modules
|
2021-10-19 04:06:08 +00:00
|
|
|
|
2022-07-06 19:51:49 +00:00
|
|
|
# Copy build dependencies
|
|
|
|
COPY --from=build-base /usr/src/app/package.json ./
|
|
|
|
COPY --from=build-base /usr/src/app/node_modules ./node_modules
|
|
|
|
|
|
|
|
# Run livepush here
|
2021-10-19 04:06:08 +00:00
|
|
|
#dev-copy=entry.sh .
|
|
|
|
#dev-cmd-live=LIVEPUSH=1 ./entry.sh
|
|
|
|
|
2022-07-06 19:51:49 +00:00
|
|
|
# Copy build files
|
2021-10-19 04:06:08 +00:00
|
|
|
COPY build-utils ./build-utils
|
2022-08-19 20:07:33 +00:00
|
|
|
COPY webpack.config.js tsconfig.json tsconfig.release.json tsconfig.js.json .mochapodrc.yml ./
|
|
|
|
COPY typings ./typings
|
2021-10-19 04:06:08 +00:00
|
|
|
COPY src ./src
|
|
|
|
COPY test ./test
|
2022-08-19 20:07:33 +00:00
|
|
|
|
2022-11-11 16:28:45 +00:00
|
|
|
# Run type checking and unit tests here
|
2022-09-12 11:35:19 +00:00
|
|
|
# to prevent setting up a test environment that will
|
2022-08-22 23:54:21 +00:00
|
|
|
# most likely fail.
|
2022-09-12 22:10:17 +00:00
|
|
|
RUN npm run test
|
2022-08-22 23:54:21 +00:00
|
|
|
|
2022-09-12 11:35:19 +00:00
|
|
|
# When running tests from a container built from this stage,
|
2022-08-19 20:07:33 +00:00
|
|
|
# skip the mocha-pod setup
|
|
|
|
ENV MOCHAPOD_SKIP_SETUP=1
|
|
|
|
|
2022-09-12 11:35:19 +00:00
|
|
|
# This command will be used by default when running integration tests
|
2022-08-19 20:07:33 +00:00
|
|
|
# from this stage
|
|
|
|
CMD npm run test:integration
|
2021-10-19 04:06:08 +00:00
|
|
|
|
2022-07-06 19:51:49 +00:00
|
|
|
###################################################
|
|
|
|
# Build the production package
|
|
|
|
###################################################
|
|
|
|
FROM build-base as build-prod
|
|
|
|
|
|
|
|
WORKDIR /usr/src/app
|
|
|
|
|
|
|
|
# Copy build files
|
|
|
|
COPY build-utils ./build-utils
|
|
|
|
COPY webpack.config.js tsconfig.json tsconfig.release.json ./
|
|
|
|
COPY src ./src
|
|
|
|
COPY typings ./typings
|
|
|
|
|
|
|
|
# Compile the sources using the dev
|
|
|
|
# dependencies
|
|
|
|
RUN npm run build
|
2021-10-19 04:06:08 +00:00
|
|
|
|
|
|
|
# Run the production install here, to avoid the npm dependency on
|
|
|
|
# the later stage
|
2022-09-12 20:33:45 +00:00
|
|
|
RUN npm ci \
|
|
|
|
--production \
|
|
|
|
--no-optional \
|
|
|
|
--unsafe-perm \
|
|
|
|
--build-from-source \
|
|
|
|
--sqlite=/usr/lib \
|
2021-10-19 04:06:08 +00:00
|
|
|
&& npm cache clean --force \
|
|
|
|
# For some reason this doesn't get cleared with the other
|
|
|
|
# cache
|
|
|
|
&& rm -rf node_modules/.cache \
|
|
|
|
# Remove various uneeded filetypes in order to reduce space
|
|
|
|
# We also remove the spurious node.dtps, see https://github.com/mapbox/node-sqlite3/issues/861
|
|
|
|
&& find . -path '*/coverage/*' -o -path '*/test/*' -o -path '*/.nyc_output/*' \
|
|
|
|
-o -name '*.tar.*' -o -name '*.in' -o -name '*.cc' \
|
|
|
|
-o -name '*.c' -o -name "*.ts" -o -name '*.eslintrc' \
|
|
|
|
-o -name '*.h' -o -name '*.html' -o -name '*.markdown' \
|
|
|
|
-o -name '*.md' -o -name '*.patch' -o -name '*.png' \
|
|
|
|
-o -name '*.yml' \
|
|
|
|
-delete \
|
|
|
|
&& find . -type f -path '*/node_modules/sqlite3/deps*' -delete \
|
|
|
|
&& find . -type f -path '*/node_modules/knex/build*' -delete \
|
|
|
|
&& rm -rf node_modules/sqlite3/node.dtps
|
|
|
|
|
2022-07-06 19:51:49 +00:00
|
|
|
###################################################
|
|
|
|
# Build the production image
|
|
|
|
###################################################
|
|
|
|
FROM runtime-base
|
2021-10-19 04:06:08 +00:00
|
|
|
|
|
|
|
WORKDIR /usr/src/app
|
|
|
|
|
2022-07-06 19:51:49 +00:00
|
|
|
COPY --from=build-prod /usr/src/app/dist ./dist
|
|
|
|
COPY --from=build-prod /usr/src/app/package.json ./
|
|
|
|
COPY --from=build-prod /usr/src/app/node_modules ./node_modules
|
2021-10-19 04:06:08 +00:00
|
|
|
|
|
|
|
COPY entry.sh .
|
|
|
|
|
|
|
|
VOLUME /data
|
|
|
|
HEALTHCHECK --interval=5m --start-period=1m --timeout=30s --retries=3 \
|
|
|
|
CMD wget http://127.0.0.1:${LISTEN_PORT:-48484}/v1/healthy -O - -q
|
|
|
|
|
|
|
|
CMD ["/usr/src/app/entry.sh"]
|