1

I've found a few similar questions here on Stack Overflow, but nothing that exactly answers my question. The closest I've found is this: Two git repositories in one directory?

But that question is from '09, which is an aeon in terms of DevOps. So here goes.

I'm working on two projects from the same directory. One is a template for running a test environment out of Docker containers (we'll call it template). The other is the actual app I'm developing in this environment (call it project). The directory structure looks like this:

.
+--_ app
|  |-- some-file
|  +-- some-file2
+--_ somedir
|  +-- other-files
+--- Dockerfile
+--- docker-compose.yml

template needs to include all the files except app/*. project needs to include everything in app/* and Dockerfile. I can't put Dockerfile inside of app/ and then make an exception for it in .gitignore because then I wouldn't be able to initialize a project in app/ using laravel new or other commandline tools because they require an empty dir.

Meanwhile the Dockerfile needs to be included in the project repo because it's used for deployment of the project as well as testing.

So what would be the best approach for this situation?

Bintz
  • 784
  • 2
  • 9
  • 22

1 Answers1

0

I think I Kind of understand what you're trying to achieve - you have some application/service dependencies that you need to run while working on your app. I've approached it a bit differently than having 2 git repos in 1 dir (which TBH I'm not sure how that would work).

Let me explain how I've approached this. I can't say if what I'm doing is the best approach, but it does seems to work quite well.

Firstly we've got a 'Docker.Dependencies' repo that has all the core dependencies that we use (or at least locally equivalent dependencies e.g. the IDP we run in production can't be run locally, so I just use Keycloak locally instead). The 'Docker.Dependencies' repo has a directory structure as shown below. Note: this will be a git submodule in my microservice repos:

enter image description here

The sub-directories have Dockerfiles wherever I need to add something to the base official image e.g. for Logstash, I need to install some plugins copy some pipeline configurations.

There's also a bunch of yml files at the root level. These are all docker-compose files, which I can chain together if required i.e.

docker-compose -f database.yml -f security.yml -f logging.yml up --build

Now over to my microservice repos; which have a directory structure as follows:

enter image description here

As mentioned, the 'Docker.Dependencies' sub-dir is actually a git submodule.

I've created a few helper scripts including a PowerShell module (package-scripts.psm1) and a script to (re)install the module (init.ps1) as well as some NPM scripts (package.json) that call the PowerShell commands, so that I can very easily do things like:

  • npm run dependencies
  • npm run migrations as in database migraions
  • npm run services to run microservices in docker
  • etc.

enter image description here

^^ as you can see in the packages.json file above the PowerShell scripts are all paramatised, so I customise as required for a particular microservice repo. Note: These helper scripts could probably be in another git submodule (which is something I actually plan on doing). Also I chose PowerShell instead if bash because some of our developers use Windows for their development environment.

Under src is where the source code lives and this is also where I have the microservice Dockerfiles. As mentioned I can run my microservices using npm run services or I could just run them directly from my IDE of choice. There's a bit of config required (which is all part of the microservice template) as we need everything to 'just work' for different machine setups e.g. docker desktop on Windows, docker on Linux, docker-machine; running the microservice in a docker container vs. running on host machine...

The microservice Dockerfile are built and published to our docker registry in the CI/CD pipeline.

Ryan.Bartsch
  • 3,698
  • 1
  • 26
  • 52