Separate docker image when in devMode
# 🌱|help-and-getting-started
i
Hey nice garden folks! I would like to use a separate docker image when running in dev mode, how can I achieve that in the most straightforward way? I couldn't find
Went with a simple ternary in the end (although intuitively I was expecting it to be a dedicated field under services/devMode)
Copy code
kind: Module
name: ui
type: container
dockerfile: "${command.params contains 'dev' ? 'Dockerfile.dev' : 'Dockerfile'}"
b
Hey @icy-furniture-17516 this was actually a really hacky and neat way to solve this problem! I also agree that there should me a dedicated field to add a different dockerfile if using devMode!🌸 Would you be open to creating a feature request directly in our Github for this so we might have it in the future? 🏡
i
Absolutely!
b
Thanks a lot! 🌸
i
b
Thanks a lot @icy-furniture-17516 I'll make sure to bring this Feature request up!
a
Are you using Dockerfiles specifically for devMode, to work around the fact that the container module will rebuild when the Dockerfile source code (from COPY statements) changes, which is redundant when devMode of the service which uses the output image is already syncing the same source code? I think that'd it be a nice feature for Garden to
exclude
files when building a service's container, that are `include`d in the devMode sync, rather than maintaining duplicate Dockerfiles just for dev mode with the source code stripped out. I'm not sure that's possible/desirable though so this is a nice workaround
i
Well I was doing it because the dev container is very different from the prod container. In dev we simply run
yarn serve
while in prod we use a multistage docker build to build the static assets, and copy them over to a final image where nginx will pick them up
but I noticed that garden doesn't rebuild the image when I make changes in the source files
sometimes it does, but I'm not entirely sure when and why exactly
but you are right, it would be really nice if we could control when to rebuild an image when running in devmode
@bright-policeman-43626 @quaint-dress-831 how does it work exactly? When does garden rebuild an image when it is running in devMode? I couldn't find detailed information on that.
q
@icy-furniture-17516 I think Dev Mode will not trigger a rebuild on anything within the Mutagen file sync path you've set. The UX of running a new pod and terminating your connection to the last every time you save would be nasty. I will double-check on the nitty-gritty technicals for you. @chilly-gigabyte-83853 would likely know.
i
I assumed the same, thx for checking! I'm happy with some pointers in the code and dig deeper for myself
a
Turns out it was actually rebuilding the image for the tests which I didn't expect in dev mode https://github.com/garden-io/garden/issues/3922
c
Hi @icy-furniture-17516, sorry for the late reply but I completely missed the mention by @quaint-dress-831 😬. In devMode Garden won't rebuild the image, we usually use a ternary for the Dockerfile (if you need different Dockerfiles). I'd be interested to hear more about your setup and what's the difference between prod/dev dockerfiles. We use one for both environments but it's a multistage one and we specify a different stage for development using
build.targetImage
. We start in devMode a command that runs concurrently, which runs
swc
in watch mode for fast rebuilding and nodemon to restart the node server (I am assuming you are running a node app here). The dev command and devMode are getting a revamp in the upcoming 0.13 release and will also allow an interactive way of rebuilding the container if needed, but I'd need to double check for details before making promises. 🙂
i
we started to use multi-stage as well, but how do I tell I want to use the intermediate layer when in dev mode? we still use a variable and ended up with this:
Copy code
mode: "${command.params contains 'dev' && (command.params.dev contains 'mymodule' || command.params.dev contains '*' || command.params.dev.length == 0) ? 'dev' : 'prod'}"
> In devMode Garden won't rebuild the image I experienced rebuilds in devMode when I modified the module's garden.yml and I ended up excude-ing it from module files. Is that a bad practice?
Another thing we are struggling with a bit (and sorry if it's offtopic here, I'm happy to bring it up separately if it makes sense) is using entr with multiple files. The issue is, that it seems entr might reload our app when the sync has finished for one of the files but is still in progress but the reload doesn't seem to happen again with the final state. Is it a thing you experienced as well, or maybe it's just a false assumption we had during our trial and error sessions? Is there a better way to do this? Do you plan to have better support for this app reload use-case? For example if this is really an issue, garden could possibly provide a convenient way for using entr by syncing a hash (calculated from a predefined file set) to the continer and let entr watch and react only for that
q
@icy-furniture-17516 what do you mean by entr?
a
Just wanted to chime in here to mention this: https://github.com/garden-io/garden/pull/3913 This is about to get a lot cleaner and easier with the upcoming Bonsai (0.13) release.
i
4 Views