Created
February 5, 2024 17:56
-
-
Save devgianlu/fbac945cb767a4a1d8aa9cb2462e3d5c to your computer and use it in GitHub Desktop.
Utility script to generate a docker-compose.yml for multiple GitHub self-hosted runners
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import json | |
service_block = """ | |
worker_{org_clean}_{name_clean}: | |
image: myoung34/github-runner | |
restart: unless-stopped | |
environment: | |
REPO_URL: https://github.com/{org}/{name} | |
RUNNER_NAME: oracle_{org_clean}_{name_clean} | |
RUNNER_TOKEN: {token} | |
RUNNER_WORKDIR: /tmp/runner_{org_clean}_{name_clean}/work | |
CONFIGURED_ACTIONS_RUNNER_FILES_DIR: /conf | |
LABELS: linux,arm64,oracle | |
security_opt: | |
- label:disable | |
volumes: | |
- /var/run/docker.sock:/var/run/docker.sock | |
- ./data/{org_clean}_{name_clean}:/conf | |
- /tmp/runner_{org_clean}_{name_clean}:/tmp/runner_{org_clean}_{name_clean} | |
""" | |
with open('repos.json', 'r') as f: | |
repos = json.load(f) | |
docker_compose = 'services:' | |
for repo in repos: | |
assert len(repo.get('org', '')) > 0 | |
assert len(repo.get('name', '')) > 0 | |
assert len(repo.get('token', '')) > 0 | |
print(f'Repository {repo["org"]}/{repo["name"]}: {repo["token"]}') | |
docker_compose += service_block.format( | |
org=repo['org'], | |
org_clean=repo['org'].lower(), | |
name=repo['name'], | |
name_clean=repo['name'].lower(), | |
token=repo['token'] | |
) | |
with open('docker-compose.yml', 'w') as f: | |
f.write(docker_compose) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"org": "aaaaa", | |
"name": "bbbbb", | |
"token": "XXXXXXXXXXXXXXX" | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment