Skip to content

Commit 0d09240

Browse files
committed
Get docker builds working
1 parent c1be4cb commit 0d09240

File tree

5 files changed

+141
-0
lines changed

5 files changed

+141
-0
lines changed

.dockerignore

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
node_modules
2+
**/node_modules
3+
4+
.git
5+
.gitignore
6+
7+
**/build
8+
**/public/assets
9+
10+
.env*
11+
**/.env*

.npmrc

+4
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
node-linker=hoisted
2+
# For docker builds:
3+
deploy-all-files=true
4+
inject-workspace-packages=true
5+
sync-injected-deps-after-scripts[]=build

Dockerfile

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# syntax=docker/dockerfile:1.12
2+
3+
# Please see https://docs.docker.com/engine/reference/builder for information about
4+
# the extended buildx capabilities used in this file.
5+
# Make sure multiarch TARGETPLATFORM is available for interpolation
6+
# See: https://docs.docker.com/build/building/multi-platform/
7+
ARG TARGETPLATFORM=${TARGETPLATFORM}
8+
ARG BUILDPLATFORM=${BUILDPLATFORM}
9+
ARG BASE_REGISTRY="docker.io"
10+
11+
# # Node version to use in base image, change with [--build-arg NODE_MAJOR_VERSION="20"]
12+
# renovate: datasource=node-version depName=node
13+
ARG NODE_MAJOR_VERSION="22"
14+
15+
# Node image to use for base image based on combined variables (ex: 20-bookworm-slim)
16+
FROM ${BASE_REGISTRY}/node:${NODE_MAJOR_VERSION}-alpine AS node
17+
18+
# Resulting version string is vX.X.X-FIRES_VERSION_PRERELEASE+FIRES_VERSION_METADATA
19+
# Example: v4.3.0-nightly.2023.11.09+pr-123456
20+
# Overwrite existence of 'alpha.X' in version.json [--build-arg FIRES_VERSION_PRERELEASE="nightly.2023.11.09"]
21+
ARG FIRES_VERSION_PRERELEASE=""
22+
# Append build metadata or fork information to version.json [--build-arg FIRES_VERSION_METADATA="pr-123456"]
23+
ARG FIRES_VERSION_METADATA=""
24+
ARG SOURCE_COMMIT=""
25+
26+
# Timezone used by the Docker container and runtime, change with [--build-arg TZ=Europe/Berlin]
27+
ARG TZ="Etc/UTC"
28+
# Linux UID (user id) for the fires user, change with [--build-arg UID=1234]
29+
ARG UID="991"
30+
# Linux GID (group id) for the fires user, change with [--build-arg GID=1234]
31+
ARG GID="991"
32+
33+
# Apply FIRES build options based on options above
34+
ENV \
35+
# Apply FIRES version information
36+
FIRES_VERSION_PRERELEASE="${FIRES_VERSION_PRERELEASE}" \
37+
FIRES_VERSION_METADATA="${FIRES_VERSION_METADATA}" \
38+
SOURCE_COMMIT="${SOURCE_COMMIT}" \
39+
# Apply timezone
40+
TZ=${TZ}
41+
42+
ENV \
43+
# Configure the IP to bind to when serving traffic
44+
HOST="0.0.0.0" \
45+
# Use production settings for nodejs based tools
46+
NODE_ENV="production"
47+
48+
# Set default shell used for running commands
49+
SHELL ["/bin/sh", "-o", "pipefail", "-o", "errexit", "-c"]
50+
51+
ARG TARGETPLATFORM
52+
53+
RUN echo "Target platform is $TARGETPLATFORM";
54+
55+
RUN \
56+
# Sets timezone
57+
echo "${TZ}" > /etc/localtime; \
58+
# Creates fires user/group and sets home directory
59+
addgroup -Sg "${GID}" fires; \
60+
adduser -S -u "${UID}" -h /opt/fires fires fires; \
61+
# Creates /fires symlink to /opt/fires
62+
ln -s /opt/fires /fires;
63+
64+
# Set /opt/mastodon as working directory
65+
WORKDIR /opt/fires
66+
67+
# hadolint ignore=DL3008,DL3005
68+
RUN \
69+
# Mount Apk cache directory from Docker buildx caches
70+
--mount=type=cache,id=apk-cache-${TARGETPLATFORM},target=/var/cache/apk/,sharing=locked \
71+
# Apk update & upgrade to check for security updates to Debian image
72+
apk update; \
73+
apk upgrade; \
74+
# Install curl and tini
75+
apk add tini tzdata curl wget jq;
76+
77+
# Configure pnpm
78+
ENV PNPM_HOME="/pnpm"
79+
ENV PATH="$PNPM_HOME:$PATH"
80+
81+
# Create temporary build layer from base image
82+
FROM node AS build
83+
ARG TARGETPLATFORM
84+
COPY . /opt/fires
85+
WORKDIR /opt/fires
86+
87+
# Configure Corepack
88+
RUN \
89+
corepack enable; \
90+
corepack prepare --activate;
91+
92+
RUN --mount=type=cache,id=pnpm-${TARGETPLATFORM},target=/pnpm/store pnpm install --filter !@fedimod/fires-docs --frozen-lockfile
93+
RUN pnpm run --filter=@fedimod/fires-server -r build
94+
RUN pnpm deploy --filter=@fedimod/fires-server --prod /fires-server-deploy
95+
96+
# pnpm deploy omits the `imports` key in the output package.json,
97+
# so we have to copy it across ourselves:
98+
RUN \
99+
mv /opt/fires/components/fires-server/build /fires-server-build; \
100+
jq --argjson imports "$(jq .imports /opt/fires/components/fires-server/package.json)" '.imports = $imports' /fires-server-deploy/package.json > /fires-server-build/package.json;
101+
102+
FROM node AS fires-server
103+
COPY --from=build /fires-server-build/ /opt/fires/fires-server/
104+
COPY --from=build /fires-server-deploy/pnpm-lock.yaml /opt/fires/fires-server/
105+
COPY --from=build /fires-server-deploy/node_modules /opt/fires/fires-server/node_modules/
106+
WORKDIR /opt/fires/fires-server/
107+
USER fires
108+
EXPOSE 4444
109+
110+
# Set container tini as default entry point
111+
ENTRYPOINT ["/sbin/tini", "--"]
112+
113+
CMD ["node", "bin/server.js"]

components/fires-server/.env.docker

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
PORT=4444
2+
3+
LOG_LEVEL=trace
4+
5+
# You can generate an APP_KEY with: `node ace generate:key` or `openssl rand -hex 32`
6+
APP_KEY=test_determinist_key_DO_NOT_USE_IN_PRODUCTION
7+
8+
DATABASE_HOST=postgresql
9+
DATABASE_PORT=5432
10+
DATABASE_USER=postgres
11+
DATABASE_PASSWORD=postgres
12+
DATABASE_DATABASE=fires_production

pnpm-lock.yaml

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)