Commit 09c31f4d authored by akira's avatar akira
Browse files

NEW help command to register and run runners

parent ecaaa0f1
#!/bin/env python
import argparse
import subprocess
import os
import shlex
register_command_template = ("gitlab-ci-multi-runner register "
"--non-interactive "
"--locked "
"--executor shell "
"--config {config_path} "
"--url '{site_url}' "
"--tls-ca-file {cert_file} "
"--name '{hostname}-{project_name}' "
"--registration-token {token} "
"--builds-dir {runner_dir}"
"--tag-list {user},{hostname} ")
def main():
default_hostname = os.getenv('HOSTNAME').split('.')[-1]
default_user = os.getenv('USER')
default_cert_file_path = os.path.join(os.getenv('PWD'), "dci-gitlab.cines.fr.crt")
parser = argparse.ArgumentParser(description='Register gitlab runners',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('token', type=str,
help='The gitlab specific project token')
parser.add_argument('project_name', metavar='project-name', type=str,
help='the project name')
parser.add_argument('--hostname', type=str, default=default_hostname,
help='change hostname')
parser.add_argument('--user', type=str, default=default_user,
help='change user')
parser.add_argument('--site-url', type=str, default='https://dci-gitlab.cines.fr/',
help='change gitlabs site url')
parser.add_argument('--cert-file', type=str, default=default_cert_file_path,
help='use certificate file')
args = parser.parse_args()
runner_dir = os.path.join(os.getenv('PWD'), '-'.join([args.hostname, args.project_name]))
register_command = register_command_template.format(project_name=args.project_name,
config_path=os.path.join(runner_dir, "config.toml"),
site_url=args.site_url,
hostname=args.hostname,
token=args.token,
cert_file=os.path.abspath(args.cert_file),
runner_dir=runner_dir,
user=args.user)
if os.path.isdir(runner_dir):
print("target dir already exists, registration not possible")
exit()
os.mkdir(runner_dir)
subprocess.check_call(shlex.split(register_command))
#toml_file = open(os.path.join(runner_dir, "config.toml"), "w")
#toml_file.write(toml_configuration)
#toml_file.close
if __name__ == '__main__':
main()
#!/bin/env python
import argparse
import subprocess
import os
import shlex
run_command_template = ("gitlab-ci-multi-runner run "
"--config {config_path} ")
def main():
default_hostname = os.getenv('HOSTNAME').split('.')[-1]
parser = argparse.ArgumentParser(description='Run gitlab runners',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('project_name', metavar='project-name', type=str,
help='the project name')
parser.add_argument('--hostname', type=str, default=default_hostname,
help='change hostname')
args = parser.parse_args()
runner_dir = os.path.join(os.getenv('PWD'), '-'.join([args.hostname, args.project_name]))
config_path = os.path.join(runner_dir, "config.toml")
run_command = run_command_template.format(config_path=config_path)
if not os.path.exists(config_path):
print("target project not available please register first")
exit()
subprocess.check_call(shlex.split(run_command))
#toml_file = open(os.path.join(runner_dir, "config.toml"), "w")
#toml_file.write(toml_configuration)
#toml_file.close
if __name__ == '__main__':
main()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment