shy-match-55049
06/29/2021, 11:02 PMPython + Docker + GCP
Monorepo architecture!? Curious to see how others have done this 🙂ambitious-actor-36781
06/29/2021, 11:29 PMhappy-kitchen-89482
06/29/2021, 11:35 PMhappy-kitchen-89482
06/29/2021, 11:35 PMshy-match-55049
06/29/2021, 11:39 PMmonorepo/services/python/service1
monorepo/services/python/service2
monorepo/services/python/service3
monorepo/services/python/service4
monorepo/services/python/service5
Each with independent requirements, maybe some shared code (like a database client class, how would that work, where would it live, etc...)
Lastly, I'd like to write tests, and dockerize them, and run a docker compose at the top level to spin up all services at once.
I think if an example repo is there that achieves those goals, or at least shows the file structure, that would be a HUGE win for any new developer using pants!witty-crayon-22786
06/29/2021, 11:42 PMwitty-crayon-22786
06/29/2021, 11:44 PMshy-match-55049
06/29/2021, 11:44 PMwitty-crayon-22786
06/29/2021, 11:50 PMwitty-crayon-22786
06/29/2021, 11:50 PMpex_binary
shy-match-55049
06/29/2021, 11:51 PMwitty-crayon-22786
06/29/2021, 11:51 PMsrc/<lang>
pattern is the src
token, which you don’t have in your example abovehappy-kitchen-89482
06/29/2021, 11:52 PMsrc/python
if you think you might have other languages in the future, or just src/
or even the repo root itself if not). Then you can have all the code live under <srcroot>/myrootpkg/
with shared code in, say, <srcroot>/myrootpkg/util
, <srcroot>/myrootpkg/db
and so on.happy-kitchen-89482
06/29/2021, 11:53 PM<srcroot>/myrootpkg/service1
, ``<srcroot>/myrootpkg/service2` etchappy-kitchen-89482
06/29/2021, 11:53 PMhappy-kitchen-89482
06/29/2021, 11:53 PMhappy-kitchen-89482
06/29/2021, 11:54 PM<srcroot>/myrootpkg/util/foo_test.py
next to <srcroot>/myrootpkg/util/foo.py
and so onhappy-kitchen-89482
06/29/2021, 11:54 PMshy-match-55049
06/29/2021, 11:54 PMshy-match-55049
06/29/2021, 11:54 PMhappy-kitchen-89482
06/29/2021, 11:54 PMshy-match-55049
06/29/2021, 11:55 PMshy-match-55049
06/29/2021, 11:55 PMhappy-kitchen-89482
06/29/2021, 11:55 PMhappy-kitchen-89482
06/29/2021, 11:55 PMhappy-kitchen-89482
06/29/2021, 11:56 PMsrc/<lang>
is a source root, just as a convention. You can omit the src/
part but then you have to manually tell Pants about the source root.happy-kitchen-89482
06/29/2021, 11:57 PMrequirements.txt
for the repo, since Pants knows how to take just the subset of deps you actually need for a given binaryhappy-kitchen-89482
06/29/2021, 11:57 PMshy-match-55049
06/29/2021, 11:57 PMhappy-kitchen-89482
06/29/2021, 11:57 PMrequirements.txt
represents the universe from which dependencies are chosen as needed, but only the actually needed ones are used.happy-kitchen-89482
06/29/2021, 11:57 PMshy-match-55049
06/29/2021, 11:58 PMhappy-kitchen-89482
06/29/2021, 11:58 PMrequirements.txt
, even conflicting oneshappy-kitchen-89482
06/29/2021, 11:58 PMshy-match-55049
06/29/2021, 11:59 PMambitious-actor-36781
06/30/2021, 12:00 AM.pex
file, and then you bung that in a dockerfile with ENTRYPOINT [foo.pex]
witty-crayon-22786
06/30/2021, 12:00 AMshy-match-55049
06/30/2021, 12:01 AMambitious-actor-36781
06/30/2021, 12:01 AMFROM python:3.8
COPY artifact.pex /bin
ENTRYPOINT ['artifact.pex']
RUN ['--run-stuff']
witty-crayon-22786
06/30/2021, 12:02 AMshy-match-55049
06/30/2021, 12:07 AMmonorepo/services/python/service1/Dockerfile
monorepo/services/python/service2/Dockerfile
monorepo/services/python/service3/Dockerfile
monorepo/services/python/service4/Dockerfile
monorepo/3rdparty/python/requirements.txt
Would each of those Dockerfile
's just be
FROM python:3.9.6-slim
COPY service{n}.pex /bin
ENTRYPOINT ['service{n}.pex']
RUN ['--run-stuff']
witty-crayon-22786
06/30/2021, 12:07 AMshy-match-55049
06/30/2021, 12:08 AMambitious-actor-36781
06/30/2021, 12:17 AMpants containers
and runs docker build
ambitious-actor-36781
06/30/2021, 12:19 AMpants publish-packages
run twine)witty-crayon-22786
06/30/2021, 12:20 AMambitious-actor-36781
06/30/2021, 12:25 AMpants package
to a repository (currently working on this)
2. A way to build pants targets into a docker image (e.g. docker_image(name='a_service', dockerfile='src/python/a_service/Dockerfile', dependencies=[':a_service_binary'])
)
3. (?) take output of #2 and run it through #1 so it pushes the images to a container registry.witty-crayon-22786
06/30/2021, 12:26 AMwitty-crayon-22786
06/30/2021, 12:28 AMpex
construction) might need to take place inside the docker container.witty-crayon-22786
06/30/2021, 12:28 AMwitty-crayon-22786
06/30/2021, 12:29 AMambitious-actor-36781
06/30/2021, 12:29 AMpants
image on the Docker registry, and you can just do your entire build inside there"witty-crayon-22786
06/30/2021, 12:30 AMwitty-crayon-22786
06/30/2021, 12:31 AMshy-match-55049
06/30/2021, 2:20 AMshy-match-55049
06/30/2021, 2:20 AMambitious-actor-36781
06/30/2021, 2:24 AMhappy-kitchen-89482
06/30/2021, 4:47 AMhappy-kitchen-89482
06/30/2021, 4:47 AMclean-night-52582
06/30/2021, 7:06 AMwitty-crayon-22786
06/30/2021, 3:58 PM