Home > Mobile >  How to install python package into a docker service inside of a monorepo
How to install python package into a docker service inside of a monorepo

Time:10-19

I have a monorepo setup such as the following:

/serviceA
/serviceB
/packageA
/packageB

I would like to install packageA inside of serviceA, which is docker container with a python service inside.

Inside of my serviceA requirements.txt file I can reference the local package: file:///Users/me/dev/platform/packageA, this fails when submitting to gcloud builds as the package is not on that machine.

My question is, what are my options here and am I going about this setup the correct/best way?

My thinking is that I could try and copy the code into the docker, but this seems a little hacky - as I am not sure where the version would go..

The other option is to push to GH first and reference from there, but this would mean I need to somehow grant access to the repo to cloud build.

CodePudding user response:

You can use Docker multi stage build strategy:

FROM base as package-builder
COPY your_package_A_code
RUN your_package_build_stuff

FROM base
COPY --from=package-builder /path/builded/package_A /path/to/package_A

This way you don't expose the code of your package A inside the service A. Then, reference your package_A where you decide to store (in my example:/path/to/package_A) in your requirements.txt.

  • Related