-
-
Notifications
You must be signed in to change notification settings - Fork 250
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
Optimize docker memory #976
Conversation
📦 A new release has been made for this pull request.To play around with this PR, pull Images are available for x86_64 and ARM64.
|
9940687
to
1666045
Compare
1666045
to
a325308
Compare
ce3d97b
to
1e85acb
Compare
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.
apologies for the late review, thanks for the contribution!
Dockerfile
Outdated
@@ -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 comment
The 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 comment
The 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.
@@ -14,18 +14,29 @@ COPY package.json . | |||
COPY yarn.lock . | |||
|
|||
RUN yarn install --prod | |||
RUN cp -R node_modules /usr/app/prod_node_modules |
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 this dependencies
layer, then not copying node_modules
and instead running yarn install --prod
in the runner image to simplify it a little
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'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.
🚀 Released in Release v2.4.4. |
When running this bot in docker container on my VPS server I encountered high ram usage. After investigation I found out that it runs with chain of yarn/npm/tsx/run-with-database-url.ts.
In this PR I:
tsc
.tsc
.run-with-database-url.ts
with simpler solution that doesn't run additional node processes in runtime.yarn start
with direct invocation of node indockerfile
.Before PR docker stats displayed 300-400mb of memory usage. Now it's 60-120mb.