Skip to content

Commit

Permalink
Use env vars to select between dev and prod
Browse files Browse the repository at this point in the history
  • Loading branch information
vladbogo committed Aug 10, 2023
1 parent a940034 commit 24f2475
Show file tree
Hide file tree
Showing 16 changed files with 175 additions and 85 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ venv
workers
autogen
master-config.yaml
.venv
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ RUN apt-get update \
python3-distutils \
python3-pip \
python3-venv \
python-dotenv \
&& if [ "$master_type" = "master-web" ]; then \
apt-get -y install --no-install-recommends \
libcairo2 \
Expand Down
4 changes: 4 additions & 0 deletions docker-compose/dev.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
TITLE="MariaDB CI"
TITLE_URL=https://github.com/MariaDB/server
BUILDMASTER_URL=https://buildbot.dev.mariadb.org/
MQ_ROUTER_URL=ws://crossbar:8085/ws
50 changes: 50 additions & 0 deletions docker-compose/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ services:
image: quay.io/mariadb-foundation/bb-master:master-web
restart: unless-stopped
container_name: master-web
environment:
- TITLE=MariaDB CI
- TITLE_URL=https://github.com/MariaDB/server
- BUILDMASTER_URL=https://buildbot.dev.mariadb.org/
- MQ_ROUTER_URL=ws://crossbar:8085/ws
volumes:
- ./logs:/var/log/buildbot
- ./buildbot/:/srv/buildbot/master
Expand All @@ -49,6 +54,11 @@ services:
image: quay.io/mariadb-foundation/bb-master:master
restart: unless-stopped
container_name: autogen_aarch64-master-0
environment:
- TITLE=MariaDB CI
- TITLE_URL=https://github.com/MariaDB/server
- BUILDMASTER_URL=https://buildbot.dev.mariadb.org/
- MQ_ROUTER_URL=ws://crossbar:8085/ws
volumes:
- ./logs:/var/log/buildbot
- ./buildbot/:/srv/buildbot/master
Expand All @@ -69,6 +79,11 @@ services:
image: quay.io/mariadb-foundation/bb-master:master
restart: unless-stopped
container_name: autogen_amd64-master-0
environment:
- TITLE=MariaDB CI
- TITLE_URL=https://github.com/MariaDB/server
- BUILDMASTER_URL=https://buildbot.dev.mariadb.org/
- MQ_ROUTER_URL=ws://crossbar:8085/ws
volumes:
- ./logs:/var/log/buildbot
- ./buildbot/:/srv/buildbot/master
Expand All @@ -89,6 +104,11 @@ services:
image: quay.io/mariadb-foundation/bb-master:master
restart: unless-stopped
container_name: autogen_amd64-master-1
environment:
- TITLE=MariaDB CI
- TITLE_URL=https://github.com/MariaDB/server
- BUILDMASTER_URL=https://buildbot.dev.mariadb.org/
- MQ_ROUTER_URL=ws://crossbar:8085/ws
volumes:
- ./logs:/var/log/buildbot
- ./buildbot/:/srv/buildbot/master
Expand All @@ -109,6 +129,11 @@ services:
image: quay.io/mariadb-foundation/bb-master:master
restart: unless-stopped
container_name: autogen_ppc64le-master-0
environment:
- TITLE=MariaDB CI
- TITLE_URL=https://github.com/MariaDB/server
- BUILDMASTER_URL=https://buildbot.dev.mariadb.org/
- MQ_ROUTER_URL=ws://crossbar:8085/ws
volumes:
- ./logs:/var/log/buildbot
- ./buildbot/:/srv/buildbot/master
Expand All @@ -129,6 +154,11 @@ services:
image: quay.io/mariadb-foundation/bb-master:master
restart: unless-stopped
container_name: autogen_s390x-master-0
environment:
- TITLE=MariaDB CI
- TITLE_URL=https://github.com/MariaDB/server
- BUILDMASTER_URL=https://buildbot.dev.mariadb.org/
- MQ_ROUTER_URL=ws://crossbar:8085/ws
volumes:
- ./logs:/var/log/buildbot
- ./buildbot/:/srv/buildbot/master
Expand All @@ -149,6 +179,11 @@ services:
image: quay.io/mariadb-foundation/bb-master:master
restart: unless-stopped
container_name: autogen_x86-master-0
environment:
- TITLE=MariaDB CI
- TITLE_URL=https://github.com/MariaDB/server
- BUILDMASTER_URL=https://buildbot.dev.mariadb.org/
- MQ_ROUTER_URL=ws://crossbar:8085/ws
volumes:
- ./logs:/var/log/buildbot
- ./buildbot/:/srv/buildbot/master
Expand All @@ -169,6 +204,11 @@ services:
image: quay.io/mariadb-foundation/bb-master:master
restart: unless-stopped
container_name: master-docker-nonstandard
environment:
- TITLE=MariaDB CI
- TITLE_URL=https://github.com/MariaDB/server
- BUILDMASTER_URL=https://buildbot.dev.mariadb.org/
- MQ_ROUTER_URL=ws://crossbar:8085/ws
volumes:
- ./logs:/var/log/buildbot
- ./buildbot/:/srv/buildbot/master
Expand All @@ -189,6 +229,11 @@ services:
image: quay.io/mariadb-foundation/bb-master:master
restart: unless-stopped
container_name: master-galera
environment:
- TITLE=MariaDB CI
- TITLE_URL=https://github.com/MariaDB/server
- BUILDMASTER_URL=https://buildbot.dev.mariadb.org/
- MQ_ROUTER_URL=ws://crossbar:8085/ws
volumes:
- ./logs:/var/log/buildbot
- ./buildbot/:/srv/buildbot/master
Expand All @@ -209,6 +254,11 @@ services:
image: quay.io/mariadb-foundation/bb-master:master
restart: unless-stopped
container_name: master-protected-branches
environment:
- TITLE=MariaDB CI
- TITLE_URL=https://github.com/MariaDB/server
- BUILDMASTER_URL=https://buildbot.dev.mariadb.org/
- MQ_ROUTER_URL=ws://crossbar:8085/ws
volumes:
- ./logs:/var/log/buildbot
- ./buildbot/:/srv/buildbot/master
Expand Down
81 changes: 59 additions & 22 deletions docker-compose/generate-config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#!/usr/bin/env python3
import argparse
import os

master_directories = [
from dotenv import load_dotenv

MASTER_DIRECTORIES = [
"autogen/aarch64-master-0",
"autogen/amd64-master-0",
"autogen/amd64-master-1",
Expand All @@ -15,7 +19,7 @@
"master-protected-branches",
]

start_template = """
START_TEMPLATE = """
---
version: "3.7"
services:
Expand Down Expand Up @@ -63,7 +67,7 @@
- crossbar
"""

docker_compose_template = """
DOCKER_COMPOSE_TEMPLATE = """
{master_name}:
image: quay.io/mariadb-foundation/bb-master:master
restart: unless-stopped
Expand All @@ -85,7 +89,7 @@
- crossbar
"""

end_template = """
END_TEMPLATE = """
networks:
net_front:
driver: bridge
Expand All @@ -108,21 +112,54 @@
com.docker.network.bridge.name: "br_bb_back"
"""

# Generate startup scripts and Docker Compose pieces for each master directory
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)
# Function to construct environment section for Docker Compose
def construct_env_section(env_vars):
env_section = " environment:\n"
for key, value in env_vars.items():
env_section += f" - {key}={value}\n"
return env_section.rstrip('\n')

def main(args):
# Load environment variables from the corresponding .env file
env_file = "prod.env" if args.env == "prod" else "dev.env"
load_dotenv(env_file)

env_vars = {
"TITLE": os.getenv("TITLE"),
"TITLE_URL": os.getenv("TITLE_URL"),
"BUILDMASTER_URL": os.getenv("BUILDMASTER_URL"),
"MQ_ROUTER_URL": os.getenv("MQ_ROUTER_URL")
}

# Modify the start_template to include the environment variables for master-web
master_env_section = construct_env_section(env_vars)
start_template = START_TEMPLATE.replace("container_name: master-web", f"container_name: master-web\n{master_env_section}")

# Modify the docker_compose_template to include the environment variables
docker_compose_template = DOCKER_COMPOSE_TEMPLATE.replace("container_name: {master_name}", f"container_name: {{master_name}}\n{master_env_section}")

# Generate startup scripts and Docker Compose pieces for each master directory
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)

if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Generate Docker Compose configuration.")
parser.add_argument("--env", choices=["prod", "dev"], default="dev", help="Choose the environment (prod/dev). Default is dev.")

args = parser.parse_args()
main(args)
4 changes: 4 additions & 0 deletions docker-compose/prod.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
TITLE="MariaDB CI"
TITLE_URL=https://github.com/MariaDB/server
BUILDMASTER_URL=https://buildbot.mariadb.org/
MQ_ROUTER_URL=ws://localhost:8085/ws
1 change: 0 additions & 1 deletion master-docker-nonstandard/dockerfiles

This file was deleted.

15 changes: 8 additions & 7 deletions master-docker-nonstandard/master.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ from buildbot.steps.shell import ShellCommand, Compile, Test, SetPropertyFromCom
from buildbot.steps.mtrlogobserver import MTR, MtrLogObserver
from buildbot.steps.source.github import GitHub
from buildbot.process.remotecommand import RemoteCommand
from datetime import timedelta
from twisted.internet import defer
import sys

import docker
from datetime import timedelta
import os
import sys

sys.path.insert(0, '/srv/buildbot/master')
sys.setrecursionlimit(10000)
Expand Down Expand Up @@ -51,15 +53,14 @@ c['services'].append(gs)

# the 'title' string will appear at the top of this buildbot installation's
# home pages (linked to the 'titleURL').
c['title'] = "MariaDB CI"
c['titleURL'] = "https://github.com/MariaDB/server"
c['title'] = os.getenv('TITLE', default="MariaDB CI")
c['titleURL'] = os.getenv('TITLE_URL', default="https://github.com/MariaDB/server")

# the 'buildbotURL' string should point to the location where the buildbot's
# internal web server is visible. This typically uses the port number set in
# the 'www' entry below, but with an externally-visible host name which the
# buildbot cannot figure out without some help.

c['buildbotURL'] = "https://buildbot.mariadb.org/"
c['buildbotURL'] = os.getenv('BUILDMASTER_URL', default="https://buildbot.mariadb.org/")

# 'protocols' contains information about protocols which master will use for
# communicating with workers. You must define at least 'port' option that workers
Expand Down Expand Up @@ -758,7 +759,7 @@ c['multiMaster'] = True

c['mq'] = { # Need to enable multimaster aware mq. Wamp is the only option for now.
'type' : 'wamp',
'router_url': 'ws://localhost:8085/ws',
'router_url': os.getenv('MQ_ROUTER_URL', default='ws://localhost:8085/ws'),
'realm': 'realm1',
# valid are: none, critical, error, warn, info, debug, trace
'wamp_debug_level' : 'info'
Expand Down
1 change: 0 additions & 1 deletion master-galera/dockerfiles

This file was deleted.

19 changes: 8 additions & 11 deletions master-galera/master.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ from buildbot.steps.shell import ShellCommand, Compile, Test, SetPropertyFromCom
from buildbot.steps.mtrlogobserver import MTR, MtrLogObserver
from buildbot.steps.source.github import GitHub
from buildbot.process.remotecommand import RemoteCommand
from datetime import timedelta
from twisted.internet import defer
import sys
import os

import docker
from datetime import timedelta
import os
import sys

sys.setrecursionlimit(10000)

Expand All @@ -32,18 +33,14 @@ exec(open("../master-private.cfg").read(), config, { })

# the 'title' string will appear at the top of this buildbot installation's
# home pages (linked to the 'titleURL').
c['title'] = "MariaDB CI"
c['titleURL'] = "https://github.com/MariaDB/server"
c['title'] = os.getenv('TITLE', default="MariaDB CI")
c['titleURL'] = os.getenv('TITLE_URL', default="https://github.com/MariaDB/server")

# the 'buildbotURL' string should point to the location where the buildbot's
# internal web server is visible. This typically uses the port number set in
# the 'www' entry below, but with an externally-visible host name which the
# buildbot cannot figure out without some help.

c['buildbotURL'] = "https://buildbot.dev.mariadb.org/"

# Custom plugin
# exec(open("grid.py").read())
c['buildbotURL'] = os.getenv('BUILDMASTER_URL', default="https://buildbot.mariadb.org/")

# 'protocols' contains information about protocols which master will use for
# communicating with workers. You must define at least 'port' option that workers
Expand Down Expand Up @@ -245,7 +242,7 @@ c['multiMaster'] = True

c['mq'] = { # Need to enable multimaster aware mq. Wamp is the only option for now.
'type' : 'wamp',
'router_url': 'ws://crossbar:8085/ws',
'router_url': os.getenv('MQ_ROUTER_URL', default='ws://localhost:8085/ws'),
'realm': 'realm1',
# valid are: none, critical, error, warn, info, debug, trace
'wamp_debug_level' : 'info'
Expand Down
15 changes: 8 additions & 7 deletions master-libvirt/master.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ from buildbot.steps.shell import ShellCommand, Compile, Test, SetPropertyFromCom
from buildbot.steps.mtrlogobserver import MTR, MtrLogObserver
from buildbot.steps.source.github import GitHub
from buildbot.process.remotecommand import RemoteCommand
from datetime import timedelta
from twisted.internet import defer
import sys

import docker
from datetime import timedelta
import os
import sys

sys.setrecursionlimit(10000)

Expand All @@ -31,15 +33,14 @@ exec(open("../master-private.cfg").read(), config, { })

# the 'title' string will appear at the top of this buildbot installation's
# home pages (linked to the 'titleURL').
c['title'] = "MariaDB CI"
c['titleURL'] = "https://github.com/MariaDB/server"
c['title'] = os.getenv('TITLE', default="MariaDB CI")
c['titleURL'] = os.getenv('TITLE_URL', default="https://github.com/MariaDB/server")

# the 'buildbotURL' string should point to the location where the buildbot's
# internal web server is visible. This typically uses the port number set in
# the 'www' entry below, but with an externally-visible host name which the
# buildbot cannot figure out without some help.

c['buildbotURL'] = "https://buildbot.dev.mariadb.org/"
c['buildbotURL'] = os.getenv('BUILDMASTER_URL', default="https://buildbot.mariadb.org/")

# 'protocols' contains information about protocols which master will use for
# communicating with workers. You must define at least 'port' option that workers
Expand Down Expand Up @@ -287,7 +288,7 @@ c['multiMaster'] = True

c['mq'] = { # Need to enable multimaster aware mq. Wamp is the only option for now.
'type' : 'wamp',
'router_url': 'ws://crossbar:8085/ws',
'router_url': os.getenv('MQ_ROUTER_URL', default='ws://localhost:8085/ws'),
'realm': 'realm1',
# valid are: none, critical, error, warn, info, debug, trace
'wamp_debug_level' : 'info'
Expand Down
Loading

0 comments on commit 24f2475

Please sign in to comment.