1

I have 2 services in one git repository written in the python and deployed to the containers with docker-compose and docker. And I wanted to add some authorization with the third party OpenID Connect service. I have written a module to deal with authorization and I desire to use it in every service. My repository looks like this:

services:
    first_service:
        Dockerfile
        docker-compose.yml
        first_service_python_module
    second_service:
        Dockerfile
        docker-compose.yml
        second_service_python_module
    docker-compose.yml
    .git

Initially, I wanted my authorization module to be in the 'services' folder but this way I cannot build my Docker images because Docker can't deal with the outer folder without special argument. But I cannot specify this argument because of docker-compose files. So I ended up with the next repository structure:

services:
    first_service:
        Dockerfile
        docker-compose.yml
        first_service_python_module
        authorization_module
    second_service:
        Dockerfile
        docker-compose.yml
        second_service_python_module
        authorization_module
    docker-compose.yml
    .git

Obviously there is a lot of code duplication and it's hard to maintain.

I want to avoid code duplication. But also not to change docker and docker-compose files a lot. How can I do it?

Valerii Boldakov
  • 1,751
  • 9
  • 19
  • 1
    Would https://stackoverflow.com/a/53298876/6309 help? – VonC Oct 08 '19 at 04:34
  • @VonC, it totally resolves my issue. Thank you for your help! What will be the right action for me considering my question? Should I remove it somehow? Mark as duplicate? Or answer it myself with your link? – Valerii Boldakov Oct 08 '19 at 08:03
  • You can close it as duplicate, unless you can write an answer below which *builds* upon that other answer and provide an addition specific to your use case. – VonC Oct 08 '19 at 08:06

1 Answers1

0
services:
    first_service:
        Dockerfile
        docker-compose.yml
        first_service_python_module
    second_service:
        Dockerfile
        docker-compose.yml
        second_service_python_module
    service_authorization:
        authorization_module
    docker-compose.yml
    .git

So what you can do is, you can relatively import this authorization_module in your other python modules/services.

refer this https://www.python.org/dev/peps/pep-0328/

Mandar Autade
  • 336
  • 2
  • 12
  • Thank you for your answer! Sorrowfully it won't solve my issue, because I'm not able to access 'service_authorization' from the container created from current Dockerfiles. And also I won't be able to copy the 'service_authorization' folder from the current context. – Valerii Boldakov Oct 08 '19 at 08:07
  • can you run this authorization_module as a service in a different docker file ? – Mandar Autade Oct 08 '19 at 08:12
  • I want to avoid it as much as possible. I think I will follow the answer from @VonC answer in comments to question. – Valerii Boldakov Oct 08 '19 at 08:31