Skip to content
Snippets Groups Projects
generate_gitlabci.py 977 B
Newer Older
import glob
import sys

TEMPLATE = '''
build_{project}:
  image:
    name: gcr.io/kaniko-project/executor:debug
    entrypoint: [""]
  script:
    - echo "{{\\"auths\\":{{\\"$CI_REGISTRY\\":{{\\"username\\":\\"$CI_REGISTRY_USER\\",\\"password\\":\\"$CI_REGISTRY_PASSWORD\\"}}}}}}" > /kaniko/.docker/config.json
    - /kaniko/executor
      --context $CI_PROJECT_DIR/{context}
      --dockerfile $CI_PROJECT_DIR/{filepath}
      --destination $CI_REGISTRY_IMAGE/{project}
'''

try:
    if sys.argv[1]:
        TEMPLATE += f"      --build-arg {sys.argv[1]}={sys.argv[2]}"
except IndexError:
    pass

with open('.gitlab-ci.yml', 'w') as f:
    for filepath in sorted(glob.glob('library/**/Dockerfile', recursive=True)):
        project = '-'.join(filepath.split('/')[1:-1])
        context = filepath.replace('/Dockerfile', '')
        f.write(TEMPLATE.format(project=project,
                                context=context,
                                filepath=filepath))