8

I am building an app that has a couple different services. I am using docker and docker-compose to build all of the services. However there is some code I need to share between the services, specifically the ORM code. My issue is that when I try to call git submodule update --init I get the following error:

Step 6/8 : RUN git submodule update --init
 ---> Running in 88e2dcfa5b36
fatal: Not a git repository: ../.git/modules/my-repo
ERROR: Service 'my-repo' failed to build: The command '/bin/sh -c git submodule update --init' returned a non-zero code: 128

I'm not sure why it's looking in ../ for the .git directory. I'm pretty sure I set the WORKDIR correctly. Here is my whole Dockerfile

FROM node
WORKDIR /usr/src/my-repo
COPY package*.json ./
RUN npm install
COPY . .
RUN git submodule update --init
RUN git submodule foreach npm install
CMD ["npm", "start"]

Also as a side note - the submodule is a private repository how would I clone it using SSH? Do I have to set up docker with my ssh key or something? Thanks.

Edit: Also each of the services is a submodule of the parent project. I think that may be why git is looking in ../git/modules/my-repo but I'm not really sure how to get around this. My directory structure is like so:

parent-repo
--service-1
----orm
--service-2
----orm
SiHa
  • 7,830
  • 13
  • 34
  • 43
Max Paymar
  • 588
  • 1
  • 7
  • 23

1 Answers1

9

To summarize:

  • You have one directory that handles the orchestration
  • Inside that directory, you have multiple projects, that contain a node application
  • Each node application has the same dependecy for an orm lib

I had a similar setup that did not use submodules. This is just a suggestion, but it worked very well for a team with about twenty developers. You can modify your current setup with these steps:

  • Keep the orchestration directory
  • Remove all submodules from that directory
  • Now clone each service inside the orchestration dir as a normal git repo. Add each directory to the .gitignore file of the parent project.
  • Create a Dockerfile in each sub project to build a container for just that service.
  • In the parent dir, create an entry for each project in the docker-compose file

Now you have a structure like this

- orchestration/
  - .git/
  - .gitignore
  - docker-compose.yaml
  - service1/
    - .git/
    - Dockerfile
    - package.json
    - ...
  - service2/
    - .git/
    - Dockerfile
    - package.json
    - ...
  - service3/
    - .git/
    - Dockerfile
    - package.json
    - ...

Your docker-compose.yaml looks like this:

version: '3'

services:
  service1:
    build: ./service1
  service2:
    build: ./service2
  service3:
    build: ./service3

To provide the orm code to each service:

When you now call docker-compose up docker compose should build each project and start it up. If any service needs to access another service, the url to that service is just the name provided in the docker-compose file. E.g. service1 wants to access service2 then the url is http://serive1/path

You do not have to start all services, you can start them as you like, e.g. docker-compose up service1 service3.

To rebuild a service (e.g. when the code changed) call: docker-compose restart service1

mbuechmann
  • 5,413
  • 5
  • 27
  • 40