-
-
Notifications
You must be signed in to change notification settings - Fork 222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize docker image size #91
Merged
Merged
Changes from 2 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a0e8015
Move prisma to runtime dependencies
jantuomi d5fc838
Optimize Dockerfile and build script
jantuomi 9461928
Fix: remove mention of generated next-env.d.ts in Dockerfile
jantuomi cfd6ea4
Add missing reset.d.ts file to Dockerfile
jantuomi d15012f
Remove compression steps from Dockerfile and entrypoint script
jantuomi 1b61670
Add an env file with mocked env vars added for Docker production builds
justcallmelarry 407af00
Use server actions to get runtime env vars
jantuomi ebcef69
Refactor types and names
jantuomi 8fdddb4
Rollback serverActions, use parsed Zod object for runtime env
jantuomi 8bb08bd
Reintroduce featureFlags object to avoid passing secret envs to the f…
jantuomi efa352b
Improve string to boolean coercion
jantuomi fc8e274
Run prettier autoformat
jantuomi 8d7b8b5
Fix type issue, rename function to match behaviour better
jantuomi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,51 @@ | ||
FROM node:21-slim as base | ||
FROM node:21-alpine as base | ||
|
||
EXPOSE 3000/tcp | ||
WORKDIR /usr/app | ||
COPY ./ ./ | ||
COPY ./package.json \ | ||
./package-lock.json \ | ||
./next.config.js \ | ||
./next-env.d.ts \ | ||
./tsconfig.json \ | ||
./tailwind.config.js \ | ||
./postcss.config.js ./ | ||
COPY ./prisma ./prisma | ||
COPY ./src ./src | ||
|
||
RUN apt update && \ | ||
apt install openssl -y && \ | ||
apt clean && \ | ||
apt autoclean && \ | ||
apt autoremove && \ | ||
RUN apk add --no-cache openssl && \ | ||
npm ci --ignore-scripts && \ | ||
npm install -g prisma && \ | ||
prisma generate | ||
npx prisma generate | ||
|
||
# env vars needed for build not to fail | ||
ARG POSTGRES_PRISMA_URL | ||
ARG POSTGRES_URL_NON_POOLING | ||
ENV POSTGRES_PRISMA_URL=http://temporary.build.url | ||
ENV POSTGRES_URL_NON_POOLING=http://temporary.build.url | ||
|
||
ENV NEXT_TELEMETRY_DISABLED=1 | ||
RUN npm run build | ||
|
||
ENTRYPOINT ["/usr/app/scripts/container-entrypoint.sh"] | ||
RUN rm -r .next/cache | ||
|
||
FROM node:21-alpine as runtime-deps | ||
|
||
WORKDIR /usr/app | ||
RUN apk add --no-cache zstd | ||
COPY --from=base /usr/app/package.json /usr/app/package-lock.json ./ | ||
COPY --from=base /usr/app/.next ./.next | ||
COPY --from=base /usr/app/prisma ./prisma | ||
COPY ./public ./public | ||
|
||
RUN npm ci --omit=dev --omit=optional --ignore-scripts && \ | ||
npx prisma generate | ||
|
||
RUN tar cvf - . | zstd -o app.tar.zst | ||
|
||
FROM node:21-alpine as runner | ||
|
||
WORKDIR /usr/app | ||
RUN apk add --no-cache zstd | ||
|
||
COPY ./scripts ./scripts | ||
COPY --from=runtime-deps /usr/app/app.tar.zst ./app.tar.zst | ||
|
||
EXPOSE 3000/tcp | ||
|
||
ENTRYPOINT ["/bin/sh", "/usr/app/scripts/container-entrypoint.sh"] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
#!/bin/bash | ||
prisma migrate deploy | ||
|
||
set -euxo pipefail | ||
|
||
if [[ -f "app.tar.zst" ]]; then | ||
zstd -d app.tar.zst -c | tar xf - | ||
rm app.tar.zst | ||
fi | ||
|
||
npx prisma migrate deploy | ||
npm run start |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file does not exist as far as I can tell? So my test build of your branch is failing
Maybe I'm missing something
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried creating an empty file with the name just to get further, and it seems like it's gitignored, so I guess this is some sort of local file that I don't have (and which would not be present should a GHA be introduced to build images automatically or similar).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, that seems like a generated file. I'll remove that line 👍