Multi-platform Dockerfile (#2235)

* Multi-platform Dockerfile

* Add ARM64 build to Woodpecker

* Sharp 0.32.6 is in package.json now

* Add Docker Healthcheck

* Prevent 'Inferno is in development mode' message

Currently Inferno runs in development mode because NODE_ENV=production was not set. This has a negative effect on performance, and for debugging purposes developers can override this flag in their Docker composefile.

* Fixing babel build.

* Removing node-prune.

---------

Co-authored-by: Dessalines <tyhou13@gmx.com>
This commit is contained in:
Kroese 2023-11-27 13:32:04 +01:00 committed by GitHub
parent ae4a4cc8af
commit 639aa28245
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 13 deletions

View file

@ -28,7 +28,7 @@ steps:
settings: settings:
repo: dessalines/lemmy-ui repo: dessalines/lemmy-ui
dockerfile: Dockerfile dockerfile: Dockerfile
platforms: linux/amd64 platforms: linux/amd64, linux/arm64
tag: ${CI_COMMIT_TAG} tag: ${CI_COMMIT_TAG}
when: when:
event: tag event: tag
@ -39,7 +39,7 @@ steps:
settings: settings:
repo: dessalines/lemmy-ui repo: dessalines/lemmy-ui
dockerfile: Dockerfile dockerfile: Dockerfile
platforms: linux/amd64 platforms: linux/amd64, linux/arm64
tag: dev tag: dev
when: when:
event: cron event: cron

View file

@ -1,16 +1,27 @@
FROM node:20-alpine as builder FROM node:20-alpine as builder
RUN apk update && apk add curl yarn python3 build-base gcc wget git --no-cache
RUN curl -sf https://gobinaries.com/tj/node-prune | sh # Upgrade to edge to fix sharp/libvips issues
RUN echo "https://dl-cdn.alpinelinux.org/alpine/edge/main" > /etc/apk/repositories
RUN echo "https://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories
# 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)
RUN apk update && apk upgrade && apk add --no-cache curl yarn python3 build-base gcc wget git vips-dev pkgconfig
# Install node-gyp
RUN npm install -g node-gyp
WORKDIR /usr/src/app WORKDIR /usr/src/app
ENV npm_config_target_arch=x64
ENV npm_config_target_platform=linux ENV npm_config_target_platform=linux
ENV npm_config_target_libc=musl ENV npm_config_target_libc=musl
# Cache deps # Cache deps
COPY package.json yarn.lock ./ COPY package.json yarn.lock ./
RUN yarn --production --prefer-offline --pure-lockfile
RUN yarn --production --prefer-offline --pure-lockfile --network-timeout 100000
# Build # Build
COPY generate_translations.js \ COPY generate_translations.js \
@ -26,12 +37,9 @@ COPY .git .git
# Set UI version # Set UI version
RUN echo "export const VERSION = '$(git describe --tag)';" > "src/shared/version.ts" RUN echo "export const VERSION = '$(git describe --tag)';" > "src/shared/version.ts"
RUN yarn --production --prefer-offline RUN yarn --production --prefer-offline --network-timeout 100000
RUN NODE_OPTIONS="--max-old-space-size=8192" yarn build:prod RUN NODE_OPTIONS="--max-old-space-size=8192" yarn build:prod
# Prune the image
RUN node-prune /usr/src/app/node_modules
RUN rm -rf ./node_modules/import-sort-parser-typescript RUN rm -rf ./node_modules/import-sort-parser-typescript
RUN rm -rf ./node_modules/typescript RUN rm -rf ./node_modules/typescript
RUN rm -rf ./node_modules/npm RUN rm -rf ./node_modules/npm
@ -39,13 +47,27 @@ RUN rm -rf ./node_modules/npm
RUN du -sh ./node_modules/* | sort -nr | grep '\dM.*' RUN du -sh ./node_modules/* | sort -nr | grep '\dM.*'
FROM node:20-alpine as runner FROM node:20-alpine as runner
RUN apk update && apk add curl --no-cache ENV NODE_ENV=production
# Upgrade to edge to fix sharp/libvips issues
RUN echo "https://dl-cdn.alpinelinux.org/alpine/edge/main" > /etc/apk/repositories
RUN echo "https://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories
RUN apk update && apk upgrade && apk add curl vips-cpp
COPY --from=builder /usr/src/app/dist /app/dist COPY --from=builder /usr/src/app/dist /app/dist
COPY --from=builder /usr/src/app/node_modules /app/node_modules COPY --from=builder /usr/src/app/node_modules /app/node_modules
RUN chown -R node:node /app RUN chown -R 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 USER node
EXPOSE 1234 EXPOSE 1234
WORKDIR /app WORKDIR /app
CMD node dist/js/server.js CMD exec node dist/js/server.js

View file

@ -97,11 +97,11 @@
"tributejs": "^5.1.3", "tributejs": "^5.1.3",
"webpack": "^5.89.0", "webpack": "^5.89.0",
"webpack-cli": "^5.1.4", "webpack-cli": "^5.1.4",
"@babel/plugin-proposal-class-properties": "^7.18.6",
"webpack-node-externals": "^3.0.0" "webpack-node-externals": "^3.0.0"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.23.3", "@babel/core": "^7.23.3",
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@types/autosize": "^4.0.0", "@types/autosize": "^4.0.0",
"@types/bootstrap": "^5.2.6", "@types/bootstrap": "^5.2.6",
"@types/cookie": "^0.6.0", "@types/cookie": "^0.6.0",