-
Notifications
You must be signed in to change notification settings - Fork 17
Multistage build docker #115
Multistage build docker #115
Conversation
.travis.yml
Outdated
- docker build --build-arg BUILD_COMMIT=$TRAVIS_COMMIT -t humanconnection/nitro-web . | ||
- docker-compose -f docker-compose.yml up -d | ||
- docker build --build-arg BUILD_COMMIT=$TRAVIS_COMMIT --target production -t humanconnection/nitro-web . | ||
- docker-compose -f docker-compose.travis.yml up -d |
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.
- docker-compose -f docker-compose.travis.yml up -d | |
- docker-compose -f docker-compose.yml up -f docker-compose.travis.yml up -d |
@mattwr18 I suspect this is the reason for the failing build. Without the default docker-compose.yml
frontend and backend are not joining the same network and cannot reach each other. Also we wait-on http://localhost:3000
later in .travis.yml
and if we don't expose port 3000 we will wait forever.
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.
Great, I'll give this a go! I am exposing 3000 on line 34... although I believe it is waiting cause it is not spinning up properly, although, it is failing silently
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.
Are you sure? I believe with docker-compose
you have to expose all the ports in the .yml
file explicitly. (Although I never looked it up)
docker-compose.travis.yml
Outdated
|
||
services: | ||
backend: | ||
image: humanconnection/nitro-web:builder |
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.
image: humanconnection/nitro-web:builder |
I think it's in the base docker-compose.yml
so not needed here.
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.
Do you know the reason for having yet another docker-compose.yml
just for travis? Because of shared folders. Travis struggles to delete them after running the tests, thus silently failing our deployments. The reason why Travis cannot delete the files is that the docker
user on Travis creates the files, not the user who is later trying to delete them.
.travis.yml
Outdated
@@ -19,7 +19,7 @@ before_install: | |||
|
|||
install: | |||
- docker build --build-arg BUILD_COMMIT=$TRAVIS_COMMIT --target production -t humanconnection/nitro-web . | |||
- docker-compose -f docker-compose.yml -f docker-compose.travis.yml up -d | |||
- docker-compose -f docker-compose.yml up -f docker-compose.travis.yml up -d |
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.
no no, the up
is there already 😉 @mattwr18
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.
ahh, right... I thought I had missed it yesterday from your review above... it's still failing the build though
@mattwr18 great work, can you tell me how large the docker image is on your machine after this PR? |
A little bigger than a third of the size it was!! |
@mattwr18 yes, you can add a repository and a tag. See our build server and the deploy script:
adds the repository and
does the same for |
Output from build, command
but unfortunately still getting this output
|
I've run the exact same commands as from the build locally and they have passed... |
@mattwr18 ouch, that was a hard to spot error. It struck my eye when I was switching back and forth between `docker-compose.override.yml` and `docker-compose.travis.yml`.
ahhh duh!! sorry 😛 |
This should fix our build server. Probably the container immediately exited on Travis which is using the `builder` stage for testing.
Size of the production image now
|
Why not just copy all into the build image and trusting the dockerignore file? @mattwr18 |
that's a good idea @appinteractive, right now we were just concerned with the minimum to get it passing the build, but we can definitely explore that route. Currently, it's unexpectedly failing the build because of many linting errors, which we are not able to reproduce locally. |
Yeah that’s because of failing config files for the Linter. Please try to copy the whole root dir and trust the dockerignore. After that you just copy the needed files to the production image. That way the build will be more solid to change imho. |
Dockerfile
Outdated
FROM base as production | ||
ENV NODE_ENV=production | ||
COPY --from=build-and-test ./nitro-web/node_modules ./node_modules | ||
COPY --from=build-and-test ./nitro-web/plugins ./plugins |
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 do you copy the plugins and static files over when you already copied everything in the base 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.
Good point, carry over from before your above suggestion.
…3-minimize-docker-image-size-with-multi-stage-build
…3-minimize-docker-image-size-with-multi-stage-build
@appinteractive @roschaefer I have gotten this build to pass reliably again and cleaned it up even more in the process, taking into account your suggestions. It is not an ideal situation, however. The reason it was failing the build before @roschaefer is because for some reason the commands This is also the reason I needed to add the |
a96221f
to
6b4601e
Compare
I give up now after numerous attempts to reduce the docker image size. The only thing left is that I've put the NODE_ENV=.. configuration in the docker-compose.X.yml files, I think that's slightly cleaner
This reverts commit 6b4601e. @mattwr18 for reasons I don't understand, our build server hangs https://travis-ci.com/Human-Connection/Nitro-Web/builds/96979338 Honestly, I start to think this is a bug in `docker-compose`
@mattwr18 I'm done, I believe this is a bug with |
Wow!! what happened!? I thought it was around 315MB, still an big improvement, but nothing the 114MB!!! |
@mattwr18 I assume it comes from the |
Did you have a look at the links I shared with you here about the use of |
…eo4j Import remote mongodb in neo4j
fixes #93