Skip to content

get prod dockerfile working properly#10790

Merged
timothy-spencer merged 44 commits intomainfrom
tspencer/update_prod_dockerfile
Aug 1, 2024
Merged

get prod dockerfile working properly#10790
timothy-spencer merged 44 commits intomainfrom
tspencer/update_prod_dockerfile

Conversation

@timothy-spencer
Copy link
Contributor

@timothy-spencer timothy-spencer commented Jun 10, 2024

🛠 Summary of changes

  • Ensure that image is mostly read-only to the app user
  • make sure keys are readable by the app user
  • Make it so that build-essentials is not installed (smaller image, less tooling for attackers to work with)
  • Make sure puma knows what xff header to use
  • Ensure that service_providers.yml and related files are copied into the image

This image is running on https://idp.tstest.identitysandbox.gov/

@timothy-spencer timothy-spencer changed the title WIP: get prod dockerfile working properly get prod dockerfile working properly Jun 18, 2024
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably want to keep the ordering here for the same reasons discussed in https://gitlab.login.gov/lg/identity-dashboard/-/merge_requests/42

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How's that? I added a multi-stage build for you! :-)

# 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
RUN yarn install --production=true --frozen-lockfile --cache-folder .yarn-cache

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you want a yarn install? This command adds 408MB to the image, so it's doing something.

Copy link
Contributor

@mitchellhenke mitchellhenke Jun 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably mostly a bunch of node_modules which we could copy to avoid installing twice.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though if we copy the compiled assets, we don't need to do that either.

COPY config/service_providers.localdev.yml $RAILS_ROOT/config/service_providers.yml

# Precompile assets
RUN apt-get install -y make
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should just be the public/ folder

@timothy-spencer
Copy link
Contributor Author

timothy-spencer commented Jun 27, 2024

@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.

@timothy-spencer
Copy link
Contributor Author

@mitchellhenke , any reason why we can't get this approved?

@timothy-spencer
Copy link
Contributor Author

@mitchellhenke OK. I think it's ready for review again at last. :-)

@mitchellhenke mitchellhenke force-pushed the tspencer/update_prod_dockerfile branch from 3654d4c to 2acd1c2 Compare July 24, 2024 17:03
@mitchellhenke mitchellhenke force-pushed the tspencer/update_prod_dockerfile branch from cf09d92 to 363535f Compare August 1, 2024 15:43
@timothy-spencer timothy-spencer merged commit 9365c40 into main Aug 1, 2024
@timothy-spencer timothy-spencer deleted the tspencer/update_prod_dockerfile branch August 1, 2024 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants