Skip to content

Commit

Permalink
Generate docker-compose.yaml entirely
Browse files Browse the repository at this point in the history
  • Loading branch information
vladbogo authored and fauust committed Aug 10, 2023
1 parent ed37635 commit c1647db
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 59 deletions.
43 changes: 2 additions & 41 deletions docker-compose/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# This is an autogenerated file. Do not edit it manually. Use `python generate-config.py` instead.
---
version: "3.7"
services:
Expand Down Expand Up @@ -204,46 +205,6 @@ services:
- mariadb
- crossbar

# master-libvirt:
# image: quay.io/mariadb-foundation/bb-master:master
# restart: unless-stopped
# container_name: master-libvirt
# volumes:
# - ./logs:/var/log/buildbot
# - ./buildbot/:/srv/buildbot/master
# entrypoint:
# - /bin/bash
# - -c
# - "/srv/buildbot/master/docker-compose/start.sh master-libvirt"
# networks:
# net_front:
# net_back:
# ports:
# - "127.0.0.1:8019:8019"
# depends_on:
# - mariadb
# - crossbar

# master-nonlatent:
# image: quay.io/mariadb-foundation/bb-master:master
# restart: unless-stopped
# container_name: master-nonlatent
# volumes:
# - ./logs:/var/log/buildbot
# - ./buildbot/:/srv/buildbot/master
# entrypoint:
# - /bin/bash
# - -c
# - "/srv/buildbot/master/docker-compose/start.sh master-nonlatent"
# networks:
# net_front:
# net_back:
# ports:
# - "127.0.0.1:8020:8020"
# depends_on:
# - mariadb
# - crossbar

master-protected-branches:
image: quay.io/mariadb-foundation/bb-master:master
restart: unless-stopped
Expand All @@ -259,7 +220,7 @@ services:
net_front:
net_back:
ports:
- "127.0.0.1:8021:8021"
- "127.0.0.1:8019:8019"
depends_on:
- mariadb
- crossbar
Expand Down
109 changes: 91 additions & 18 deletions docker-compose/generate-config.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/usr/bin/env python

# TODO vlad:
# - generate directly into docker-compose.yaml file
# - generate only 1 blank lines between block (not 2)

master_directories = [
"autogen/aarch64-master-0",
"autogen/amd64-master-0",
Expand All @@ -13,11 +9,60 @@
"autogen/x86-master-0",
"master-docker-nonstandard",
"master-galera",
"master-libvirt",
"master-nonlatent",
# TODO Enable these once it's more clear what needs to be done
# "master-libvirt",
# "master-nonlatent",
"master-protected-branches",
]

start_template = """
---
version: "3.7"
services:
mariadb:
image: mariadb:10.6
restart: unless-stopped
container_name: mariadb
environment:
- MARIADB_ROOT_PASSWORD=password
- MARIADB_DATABASE=buildbot
- MARIADB_USER=buildmaster
- MARIADB_PASSWORD=password
networks:
net_back:
healthcheck:
test: ['CMD', "mariadb-admin", "--password=password", "--protocol", "tcp", "ping"]
volumes:
- ./db:/docker-entrypoint-initdb.d:ro
- ./mariadb:/var/lib/mysql:rw
# command: --tmpdir=/var/lib/mysql/tmp
crossbar:
image: crossbario/crossbar
restart: unless-stopped
container_name: crossbar
networks:
net_back:
master-web:
image: quay.io/mariadb-foundation/bb-master:master-web
restart: unless-stopped
container_name: master-web
volumes:
- ./logs:/var/log/buildbot
- ./buildbot/:/srv/buildbot/master
entrypoint:
- /srv/buildbot/master/docker-compose/start-bbm-web.sh
networks:
net_front:
net_back:
ports:
- "127.0.0.1:8010:8010"
depends_on:
- mariadb
- crossbar
"""

docker_compose_template = """
{master_name}:
image: quay.io/mariadb-foundation/bb-master:master
Expand All @@ -40,16 +85,44 @@
- crossbar
"""

end_template = """
networks:
net_front:
driver: bridge
ipam:
driver: default
config:
- subnet: 172.200.0.0/24
driver_opts:
com.docker.network.enable_ipv6: "false"
com.docker.network.bridge.name: "br_bb_front"
net_back:
driver: bridge
internal: true
ipam:
driver: default
config:
- subnet: 172.16.201.0/24
driver_opts:
com.docker.network.enable_ipv6: "false"
com.docker.network.bridge.name: "br_bb_back"
"""

# Generate startup scripts and Docker Compose pieces for each master directory
port = 8011
for master_directory in master_directories:
master_name = master_directory.replace("/", "_")

# Generate Docker Compose piece
docker_compose_piece = docker_compose_template.format(
master_name=master_name,
master_directory=master_directory,
port=port,
)
port += 1
print(docker_compose_piece)
with open("docker-compose.yaml", "w") as f:
f.write("# This is an autogenerated file. Do not edit it manually. Use `python generate-config.py` instead.")
f.write(start_template)
port = 8011
for master_directory in master_directories:
master_name = master_directory.replace("/", "_")

# Generate Docker Compose piece
docker_compose_piece = docker_compose_template.format(
master_name=master_name,
master_directory=master_directory,
port=port,
)
port += 1

f.write(docker_compose_piece)
f.write(end_template)

0 comments on commit c1647db

Please sign in to comment.