Add Dockerfile and docker compose files specifically for a development#207
Add Dockerfile and docker compose files specifically for a development#207TomK32 wants to merge 1 commit intoxemle:masterfrom
Conversation
|
Hi @TomK32 Thank you for your PR I can see your motivation to move the development into docker containers. My question is:
Which IDE are you using for development so that this setup helps you to get things done? Why I am asking: For this project I am using Visual Studio Code. To run only the setup in containers does not help me to setup the full environment with the IDE. I've heard that dev containers should be awesome and gives so also control for your (recommended and used) IDE extensions. So I imagine a dev setup completely in containers including the IDE. The only external thing I would leave at the host system would be the git handling (because I do not know how to move this into the container as well. Well I would know but never thought about all the details...) And since you seem to be good dev I want to challenge this PR if you like. So what about having additional https://docs.linuxserver.io/images/docker-code-server as compose service so that the user can code directly in the browser without installing an IDE? So the user has just to checkout this repo and run one docker compose command and can code right away without any dependency except git and docker compose? And since VS Code has great support for dev containser I do not know if it would helpful to span the dev setup by a dev container definition instead of a bunch of docker compose files? (well, dev containers might use docker compose, too but I have the feeling that it comes with some sugar and spices around docker compose). And with dev container the user can decide to use his favorite IDE or the vscode in the browser... |
|
|
||
| EXPOSE 3000 5173 | ||
|
|
||
| CMD npm install --verbose && npm run build && node gallery.js run server |
There was a problem hiding this comment.
install and build is run on every start.
I recommend to move it to a RUN step so that the user can just build the image and then start the development when starting the container. Otherwise the container startup time will long at the first start and laggy on sequential starts.
There was a problem hiding this comment.
With CMD it is a one-step startup and years ago I was prone to forget the docker compose build step...
Removing node_modules from the .dockerignore will speed up sequential starts but... why restart the container in the first place? I have angular dev containers running without restarts for weeks and months. I see the webapp doing a fast recompile when I make small changes, gallery and api-server surely do the same?
There was a problem hiding this comment.
I have angular dev containers running without restarts for weeks and months
HomeGallery lacks of such setup. Currently it is more hand crafted and there is not a hot reloading mechanism for the server. So there is a big gap between frontend code and backend code. Also JS/TS, code style and documentation varies between the sub packages.
I see the webapp doing a fast recompile when I make small changes
This works since the recent change to the awesome vite.
gallery and api-server surely do the same?
Unfortunatly not.
why restart the container in the first place?
Depends for the audience.
For me as maintainer I work on my bare metal on the sources. No need for containerizing the dev environment.
The community is quite small and I think the experience should be as smooth as possible. I expect more that people try it on a daily basis. While it is safer to install and build the things on the container start, I have the impression it will slow down sequential starts.
Anyway, the containerizing the dev environment is a huge win and if we do not share where to run npm install and npm build it is a lower prio.
There was a problem hiding this comment.
gallery and api-server surely do the same?
Unfortunatly not.
Isn't nodemon the way to go for that? I gave it a try last week and while I'm not done yet with other changes, it does work as intended.
| webapp: | ||
| environment: | ||
| VIRTUAL_HOST: '${HOME_GALLERY_HOST:-home-gallery.localhost}' | ||
| VIRTUAL_PORT: 5173 |
There was a problem hiding this comment.
vite.config.ts in packages/webapp has hardcoded proxy route to the server on local host. This hard coded route can be improved by a environment variable with fallback to localhost.
So maybe this nginx proxy rule becomes obsolete?
There was a problem hiding this comment.
An env variable in vite.config.ts would be sweet and might indeed make some nginx proxy wizard obsolete.
nginx-proxy gets the requests to /api and /files before the webapp does so I added the VIRTUAL_HOST_MULTIPORTS rules above to point them to the correct container directly instead of having them go through the webapp/vite. What web servers are others using besides nginx? Or do you run it without one?
There was a problem hiding this comment.
I've added GALLERY_SERVER_URL env for the webapp package which can be used.
IMHO the GALLERY_SERVER_URL env with build in http proxy via vite is better than an extra nginx container.
Can you update your compose accordingly?
|
|
||
| EXPOSE 3000 | ||
|
|
||
| CMD sh -c 'npm install && node download-models.js && node index.js' |
There was a problem hiding this comment.
Also here: npm install and node download-models.js should be moved to a RUN step to improve container startup time.
There was a problem hiding this comment.
Currently the dev container of api-server has no difference to the docker image of production. So I think we can skip this for the beginning.
|
@xemle I use vim, running on the host. If you find that having whatever extra plugins your use for VSCode to be useful, add another docker-compose file or even a Dockerfile if that's the only way to add more plugins, why not? But I'd never force that on anyone else. Starting it all with three files in You can run git in a container as well, but it's getting a bit silly once you want to respect the user/group ownership:
|
|
|
||
| WORKDIR /app | ||
|
|
||
| ENV HOME=/data |
There was a problem hiding this comment.
Why providing the env vars not in the compose files? It would be more flexible in a dev environment which is not baked into the image
|
Could you
|
Give it a try and I'll update the docs once this is merged.
I'd recommend that you first get nginx-proxy working, I use it both on my dev machine, homelab and staging servers.
(obviously change the HOST)