-1

I am working on a project which consists of docker-compose.yml file (with published public docker images) together with environment files.

Typically, a user would

  1. git clone the repo
  2. make the necessary changes to the environment files
  3. run docker-compose up
  4. Figure out whats wrong with his config changes. Go to step 2.
  5. Eventually be happy

As working with docker and changing variables for non-devs can be a bit tedious, I was wondering if its possible to wrap the entire repo in a python wheel/pip installable package to improve the UX by allowing the user to;

  1. pip install mypackage (which would also install docker-compose etc.)
  2. mypackage start --variant=two --path=/home/ (does the config changes automatically)
  3. Be happy

Is it possible to do something like this with python wheel or does it require some black magick and/or is this considered a safety risk/not recommended?

japrescott
  • 4,736
  • 3
  • 25
  • 37
  • 1
    You can make your package runnable like this by including a `__main__.py` script at the root level of the package. So something like `mypackage/__main__.py` that runs the changes you need – C.Nivs Jul 17 '23 at 13:29
  • That in principle should be possible. Note that it still requires giving the end user access to the Docker socket, which in turn implies unrestricted root-level access over the host system. If your application itself is written in Python and you're more comfortable with this ecosystem, also consider whether you can use a virtual environment instead of Docker here. – David Maze Jul 17 '23 at 15:00

1 Answers1

2

starting a service right out of the pip installation is dangerous

One thing is for you to install a package via pip, another is to invoke/run it, which by my opinion needs to happen separately by the intention of the User, not automatically (which would rarely be the case).

If you want to wrap this and use ONLY within your own environment, that is up to you, but overall this is a bad idea, although it seems as an improvement.

I would use a separate script to pull via pip, and then run whatever needs to run

Having said that, You should be able to accomplish the install land run with pip-run

Ron
  • 5,900
  • 2
  • 20
  • 30
  • Thanks @Ron! It was not my intention to directly start it with `pip install mypackage` but that the user later can start it themself with `mypackage --some=option`. Would that be considered safe? – japrescott Jul 17 '23 at 13:40
  • 1
    that would be way-safer, yes .. Maybe I got the question wrong? – Ron Jul 17 '23 at 13:42