-
Notifications
You must be signed in to change notification settings - Fork 371
Expand file tree
/
Copy pathDockerfile
More file actions
100 lines (77 loc) · 3.13 KB
/
Dockerfile
File metadata and controls
100 lines (77 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# syntax=docker/dockerfile:1
FROM node:current-slim AS builder
ARG TARGETARCH
# Added vips-dev and pkgconfig so that local vips is used instead of prebuilt
# Done for two reasons:
# - libvips binaries are not available for ARM32
# - It can break depending on the CPU (https://github.com/LemmyNet/lemmy-ui/issues/1566)
# Caching as per https://stackoverflow.com/a/72851168
RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked \
--mount=target=/var/cache/apt,type=cache,sharing=locked \
rm -f /etc/apt/apt.conf.d/docker-clean \
&& apt-get update \
&& apt-get -y --no-install-recommends install \
curl python3 gcc wget git libvips-dev pkg-config python3-pip make g++
# Install node-gyp and corepack
RUN --mount=type=cache,target=/root/.npm \
npm install -g -f node-gyp corepack
# Enable corepack to use pnpm
RUN corepack enable
WORKDIR /usr/src/app
ENV npm_config_target_platform=linux
ENV npm_config_target_libc=musl
# Cache deps
COPY package.json pnpm-lock.yaml ./
RUN \
--mount=type=cache,target=/root/.local/share/pnpm/store \
pnpm i
# Build
COPY generate_translations.js \
tsconfig.json \
webpack.config.js \
.babelrc \
./
COPY lemmy-translations lemmy-translations
COPY src src
COPY .git .git
# Set UI version
# If the CI is the cron, then use nightly, otherwise use the tag.
ARG CI_PIPELINE_EVENT
RUN \
VERSION_OUT=$([ "$CI_PIPELINE_EVENT" = "cron" ] && echo "nightly-$(date -u +"%Y-%m-%d")" || echo $(git describe --tag)); \
echo "export const VERSION = '$VERSION_OUT';" > "src/shared/version.ts"
RUN cat src/shared/version.ts
RUN echo "export const BUILD_DATE_ISO8601 = '$(date -u +"%Y-%m-%dT%H:%M:%SZ")';" > "src/shared/build-date.ts"
RUN \
--mount=type=cache,target=/root/.local/share/pnpm/store \
pnpm i
RUN \
--mount=type=cache,target=/root/.local/share/pnpm/store \
pnpm prebuild:prod
RUN \
--mount=type=cache,target=/root/.local/share/pnpm/store \
pnpm build:prod
RUN rm -rf ./node_modules/import-sort-parser-typescript
RUN rm -rf ./node_modules/typescript
RUN rm -rf ./node_modules/npm
FROM node:current-slim AS runner
ARG TARGETARCH
ENV NODE_ENV=production
RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked \
--mount=target=/var/cache/apt,type=cache,sharing=locked \
rm -f /etc/apt/apt.conf.d/docker-clean \
&& apt-get update \
&& apt-get -y --no-install-recommends install \
curl
COPY --from=builder --chown=node:node /usr/src/app/dist /app/dist
COPY --from=builder --chown=node:node /usr/src/app/node_modules /app/node_modules
RUN chown node:node /app
LABEL org.opencontainers.image.authors="The Lemmy Authors"
LABEL org.opencontainers.image.source="https://github.com/LemmyNet/lemmy-ui"
LABEL org.opencontainers.image.licenses="AGPL-3.0-or-later"
LABEL org.opencontainers.image.description="The official web app for Lemmy."
HEALTHCHECK --interval=60s --start-period=10s --retries=2 --timeout=10s CMD curl -ILfSs http://localhost:1234/ > /dev/null || exit 1
USER node
EXPOSE 1234
WORKDIR /app
CMD ["node", "--enable-source-maps", "dist/js/server.js"]