1
0

Dockerfile 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. # syntax=docker/dockerfile:1.7
  2. # Please see https://docs.docker.com/engine/reference/builder for information about
  3. # the extended buildx capabilities used in this file.
  4. # Make sure multiarch TARGETPLATFORM is available for interpolation
  5. # See: https://docs.docker.com/build/building/multi-platform/
  6. ARG TARGETPLATFORM=${TARGETPLATFORM}
  7. ARG BUILDPLATFORM=${BUILDPLATFORM}
  8. # Node version to use in base image, change with [--build-arg NODE_MAJOR_VERSION="20"]
  9. ARG NODE_MAJOR_VERSION="20"
  10. # Debian image to use for base image, change with [--build-arg DEBIAN_VERSION="bookworm"]
  11. ARG DEBIAN_VERSION="bookworm"
  12. # Node image to use for base image based on combined variables (ex: 20-bookworm-slim)
  13. FROM docker.io/node:${NODE_MAJOR_VERSION}-${DEBIAN_VERSION}-slim as streaming
  14. # Timezone used by the Docker container and runtime, change with [--build-arg TZ=Europe/Berlin]
  15. ARG TZ="Etc/UTC"
  16. # Linux UID (user id) for the mastodon user, change with [--build-arg UID=1234]
  17. ARG UID="991"
  18. # Linux GID (group id) for the mastodon user, change with [--build-arg GID=1234]
  19. ARG GID="991"
  20. # Apply Mastodon build options based on options above
  21. ENV \
  22. # Apply Mastodon version information
  23. MASTODON_VERSION_PRERELEASE="${MASTODON_VERSION_PRERELEASE}" \
  24. MASTODON_VERSION_METADATA="${MASTODON_VERSION_METADATA}" \
  25. # Apply timezone
  26. TZ=${TZ}
  27. ENV \
  28. # Configure the IP to bind Mastodon to when serving traffic
  29. BIND="0.0.0.0" \
  30. # Explicitly set PORT to match the exposed port
  31. PORT=4000 \
  32. # Use production settings for Yarn, Node and related nodejs based tools
  33. NODE_ENV="production" \
  34. # Add Ruby and Mastodon installation to the PATH
  35. DEBIAN_FRONTEND="noninteractive"
  36. # Set default shell used for running commands
  37. SHELL ["/bin/bash", "-o", "pipefail", "-o", "errexit", "-c"]
  38. ARG TARGETPLATFORM
  39. RUN echo "Target platform is ${TARGETPLATFORM}"
  40. RUN \
  41. # Remove automatic apt cache Docker cleanup scripts
  42. rm -f /etc/apt/apt.conf.d/docker-clean; \
  43. # Sets timezone
  44. echo "${TZ}" > /etc/localtime; \
  45. # Creates mastodon user/group and sets home directory
  46. groupadd -g "${GID}" mastodon; \
  47. useradd -l -u "${UID}" -g "${GID}" -m -d /opt/mastodon mastodon; \
  48. # Creates symlink for /mastodon folder
  49. ln -s /opt/mastodon /mastodon;
  50. # hadolint ignore=DL3008,DL3005
  51. RUN \
  52. # Mount Apt cache and lib directories from Docker buildx caches
  53. --mount=type=cache,id=apt-cache-${TARGETPLATFORM},target=/var/cache/apt,sharing=locked \
  54. --mount=type=cache,id=apt-lib-${TARGETPLATFORM},target=/var/lib/apt,sharing=locked \
  55. # Upgrade to check for security updates to Debian image
  56. apt-get update; \
  57. apt-get dist-upgrade -yq; \
  58. apt-get install -y --no-install-recommends \
  59. ca-certificates \
  60. curl \
  61. tzdata \
  62. wget \
  63. ;
  64. # Set /opt/mastodon as working directory
  65. WORKDIR /opt/mastodon
  66. # Copy Node package configuration files from build system to container
  67. COPY package.json yarn.lock .yarnrc.yml /opt/mastodon/
  68. COPY .yarn /opt/mastodon/.yarn
  69. # Copy Streaming source code from build system to container
  70. COPY ./streaming /opt/mastodon/streaming
  71. RUN \
  72. # Mount local Corepack and Yarn caches from Docker buildx caches
  73. --mount=type=cache,id=corepack-cache-${TARGETPLATFORM},target=/usr/local/share/.cache/corepack,sharing=locked \
  74. --mount=type=cache,id=yarn-cache-${TARGETPLATFORM},target=/usr/local/share/.cache/yarn,sharing=locked \
  75. # Configure Corepack
  76. rm /usr/local/bin/yarn*; \
  77. corepack enable; \
  78. corepack prepare --activate;
  79. RUN \
  80. # Mount Corepack and Yarn caches from Docker buildx caches
  81. --mount=type=cache,id=corepack-cache-${TARGETPLATFORM},target=/usr/local/share/.cache/corepack,sharing=locked \
  82. --mount=type=cache,id=yarn-cache-${TARGETPLATFORM},target=/usr/local/share/.cache/yarn,sharing=locked \
  83. # Install Node packages
  84. yarn workspaces focus --production @mastodon/streaming;
  85. # Set the running user for resulting container
  86. USER mastodon
  87. # Expose default Streaming ports
  88. EXPOSE 4000
  89. # Run streaming when started
  90. CMD [ node ./streaming/index.js ]