CI/CD tool to merge multiple docker-compose files
Go to file
2023-07-26 09:11:31 +02:00
cmd fix(ci): Makefile, Containerfile 2023-07-26 09:11:31 +02:00
pkg fix(ci): Makefile, Containerfile 2023-07-26 09:11:31 +02:00
.containerignore fix(ci): Makefile, Containerfile 2023-07-26 09:11:31 +02:00
.gitignore fix(ci): Makefile, Containerfile 2023-07-26 09:11:31 +02:00
Containerfile fix(ci): Makefile, Containerfile 2023-07-26 09:11:31 +02:00
go.mod fix(ci): Makefile, Containerfile 2023-07-26 09:11:31 +02:00
go.sum fix(ci): Makefile, Containerfile 2023-07-26 09:11:31 +02:00
LICENSE add: MIT License 2023-07-19 21:47:47 +02:00
main.go fix(ci): Makefile, Containerfile 2023-07-26 09:11:31 +02:00
Makefile fix(ci): Makefile, Containerfile 2023-07-26 09:11:31 +02:00
README.md fix(ci): Makefile, Containerfile 2023-07-26 09:11:31 +02:00

dcmerge

dcmerge is a small program to merge docker-compose files from multiple sources. The following source are currently supported:

  • File
  • HTTP/HTTPS

Furthermore, dcmerge support different ways to merge multiple docker-compose files.

  • The default merge, add missing secrets, services, networks and volumes.
  • The existing-win merge, add and protect existing attributes.
  • The last-win merge, add or overwrite existing attributes.

default

Merge only missing secrets, services, networks and volumes without respecting their attributes. For example, when the service app is already declared, it is not possible to add the service app twice. The second service will be completely skipped.

---
# cat ~/docker-compose-A.yaml
services:
  app:
    environments:
    - CLIENT_SECRET=HelloWorld123
    image: example.local/app/name:0.1.0
---
# cat ~/docker-compose-B.yaml
services:
  app:
    image: app/name:2.3.0
    volume:
    - /etc/localtime:/etc/localtime
    - /dev/urandom:/etc/urandom
  db:
    image: postgres
    volume:
    - /etc/localtime:/etc/localtime
    - /dev/urandom:/etc/urandom
---
# dcmerge ~/docker-compose-A.yaml ~/docker-compose-B.yaml
services:
  app:
    environments:
    - CLIENT_SECRET=HelloWorld123
    image: example.local/app/name:0.1.0
  db:
    image: postgres
    volume:
    - /etc/localtime:/etc/localtime
    - /dev/urandom:/etc/urandom

existing-win

The existing-win merge protects existing attributes. For example there are two different docker-compose files, but booth has the same environment variable CLIENT_SECRET defined with different values. The first declaration of the attribute wins and is for overwriting protected.

---
# cat ~/docker-compose-A.yaml
services:
  app:
    environments:
    - CLIENT_SECRET=HelloWorld123
    image: example.local/app/name:0.1.0
---
# cat ~/docker-compose-B.yaml
services:
  app:
    environments:
    - CLIENT_SECRET=FooBar123
    image: example.local/app/name:0.1.0
---
# dcmerge --existing-win ~/docker-compose-A.yaml ~/docker-compose-B.yaml
services:
  app:
    environments:
    - CLIENT_SECRET=HelloWorld123
    image: example.local/app/name:0.1.0

last-win

The last-win merge overwrite recursive existing attributes. For example there are two different docker-compose files, but booth has the same environment variable CLIENT_SECRET defined with different values. The last passed docker-compose file which contains this environment wins.

---
# cat ~/docker-compose-A.yaml
services:
  app:
    environments:
    - CLIENT_SECRET=HelloWorld123
    image: example.local/app/name:0.1.0
---
# cat ~/docker-compose-B.yaml
services:
  app:
    environments:
    - CLIENT_SECRET=FooBar123
    image: example.local/app/name:0.1.0
---
# dcmerge --last-win ~/docker-compose-A.yaml ~/docker-compose-B.yaml
services:
  app:
    environments:
    - CLIENT_SECRET=FooBar123
    image: example.local/app/name:0.1.0