web-check/Dockerfile
Alexandre Galtier 36bccfa748
Docker improvement and fix screenshots
. Dockerfile optimization (reorder)
. Docker: Add xvfb package
. Docker: Add entrypoint.sh
. Launch dbus at container start (entrypoint.sh)
. Lauch Xvfb at container start (entrypoint.sh)
. Above fix screenshot error on docker
. Add environment variables:
. . SCREEN_RESOLUTION: for Xvfb resolution
. . BROWSER_WIDTH: for screenshot
. . BROWSER_HEIGHT: for screenshot
. . BROWSER_TIMEOUT: for screenshot
2024-09-16 22:01:44 +02:00

74 lines
2.7 KiB
Docker
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

###########################
#### APP Build #####
###########################
# Specify the Node.js version to use
ARG NODE_VERSION=21
# Specify the Debian version to use, the default is "bullseye"
ARG DEBIAN_VERSION=bullseye
# Use Node.js Docker image as the base image, with specific Node and Debian versions
FROM node:${NODE_VERSION}-${DEBIAN_VERSION} AS build
# 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 Chromes signing key
RUN apt-get update --quiet --yes --fix-missing && \
DEBIAN_FRONTEND=noninteractive apt-get --quiet --yes 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 --quiet --yes && \
DEBIAN_FRONTEND=noninteractive apt-get --quiet --yes --no-install-recommends install chromium traceroute python make g++
# 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
WORKDIR /app
# Copy package.json and yarn.lock to the working directory
COPY package.json yarn.lock ./
# Run yarn install to install dependencies and clear yarn cache
RUN yarn install --frozen-lockfile --network-timeout 100000
# Cleanup
RUN rm -rf /var/lib/apt/lists/* && \
rm -rf /app/node_modules/.cache
# Copy all files to working directory
COPY . .
# Run yarn build to build the application
RUN yarn build --production
###########################
#### Final STAGE #####
###########################
FROM node:${NODE_VERSION}-${DEBIAN_VERSION} AS final
RUN apt-get update --yes && \
DEBIAN_FRONTEND=noninteractive apt-get install --yes --no-install-recommends chromium traceroute xvfb && \
chmod 755 /usr/bin/chromium && \
rm -rf /var/lib/apt/lists/* /app/node_modules/.cache
WORKDIR /app
COPY package.json yarn.lock ./
COPY --from=build /app .
# Exposed container port, the default is 3000, which can be modified through the environment variable PORT
EXPOSE ${PORT:-3000}
# Set the environment variable CHROME_PATH to specify the path to the Chromium binaries
ENV CHROME_PATH='/usr/bin/chromium'
# Entrypoint to lauchn
COPY --chmod=755 entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
# Define the command executed when the container starts and start the server.js of the Node.js application
CMD ["yarn", "start"]