Skip to content
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

feat: use production level docker settings #26

Merged
merged 18 commits into from
Oct 24, 2023

Conversation

SgtPooki
Copy link
Member

@SgtPooki SgtPooki commented Oct 24, 2023

  • fix: docker and naming improvements
  • fix: graceful shutdown and docker cleanup
  • feat: more docker ignore and smaller prod image

For best practices, see:


Docker sizes:

main branch

$ docker inspect -f "{{ .Size }}" helia-docker-server | numfmt --to=si                                                                           
2.1G

from this PR

$ docker inspect -f "{{ .Size }}" helia-docker-helia-http-gateway | numfmt --to=si
712M

@SgtPooki
Copy link
Member Author

Dockerfile Outdated
Comment on lines 27 to 28
COPY --from=builder /usr/lib/**/libcrypto*.so /usr/lib/
COPY --from=builder /usr/lib/**/libssl*.so /usr/lib/
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
COPY --from=builder /usr/lib/**/libcrypto*.so /usr/lib/
COPY --from=builder /usr/lib/**/libssl*.so /usr/lib/
COPY --from=builder /usr/lib/**/libcrypto* /usr/lib/
COPY --from=builder /usr/lib/**/libssl* /usr/lib/

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is more than just the individual *.so files needed. It would be better to nail this down more, but removing the .so seems to fix the issue.

Dockerfile Outdated
RUN npm run build

ENV NODE_ENV production
RUN npm prune --production
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
RUN npm prune --production
RUN npm prune --omit=dev

Dockerfile Outdated
Comment on lines 19 to 20
FROM node:20-slim as app
WORKDIR /app
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
FROM node:20-slim as app
WORKDIR /app
FROM node:20-slim as app
ENV NODE_ENV production
WORKDIR /app

Copy link
Collaborator

@whizzzkid whizzzkid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was refraining from image size optimizations, but I guess this is good! Some more improvements in comments.

@@ -1,14 +1,40 @@
FROM node:20-slim
FROM node:20-slim as builder
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if alpine images are going to be even smaller.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably

Comment on lines +27 to +28
COPY --from=builder /usr/lib/**/libcrypto* /usr/lib/
COPY --from=builder /usr/lib/**/libssl* /usr/lib/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been burned in the past while handling shared libs. Can we not:

flowchart
    A[node:20-slim] -->|Install LibSSL| B(Base Image)
    B --> C[Builder Image]
    C --> |Build Assets| D(Built Image)
    B --> E[App Image]
    D --> |Copy Built Assets| E
    E --> F(Publish)
Loading

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can re-install libssl and it would re-use the cached image, but that was more troublesome due to some additional things being installed by other apt-get installed packges: build-essential cmake git libssl-dev and I didn't want to reinstall all of them.

ENV NODE_ENV production
WORKDIR /app
# built src without dev dependencies
COPY --from=builder /app ./
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a further opportunity for improvement will be removing node_modules as it has devDependencies here, reinstalling with NODE_ENV=production (already set) would only install dependencies

Further reduction in image size.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

node_modules should be removed above in the npm prune --omit=dev line

Dockerfile Show resolved Hide resolved
@SgtPooki
Copy link
Member Author

I was refraining from image size optimizations, but I guess this is good! Some more improvements in comments.

btw its not just image size adjustments, but signal handling and other general best-practices (without me spending too much time on it: ~2hr) so that tiros (or whoever) can shut it down when they want to and it wont hang

@SgtPooki SgtPooki merged commit 37ee45b into main Oct 24, 2023
1 of 2 checks passed
@SgtPooki SgtPooki deleted the feat/docker-image-improvements branch October 24, 2023 23:51
whizzzkid added a commit that referenced this pull request Oct 26, 2023
* main: (27 commits)
  feat(e2e): add /api/v0/repo/gc test
  chore: disable METRICS on CI e2e test runs
  test: add e2e test for /api/v0/version endpoint
  feat(server): ⚡️ Subdomain Gateway Using Fastify (#31)
  feat: use production level docker settings (#26)
  chore: remove unused playwright init code
  fix: use active LTS in package.json engines
  fix: playwright CI node-version=20
  test: get clinic flame & doctor output from e2e tests
  test: e2e updates
  fix: use HOST constant in healthcheck
  fix: use HOST constant
  test: cleanup playwright test code
  test: add playwright tests
  feat: move HOST,PORT to src/constants.ts
  fix: ✏️  Fixing urls. (#23)
  fix: ✏️ helia-docker -> helia-http-gateway (#22)
  build(deps): Bump @babel/traverse and depcheck (#13)
  feat: add health-check (#21)
  fix(server): 🩹 Using sessionID as a fallback to requests where referer is missing. (#20)
  ...

Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants