1
0

Dockerfile 4.3 KB

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