Reputation: 101
So, I'm in a bit of a particular situation and i'm trying to find a clean solution.
Currently we've got 18 different repos, all with python deployment utilities copy and pasted 18 times with venv... to me this is disgusting.
I'd like to bake those utilities into some kind of "tools" docker image, and just execute them wherever i need, instead of having to have each folder install all the dependencies 18 times.
/devtools/venv
/user-service/code
/data-service/code
/proxy-service/code
/admin-service/code
Ultimately I'd like to CD into user-service, and run a command similar to docker run tools version_update.py
-- and have the docker image mount user-service's code and run the script against it.
How would I do this, and is there a better way i'm not seeing?
Upvotes: 0
Views: 191
Reputation: 77365
It would depend on your docker image, but here is the basic concept.
In your docker image, lets say we have a /code
directory where we will mount the source code that we want to do work on, and a /tools
directory with all of our scripts.
We can then mount what ever directory we want into the /code
directory in the docker image and run what ever script we want. The working directory inside of the container would be set to /code
and the path would also have /tools
in it. So using your example, the docker run commands would look like this.
docker run -v /user-service/code:/code tools version_update.py
This would run the tools
docker image, mount the local /user-service/code
directory to /code
directory in the container, and then run the version_update.py
script on that code. and then exit.
The same image can be used for all the other projects as well, just change the mount point. (assuming they all have the same structure)
docker run -v /data-service/code:/code tools version_update.py
docker run -v /proxy-service/code:/code tools version_update.py
docker run -v /admin-service/code:/code tools version_update.py
And if you want to run a different tool, just change the command that you pass in.
docker run -v /user-service/code:/code tools other_command.py
Upvotes: 0
Reputation: 404
Why use docker?
I would recommend placing your scripts into a "tools" directory alongside your services (or wherever you see fit), then you can cd into one of your service directories and run python ../tools/version_update.py
.
Upvotes: 1