2023-09-14 21:59:09 +02:00
|
|
|
|
# Specify the Node.js version to use
|
|
|
|
|
ARG NODE_VERSION=16
|
2023-09-01 12:42:53 +02:00
|
|
|
|
|
2023-09-14 21:59:09 +02:00
|
|
|
|
# Specify the Debian version to use, the default is "bullseye"
|
|
|
|
|
ARG DEBIAN_VERSION=bullseye
|
2023-09-01 12:42:53 +02:00
|
|
|
|
|
2023-09-14 21:59:09 +02:00
|
|
|
|
# Use Node.js Docker image as the base image, with specific Node and Debian versions
|
2024-02-29 17:35:56 +01:00
|
|
|
|
FROM node:${NODE_VERSION}-${DEBIAN_VERSION} AS build
|
2023-09-14 21:59:09 +02:00
|
|
|
|
|
|
|
|
|
# Set the container's default shell to Bash and enable some options
|
|
|
|
|
SHELL ["/bin/bash", "-euo", "pipefail", "-c"]
|
|
|
|
|
|
|
|
|
|
# Install Chromium browser and Download and verify Google Chrome’s signing key
|
|
|
|
|
RUN apt-get update -qq --fix-missing && \
|
|
|
|
|
apt-get -qqy install --allow-unauthenticated gnupg wget && \
|
|
|
|
|
wget --quiet --output-document=- https://dl-ssl.google.com/linux/linux_signing_key.pub | gpg --dearmor > /etc/apt/trusted.gpg.d/google-archive.gpg && \
|
|
|
|
|
echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list && \
|
|
|
|
|
apt-get update -qq && \
|
2024-02-29 17:10:07 +01:00
|
|
|
|
apt-get -qqy --no-install-recommends install chromium traceroute python make g++ && \
|
2023-09-14 21:59:09 +02:00
|
|
|
|
rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
# Run the Chromium browser's version command and redirect its output to the /etc/chromium-version file
|
|
|
|
|
RUN /usr/bin/chromium --no-sandbox --version > /etc/chromium-version
|
|
|
|
|
|
|
|
|
|
# Set the working directory to /app
|
2023-09-01 12:42:53 +02:00
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
2023-09-14 21:59:09 +02:00
|
|
|
|
# Copy package.json and yarn.lock to the working directory
|
2023-09-01 12:42:53 +02:00
|
|
|
|
COPY package.json yarn.lock ./
|
|
|
|
|
|
2023-09-14 21:59:09 +02:00
|
|
|
|
# Run yarn install to install dependencies and clear yarn cache
|
2024-02-19 17:16:29 +01:00
|
|
|
|
RUN apt-get update && \
|
2024-02-29 17:10:07 +01:00
|
|
|
|
yarn install --production --frozen-lockfile --network-timeout 100000 && \
|
2023-09-01 12:42:53 +02:00
|
|
|
|
rm -rf /app/node_modules/.cache
|
|
|
|
|
|
2023-09-14 21:59:09 +02:00
|
|
|
|
# Copy all files to working directory
|
2023-09-01 12:42:53 +02:00
|
|
|
|
COPY . .
|
|
|
|
|
|
2023-09-14 21:59:09 +02:00
|
|
|
|
# Run yarn build to build the application
|
2024-02-19 17:16:29 +01:00
|
|
|
|
RUN yarn build --production
|
|
|
|
|
|
|
|
|
|
# Final stage
|
2024-02-29 17:35:56 +01:00
|
|
|
|
FROM node:${NODE_VERSION}-${DEBIAN_VERSION} AS final
|
2024-02-19 17:16:29 +01:00
|
|
|
|
|
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
|
|
|
COPY package.json yarn.lock ./
|
|
|
|
|
COPY --from=build /app .
|
|
|
|
|
|
|
|
|
|
RUN apt-get update && \
|
|
|
|
|
apt-get install -y --no-install-recommends chromium traceroute && \
|
|
|
|
|
chmod 755 /usr/bin/chromium && \
|
|
|
|
|
rm -rf /var/lib/apt/lists/* /app/node_modules/.cache
|
2023-09-01 12:42:53 +02:00
|
|
|
|
|
2023-09-14 21:59:09 +02:00
|
|
|
|
# Exposed container port, the default is 3000, which can be modified through the environment variable PORT
|
2023-08-10 22:24:52 +02:00
|
|
|
|
EXPOSE ${PORT:-3000}
|
2023-09-01 12:42:53 +02:00
|
|
|
|
|
2023-09-14 21:59:09 +02:00
|
|
|
|
# Set the environment variable CHROME_PATH to specify the path to the Chromium binaries
|
2023-07-25 06:15:55 +02:00
|
|
|
|
ENV CHROME_PATH='/usr/bin/chromium'
|
2023-09-01 12:42:53 +02:00
|
|
|
|
|
2023-09-14 21:59:09 +02:00
|
|
|
|
# Define the command executed when the container starts and start the server.js of the Node.js application
|
2024-02-29 17:35:56 +01:00
|
|
|
|
CMD ["yarn", "serve"]
|