run 1.22 KB
Newer Older
1
2
3
4
5
6
#!/bin/env python
import argparse
import subprocess
import os
import shlex

7
run_command_template = ("./gitlab-runner run "
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
                             "--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()