2024-05-10 17:10:42 +02:00
|
|
|
FROM node:lts as build
|
2023-04-28 19:00:34 +02:00
|
|
|
|
2024-05-10 17:10:42 +02:00
|
|
|
ENV NODE_ENV=production \
|
|
|
|
|
DAEMON=false \
|
|
|
|
|
SILENT=false \
|
|
|
|
|
USER=nodebb \
|
|
|
|
|
UID=1001 \
|
|
|
|
|
GID=1001
|
2023-04-28 19:00:34 +02:00
|
|
|
|
2024-05-10 17:10:42 +02:00
|
|
|
WORKDIR /usr/src/app/
|
2023-04-28 19:00:34 +02:00
|
|
|
|
2024-05-10 17:10:42 +02:00
|
|
|
COPY . /usr/src/app/
|
2023-04-28 19:00:34 +02:00
|
|
|
|
2024-05-10 17:10:42 +02:00
|
|
|
# Install corepack to allow usage of other package managers
|
|
|
|
|
RUN corepack enable
|
2023-04-28 19:00:34 +02:00
|
|
|
|
2024-05-10 17:10:42 +02:00
|
|
|
# Removing unnecessary files for us
|
|
|
|
|
RUN find . -mindepth 1 -maxdepth 1 -name '.*' ! -name '.' ! -name '..' -exec bash -c 'echo "Deleting {}"; rm -rf {}' \;
|
2023-04-28 19:00:34 +02:00
|
|
|
|
2024-05-10 17:10:42 +02:00
|
|
|
# Prepage package.json
|
|
|
|
|
RUN cp /usr/src/app/install/package.json /usr/src/app/
|
2023-11-12 19:38:00 +01:00
|
|
|
|
2024-05-10 17:10:42 +02:00
|
|
|
RUN apt-get update \
|
|
|
|
|
&& DEBIAN_FRONTEND=noninteractive \
|
|
|
|
|
apt-get -y --no-install-recommends install \
|
|
|
|
|
tini
|
2023-11-12 19:38:00 +01:00
|
|
|
|
2024-05-10 17:10:42 +02:00
|
|
|
RUN groupadd --gid ${GID} ${USER} \
|
|
|
|
|
&& useradd --uid ${UID} --gid ${GID} --home-dir /usr/src/app/ --shell /bin/bash ${USER} \
|
|
|
|
|
&& chown -R ${USER}:${USER} /usr/src/app/
|
2023-11-12 19:38:00 +01:00
|
|
|
|
2024-05-10 17:10:42 +02:00
|
|
|
USER ${USER}
|
2023-11-12 19:38:00 +01:00
|
|
|
|
2025-01-22 19:40:51 +01:00
|
|
|
RUN npm install --omit=dev \
|
|
|
|
|
&& rm -rf .npm
|
2024-05-10 17:10:42 +02:00
|
|
|
# TODO: generate lockfiles for each package manager
|
|
|
|
|
## pnpm import \
|
2023-11-12 19:38:00 +01:00
|
|
|
|
2024-05-10 17:10:42 +02:00
|
|
|
FROM node:lts-slim AS final
|
2017-11-03 11:18:35 -04:00
|
|
|
|
2024-05-10 17:10:42 +02:00
|
|
|
ENV NODE_ENV=production \
|
|
|
|
|
DAEMON=false \
|
|
|
|
|
SILENT=false \
|
|
|
|
|
USER=nodebb \
|
|
|
|
|
UID=1001 \
|
|
|
|
|
GID=1001
|
2017-11-03 11:18:35 -04:00
|
|
|
|
2024-05-10 17:10:42 +02:00
|
|
|
WORKDIR /usr/src/app/
|
2019-10-23 00:23:12 +08:00
|
|
|
|
2024-05-10 17:10:42 +02:00
|
|
|
RUN corepack enable \
|
|
|
|
|
&& groupadd --gid ${GID} ${USER} \
|
|
|
|
|
&& useradd --uid ${UID} --gid ${GID} --home-dir /usr/src/app/ --shell /bin/bash ${USER} \
|
|
|
|
|
&& mkdir -p /usr/src/app/logs/ /opt/config/ \
|
2024-05-23 23:52:33 +02:00
|
|
|
&& chown -R ${USER}:${USER} /usr/src/app/ /opt/config/
|
|
|
|
|
|
|
|
|
|
COPY --from=build --chown=${USER}:${USER} /usr/src/app/ /usr/src/app/install/docker/setup.json /usr/src/app/
|
|
|
|
|
COPY --from=build --chown=${USER}:${USER} /usr/bin/tini /usr/src/app/install/docker/entrypoint.sh /usr/local/bin/
|
|
|
|
|
|
|
|
|
|
RUN chmod +x /usr/local/bin/entrypoint.sh \
|
2024-05-10 17:10:42 +02:00
|
|
|
&& chmod +x /usr/local/bin/tini
|
2019-10-23 00:23:12 +08:00
|
|
|
|
2024-05-10 17:10:42 +02:00
|
|
|
# TODO: Have docker-compose use environment variables to create files like setup.json and config.json.
|
|
|
|
|
# COPY --from=hairyhenderson/gomplate:stable /gomplate /usr/local/bin/gomplate
|
2021-10-18 23:09:40 +02:00
|
|
|
|
2024-05-10 17:10:42 +02:00
|
|
|
USER ${USER}
|
2015-05-21 01:10:56 +02:00
|
|
|
|
2019-10-23 00:23:12 +08:00
|
|
|
EXPOSE 4567
|
2024-05-10 17:10:42 +02:00
|
|
|
|
|
|
|
|
VOLUME ["/usr/src/app/node_modules", "/usr/src/app/build", "/usr/src/app/public/uploads", "/opt/config/"]
|
|
|
|
|
|
|
|
|
|
# Utilising tini as our init system within the Docker container for graceful start-up and termination.
|
|
|
|
|
# Tini serves as an uncomplicated init system, adept at managing the reaping of zombie processes and forwarding signals.
|
|
|
|
|
# This approach is crucial to circumvent issues with unmanaged subprocesses and signal handling in containerised environments.
|
|
|
|
|
# By integrating tini, we enhance the reliability and stability of our Docker containers.
|
|
|
|
|
# Ensures smooth start-up and shutdown processes, and reliable, safe handling of signal processing.
|
|
|
|
|
ENTRYPOINT ["tini", "--", "entrypoint.sh"]
|