CI/CD tool to merge multiple docker-compose files
Go to file
CSRBot a4612a3c04
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
chore(deps): update module gopkg.in/yaml.v2 to v3
2023-11-05 23:05:23 +00:00
cmd fix: rename firstWin to existingWin 2023-08-28 11:13:32 +02:00
pkg fix(dockerCompose): protect of empty attributes 2023-08-28 11:37:24 +02:00
test/assets test: add example docker-compose 2023-08-28 10:57:36 +02:00
.dockerignore Initial Commit 2023-07-26 09:57:40 +02:00
.drone.yml chore(deps): update docker.io/plugins/docker docker tag to v20.17.0 2023-10-30 23:05:33 +00:00
.gitignore Initial Commit 2023-07-26 09:57:40 +02:00
.markdownlint.yaml Initial Commit 2023-07-26 09:57:40 +02:00
Dockerfile chore(deps): update docker.io/library/golang docker tag to v1.21.3 2023-10-11 07:49:22 +02:00
go.mod chore(deps): update module gopkg.in/yaml.v2 to v3 2023-11-05 23:05:23 +00:00
go.sum chore(deps): update module github.com/spf13/cobra to v1.8.0 2023-11-05 23:24:28 +01:00
LICENSE Initial Commit 2023-07-26 09:57:40 +02:00
main.go Initial Commit 2023-07-26 09:57:40 +02:00
Makefile Initial Commit 2023-07-26 09:57:40 +02:00
manifest.tmpl fix(ci): unsupport arm v7 2023-10-30 21:32:36 +01:00
README.md style(README): add newline 2023-07-26 10:16:15 +02:00
renovate.json fix(ci): unsupport arm v7 2023-10-30 21:32:36 +01:00

dcmerge

Build Status Docker Pulls

dcmerge is a small program to merge docker-compose files from multiple sources. It is available via RPM and docker.

The dynamic pattern of a docker-compose file, that for example environments can be specified as a string slice or a list of objects is currently not supported. dcmerge expect a strict pattern layout. The environments, ports and volumes must be declared as a slice of strings.

Dockercompose file can be read-in from different sources. Currently are the following sources 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