Commit: support login, push, parse repo ...

This commit is contained in:
jpic 2020-01-26 12:42:16 +01:00
parent ec791a0446
commit d43affe9bc

View File

@ -1,4 +1,5 @@
import os import os
import subprocess
CI_VARS = ( CI_VARS = (
# gitlab # gitlab
@ -13,30 +14,40 @@ CI_VARS = (
class Commit: class Commit:
def __init__(self, repo, tags=None, format=None, push=None): def __init__(self, repo, tags=None, format=None, push=None, registry=None):
self.repo = repo self.repo = repo
self.format = format or 'oci' self.registry = registry
self.push = push self.push = push
self.tags = tags or []
if self.repo.startswith('docker.io/'): # figure out registry host
if '/' in self.repo and not registry:
first = self.repo.split('/')[0]
if '.' in first or ':' in first:
self.registry = self.repo.split('/')[0]
# docker.io currently has issues with oci format
self.format = format or 'oci'
if self.registry == 'docker.io':
self.format = 'docker' self.format = 'docker'
self.tags = tags or []
# figure tags from CI vars
if not self.tags: if not self.tags:
for name in CI_VARS: for name in CI_VARS:
value = os.getenv(name) value = os.getenv(name)
if value: if value:
self.tags.append(value) self.tags.append(value)
# filter out tags which resolved to None
self.tags = [t for t in self.tags if t is not None] self.tags = [t for t in self.tags if t is not None]
def post_build(self, script): def post_build(self, script):
creds = None user = os.getenv('DOCKER_USER')
''' passwd = os.getenv('DOCKER_PASS')
if 'DOCKER_USER' in os.environ: if user and passwd and os.getenv('CI') and self.registry:
creds = '--creds ' + os.getenv('DOCKER_USER') subprocess.check_call([
if 'DOCKER_PASS' in os.environ: 'podman', 'login', '-u', user, '-p', passwd, self.registry])
creds += ':' + os.getenv('DOCKER_PASS')
'''
script.append(f''' script.append(f'''
umounts umounts