Dockerfile 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. # syntax=docker/dockerfile:1.4
  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. ;
  63. # Set /opt/mastodon as working directory
  64. WORKDIR /opt/mastodon
  65. # Copy Node package configuration files from build system to container
  66. COPY package.json yarn.lock .yarnrc.yml /opt/mastodon/
  67. COPY .yarn /opt/mastodon/.yarn
  68. # Copy Streaming source code from build system to container
  69. COPY ./streaming /opt/mastodon/streaming
  70. RUN \
  71. # Mount local Corepack and Yarn caches from Docker buildx caches
  72. --mount=type=cache,id=corepack-cache-${TARGETPLATFORM},target=/usr/local/share/.cache/corepack,sharing=locked \
  73. --mount=type=cache,id=yarn-cache-${TARGETPLATFORM},target=/usr/local/share/.cache/yarn,sharing=locked \
  74. # Configure Corepack
  75. rm /usr/local/bin/yarn*; \
  76. corepack enable; \
  77. corepack prepare --activate;
  78. RUN \
  79. # Mount 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. # Install Node packages
  83. yarn workspaces focus --production @mastodon/streaming;
  84. # Set the running user for resulting container
  85. USER mastodon
  86. # Expose default Streaming ports
  87. EXPOSE 4000
  88. # Run streaming when started
  89. CMD [ node ./streaming/index.js ]