Context: I’m developing my first microservice project, and still trying to wrap my head around some best practices.
The project structure is not that complicated:
DaProject/
+- ServiceA/
| +- main.py
| - Dockerfile
+- ServiceB/
| +- some_ServiceB_specific_lib/
| +- main.py
| - Dockerfile
- docker-compose.yml
Now, as I played around with implementing a couple of services, I’ve figured out some of the cross-cutting concerns for my project. Since all services will be implemented in Python, I want to take care of those concerns using Service Chassis pattern.
The question is, is there a simple, but decent way to do that?
For example, if I do this:
DaProject/
+- Chassis/
| - __init__.py
+- ServiceA/
| +- main.py
| - Dockerfile
+- ServiceB/
| +- some_ServiceB_specific_lib/
| +- main.py
| - Dockerfile
- docker-compose.yml
then I will need to reference the Chassis
package from within the services.
What I have thought about:
- I can’t just reference
../Chassis
in anyDockerfile
, as it is outside of the build scope. Okay, that makes sense. - I don’t want to manually copy the chassis into each service directory whenever I happen to update it. It’s a very simple solution, but high-maintenance and error-prone.
- Hardlinking the directory is a hack, and will likely break if the code is moved somewhere else.
- Implementing a local pypi repo sounds like a high-maintenance way to handle it. Perhaps it would be more worth it I was implementing a more abstract and reusable library, not something as project-bound as this.
- Googling pointed me towards ‘git submodule’ concept… but I have only basic familiarity with Git, and so I can’t really judge how complex this solution is.
Is there any other way I’m not aware of? Or should I bite the bullet and learn the submodule feature?