简体   繁体   中英

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

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM