consoleme icon indicating copy to clipboard operation
consoleme copied to clipboard

chore: use multi-stage build

Open pedrokiefer opened this issue 2 years ago • 7 comments

Added multi-stage build, generated image went from 2.83GB to 725MB. I haven't made extended tests to this, but it seems to be working just fine.

Closes #9038

pedrokiefer avatar Jul 12 '21 19:07 pedrokiefer

hmm... right, I used yarn in one of the stages, so it only builds the production version of the UI and that gets copied to the final image. So for developing inside a container we need a full image, node_modules included. Maybe splitting in two Dockerfiles, one for dev (full image with its 2-point-something GB) another for production (prebuilt UI, minimal pythons deps)?

Will look into the issue with cryptography module.

pedrokiefer avatar Aug 02 '21 20:08 pedrokiefer

@pedrokiefer Would one of the intermediate images be usable as the development image? It would be nice to avoid separate Dockerfiles if we can.

patricksanders avatar Aug 02 '21 23:08 patricksanders

@pedrokiefer Would one of the intermediate images be usable as the development image? It would be nice to avoid separate Dockerfiles if we can.

Not really, but I think it can be done with an env var ENVIRONMENT. And change the docker-compose to pass this argument:

build:
  context: .
  args:
    - ENVIRONMENT=dev

Would that works for you?

pedrokiefer avatar Aug 03 '21 13:08 pedrokiefer

Found the issue with cryptography, it's only listed in requirements-test.txt and it wasn't being installed. It probably should be on requirements.txt too.

pedrokiefer avatar Aug 03 '21 15:08 pedrokiefer

I just did a little experimenting and I think this will get us both development and release images from one Dockerfile:

In Dockerfile, add another intermediate stage called development (before the final stage) and move the conditional installs to it:

FROM python-builder as development

RUN pip install -r requirements-test.txt
RUN pip install watchdog argh
# Plus whatever we need to make sure Yarn and all the other UI stuff is available

Update docker-compose stanza for the consoleme service:

services:
  consoleme:
    build:
      context: .
      args:
        target: development

With this pattern, a docker build . command will still produce the release image as well as being able to run docker build --target development . to get the heavier image to run for dev.

patricksanders avatar Aug 03 '21 17:08 patricksanders

@patricksanders used your suggestion, it seems to be working and it's easier to maintain -- I was not happy with all the if's.

Do we need git installed? I got a warning while testing.

pedrokiefer avatar Aug 03 '21 19:08 pedrokiefer

Nice, the Dockerfile and compose changes look good.

I don't think git is a hard requirement. There is some self service wizard functionality that CAN use git, but that's currently a pretty specific use case for Netflix.

patricksanders avatar Aug 03 '21 19:08 patricksanders