Page MenuHomePhabricator

[Identity] Avoid secret generation and slim down size of identity server docker image
ClosedPublic

Authored by jon on Jul 19 2023, 7:05 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, May 25, 6:44 PM
Unknown Object (File)
Tue, May 7, 1:54 AM
Unknown Object (File)
Sun, May 5, 2:45 PM
Unknown Object (File)
Sat, May 4, 3:08 PM
Unknown Object (File)
Sat, May 4, 3:08 PM
Unknown Object (File)
Sat, May 4, 3:08 PM
Unknown Object (File)
Sat, May 4, 3:06 PM
Unknown Object (File)
Sat, May 4, 2:38 PM
Subscribers

Details

Summary

Secrets should not be generated as part of the docker image build. Instead, they need to be mounted in to the container.

Also reduces the image size from 1.81GB to 108MB.

https://linear.app/comm/issue/ENG-4419

Test Plan
docker build -f services/identity/Dockerfile .
# or
cd services
docker compose build identity

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

Nice! I was recently trying something similar for blob service dockerfile, but I could only get down to ~600MB in the runner stage, so 108MB is impressive. (I used a different base image for the runner stage, rust-slim is 250MB already)


Secrets should not be generated as part of the docker image build. Instead, they need to be mounted in to the container.

Shouldn't the volume mapping be added to the docker-compose file? IIRC @varun uses it for deployment.

services/identity/Dockerfile
31–34 ↗(On Diff #28875)

Why are you setting WORKDIR to some unused directory while copying the executable to /usr/local/bin? It doesn't matter much because it's in the PATH but curious about your motivation

services/identity/Dockerfile
21 ↗(On Diff #28875)

I think you should add the --locked flag because cargo install seems to ignore Cargo.lock by default: https://doc.rust-lang.org/cargo/commands/cargo-install.html#dealing-with-the-lockfile

Also tip: With the --root flag you can possibly change installation path from /usr/local/cargo/bin to another dir

services/identity/Dockerfile
28–29 ↗(On Diff #28875)
  1. Doesn't WORKDIR /home/comm/app/identity already create the directory? (docs link)
  2. Shouldn't you switch users with the USER comm instruction? Without this, you're still running as root
varun requested changes to this revision.Jul 23 2023, 8:07 AM

same questions as @bartek

This revision now requires changes to proceed.Jul 23 2023, 8:07 AM
jon marked 3 inline comments as done.

Address feedback

services/identity/Dockerfile
21 ↗(On Diff #28875)

I think you should add the --locked

Ah, didn't realize, thanks.

Also tip: With the --root flag you can possibly change installation path

This just needs to match the COPY --from=builder line. I don't have a strong preference.

28–29 ↗(On Diff #28875)

Doesn't WORKDIR /home/comm/app/identity already create the directory? (docs link)

Apparently it does. just used to the bash-ism of mkdir -p before using a directory

Shouldn't you switch users with the USER comm instruction? Without this, you're still running as root

I should, looks like I forgot to carry this over

31–34 ↗(On Diff #28875)

Why are you setting WORKDIR to some unused directory

For consistency with the builder + legacy behavior. Although /home/comm would also work. Honestly didn't give this a lot of thought other than "do something is it's a strict improvement on the old"

It doesn't matter much because it's in the PATH

That was the goal, really dislike running relative command (e.g. ./target/...), as there's a implicit dependency on the current work directory.

Thanks for explanations!

services/identity/Dockerfile
21 ↗(On Diff #28875)

Also tip: With the --root flag you can possibly change installation path

This just needs to match the COPY --from=builder line. I don't have a strong preference.

Yeah, that was just a FYI comment, no preference either

This revision is now accepted and ready to land.Jul 25 2023, 12:34 PM