Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
Feature/docker image optimizations (#4144)
Browse files Browse the repository at this point in the history
* feat: use standalone build of NextJS and outputFileTracing to reduce image size

* fix: improve download script

* wip: file proxy to sanity

* wip: rewrite headers

* wip: rewrite middlewares

* feat: removed helmet, custom next-server.js

* fix: cleanup todos

* fix: cleanup Dockerfile

* fix: cleanup next config

* fix: copy static folder after build to make it run locally

* fix: merge conflicts

Co-authored-by: VWSCoronaDashboard24 <[email protected]>
  • Loading branch information
1 parent 897aab5 commit 1f844fe
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 238 deletions.
41 changes: 31 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ COPY packages/cli/package.json ./packages/cli/
COPY packages/cms/package.json ./packages/cms/
COPY packages/common/package.json ./packages/common/
COPY packages/icons/package.json ./packages/icons/

RUN apk add --no-cache --virtual \
build-dependencies \
python3 \
Expand Down Expand Up @@ -67,21 +68,41 @@ ENV NEXT_PUBLIC_PHASE=$ARG_NEXT_PUBLIC_PHASE
ENV NEXT_PUBLIC_HOT_RELOAD_LOKALIZE=ARG_NEXT_PUBLIC_HOT_RELOAD_LOKALIZE
ENV API_URL=$ARG_API_URL

# Layer that always gets executed
FROM builder

# Yarn download uses the API_URL env variable to download the zip with JSONs from the provided URL.
RUN yarn download \
&& yarn workspace @corona-dashboard/cli validate-json-all \
&& yarn workspace @corona-dashboard/cli validate-last-values --fail-early \
&& yarn workspace @corona-dashboard/cms lokalize:import --dataset=$NEXT_PUBLIC_SANITY_DATASET \
&& yarn workspace @corona-dashboard/app build \
&& mkdir -p /app/packages/app/public/images/choropleth \
&& addgroup -g 1001 -S nodejs \
&& adduser -S nextjs -u 1001 \
&& chown -R nextjs:nodejs /app/packages/app/.next \
&& chown -R nextjs:nodejs /app/packages/app/public/images/choropleth
&& yarn workspace @corona-dashboard/app build

FROM node:lts-alpine as runner

# Required runtime dependencies for `canvas.node` - generating choropleths as image
RUN apk add --no-cache \
cairo \
jpeg \
pango \
musl \
giflib \
pixman \
pangomm \
libjpeg-turbo \
freetype

RUN addgroup -g 1001 -S nodejs \
&& adduser -S nextjs -u 1001

COPY --from=builder --chown=nextjs:nodejs /app/packages/app/.next/standalone /app/.next/standalone
COPY --from=builder --chown=nextjs:nodejs /app/packages/app/.next/static /app/.next/standalone/packages/app/.next/static
COPY --from=builder /app/packages/app/next.config.js /app/.next/standalone/packages/app

RUN mkdir -p /app/.next/standalone/packages/app/public/images/choropleth
RUN chown -R nextjs:nodejs /app/.next/standalone/packages/app/public/images/choropleth

WORKDIR /app/.next/standalone/packages/app

USER nextjs

CMD ["yarn", "start"]
ENV PORT=8080

CMD ["node", "server.js"]
214 changes: 0 additions & 214 deletions packages/app/next-server.js

This file was deleted.

Loading

0 comments on commit 1f844fe

Please sign in to comment.