-
-
Notifications
You must be signed in to change notification settings - Fork 273
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 memory #976
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,18 +14,29 @@ COPY package.json . | |
COPY yarn.lock . | ||
|
||
RUN yarn install --prod | ||
RUN cp -R node_modules /usr/app/prod_node_modules | ||
|
||
RUN yarn install | ||
|
||
FROM dependencies AS builder | ||
|
||
COPY . . | ||
|
||
# Run tsc build | ||
RUN yarn prisma generate | ||
RUN yarn build | ||
|
||
# Only keep what's necessary to run | ||
FROM base AS runner | ||
|
||
WORKDIR /usr/app | ||
|
||
COPY --from=dependencies /usr/app/node_modules node_modules | ||
COPY --from=builder /usr/app/dist ./dist | ||
COPY --from=dependencies /usr/app/prod_node_modules node_modules | ||
COPY --from=builder /usr/app/node_modules/.prisma/client ./node_modules/.prisma/client | ||
|
||
COPY . . | ||
|
||
RUN yarn prisma generate | ||
|
||
ARG COMMIT_HASH=unknown | ||
ARG BUILD_DATE=unknown | ||
|
||
|
@@ -34,4 +45,6 @@ ENV NODE_ENV production | |
ENV COMMIT_HASH $COMMIT_HASH | ||
ENV BUILD_DATE $BUILD_DATE | ||
|
||
CMD ["tini", "--", "yarn", "start"] | ||
RUN echo "DATABASE_URL=$(node dist/scripts/print-database-url.js)" > .env | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we shouldn't bake the DATABASE_URL into the image, as it potentially exposes a secret, won't work for the images published publicly on Docker Hub, and makes it harder to change I think it should work without this step? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now it can't expose any secret because location of file with SQLite DB isn't a secret. But I changed it to be more configurable. |
||
|
||
CMD ["tini", "--", "node", "dist/scripts/migrate-and-start.js"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import createDatabaseUrl from '../utils/create-database-url.js'; | ||
import {DATA_DIR} from '../services/config.js'; | ||
|
||
console.log(createDatabaseUrl(DATA_DIR)); |
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 would recommend doing
yarn install
(all dependencies) in thisdependencies
layer, then not copyingnode_modules
and instead runningyarn install --prod
in the runner image to simplify it a littleThere 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've done it to avoid downloading prod dependencies twice. That way it seems to work faster. But if you prefer calling downloading twice I will change it.