get prod dockerfile working properly#10790
Conversation
dockerfiles/idp_prod.Dockerfile
Outdated
| COPY .ruby-version $RAILS_ROOT/.ruby-version | ||
| COPY Gemfile $RAILS_ROOT/Gemfile | ||
| COPY Gemfile.lock $RAILS_ROOT/Gemfile.lock | ||
| COPY package.json $RAILS_ROOT/package.json |
There was a problem hiding this comment.
We probably want to keep the ordering here for the same reasons discussed in https://gitlab.login.gov/lg/identity-dashboard/-/merge_requests/42
There was a problem hiding this comment.
On this one, I'm going to stand firm, because this is not inline with development, but is aimed at production, and thus the image size reduction is important.
There was a problem hiding this comment.
Yeah, I wholeheartedly agree that the slimmer image is worthwhile, but we should probably do a multi-stage build since it allows us to maximize the benefits of both caching and smaller builds. The size difference doesn't seem that significant at this point (~5-6%) for a potentially significant increase in build times.
Is it possible to try a multi-stage build?
There was a problem hiding this comment.
I don't believe the build time is relevant here, though. It takes 8 minutes to build the prod image. 6 minutes to build the regular image. The overall pipeline with tests takes 16 minutes because of tests. The image builds are started at the start of the pipeline, and nothing depends on the prod image, so nothing has to wait for it to complete before it can run, and they run in parallel in a different runner pool, so don't even take up any test slots.
I will dig into the multi-stage builds to see if there's a better way to do it than when I last looked at this, but again, I think that this is not really needed.
There was a problem hiding this comment.
How's that? I added a multi-stage build for you! :-)
dockerfiles/idp_prod.Dockerfile
Outdated
| # yarn install | ||
| COPY package.json $RAILS_ROOT/package.json | ||
| COPY yarn.lock $RAILS_ROOT/yarn.lock | ||
| RUN yarn install --production=true --frozen-lockfile --cache-folder .yarn-cache |
There was a problem hiding this comment.
| RUN yarn install --production=true --frozen-lockfile --cache-folder .yarn-cache |
There was a problem hiding this comment.
Don't you want a yarn install? This command adds 408MB to the image, so it's doing something.
There was a problem hiding this comment.
Probably mostly a bunch of node_modules which we could copy to avoid installing twice.
There was a problem hiding this comment.
Though if we copy the compiled assets, we don't need to do that either.
dockerfiles/idp_prod.Dockerfile
Outdated
| COPY config/service_providers.localdev.yml $RAILS_ROOT/config/service_providers.yml | ||
|
|
||
| # Precompile assets | ||
| RUN apt-get install -y make |
There was a problem hiding this comment.
can we move this up into the big install block?
We could also move asset compilation into the build stage as well and not install any yarn/javascript I think.
There was a problem hiding this comment.
We can, though it won't make any significant difference.
I didn't move the asset compilation up, because I don't know where all the assets get put. It looked like there were a lot of assets directories in there. Is there a single one that I can copy back over?
There was a problem hiding this comment.
I think it should just be the public/ folder
|
@mitchellhenke , I rearranged stuff a bit so that almost everything is built in the builder, and then everything in the app dir is copied over. The image is about 1gb smaller in size now. Fun! The image is running over in https://idp.tstest.identitysandbox.gov/ Let me know what you think. |
|
@mitchellhenke , any reason why we can't get this approved? |
|
@mitchellhenke OK. I think it's ready for review again at last. :-) |
3654d4c to
2acd1c2
Compare
… to actually work
remove extra commands because mitchell doesn't like them Co-authored-by: Mitchell Henke <mitchell.henke@gsa.gov>
… not the image we were building
cf09d92 to
363535f
Compare
🛠 Summary of changes
This image is running on https://idp.tstest.identitysandbox.gov/