-
Notifications
You must be signed in to change notification settings - Fork 7
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
Draft: use multi-staged build for clean frontend image #348
Conversation
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.
Did you try that? I'm surprised that npm start
works without re-compiling everything.
Dockerfiles/Dockerfile.frontend
Outdated
FROM node:20-bookworm as app | ||
|
||
COPY --from=build /web/frontend/ . | ||
|
||
ENTRYPOINT ["npm", "start"] |
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.
Does that work? You don't need nodejs
anymore, as the npm run build
will create just a set of static html/js/css files. So you can do:
https://github.com/c4dt/service-stainless/blob/main/webapp/Dockerfile#L11
Or
Or any other lightweight web server image.
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 was testing it and it initially seemed fine, but now it's not working, so I put it back into Draft
before that it sort of complained that there was no package.json file as npm ci does not seem to generate one, so I copied everything over to test that
thanks for the comments, I think the error is in there somewhere (I was looking at the Dockerfiles just now, I think https://github.com/c4dt/service-spindle/blob/main/Dockerfile is probably the closest)
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 was looking at the Dockerfiles
The spindle Dockerfile uses the node
image, which is not necessary, as you should only have static files to serve for the frontend. So either a python or a webserver for static content is enough. Here is another, even more minimal webserver:
https://lipanski.com/posts/smallest-docker-image-static-website
2d4ecc6
to
6d6b29b
Compare
the frontend UI seems to be working with this version now, but I'm having trouble receiving data from DELA now |
6d6b29b
to
52204fa
Compare
OK, working now |
WORKDIR /web/frontend | ||
COPY --from=build /web/frontend/build/ . | ||
|
||
ENTRYPOINT ["python3", "-m", "http.server", "3000", "--directory", "/web/frontend/", "--bind", "127.0.0.1"] |
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 see you removed npm start
in favor of building the static site. There's one caveat to that, which is that during development, you will need to rebuild every time you do a change.
With no npm start
, you can get hot reloading, or at least you would need to do docker compose restart container
With this design, you would need docker .... build
first then docker .... up
second.
but... maybe, if we change the entrypoint to a CMD, we can override it in compose file to a npm run
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.
please see @ineiti 's comments, now that we want to actually deploy it I agree that it makes sense to have a clean Docker image
personally, I have a separate Dockerfile for developing that kept the npm start
for the reasons you mentioned
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.
You can also add a Dockerfile.dev
with the npm start
in it.
For the npm start
, do you use the -v
to link your local directory?
FROM node:20-bookworm as app | ||
|
||
WORKDIR /web/frontend | ||
COPY --from=build /web/frontend/build/ . | ||
|
||
ENTRYPOINT ["python3", "-m", "http.server", "3000", "--directory", "/web/frontend/", "--bind", "127.0.0.1"] |
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.
why use python (and the node
image) instead of a webserver, since that's the only thing we need? 🤔
PS: there are a couple of Sonar code smells that are trivial to address ( |
52204fa
to
cfd1436
Compare
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
the frontend server acts as a reverse proxy, so there needs to be a server running here as well - we'll shelve this PR for now |
closes #342