Change Tag by Commit, give it some powers
This commit is contained in:
parent
d984987ca9
commit
48e4094636
4
pod.py
4
pod.py
@ -12,6 +12,6 @@ podctl = Container(
|
|||||||
User('app', 1000, '/app'),
|
User('app', 1000, '/app'),
|
||||||
Copy(['setup.py', 'podctl'], '/app'),
|
Copy(['setup.py', 'podctl'], '/app'),
|
||||||
Pip('/app'),
|
Pip('/app'),
|
||||||
Config(cmd='podctl'),
|
Config(cmd='podctl', author='jpic'),
|
||||||
Tag('yourlabs/podctl'),
|
Commit('docker.io/yourlabs/podctl'),
|
||||||
)
|
)
|
||||||
|
|||||||
@ -1,8 +1,9 @@
|
|||||||
from .base import Base # noqa
|
from .base import Base # noqa
|
||||||
|
from .commit import Commit # noqa
|
||||||
from .config import Config # noqa
|
from .config import Config # noqa
|
||||||
from .copy import Copy # noqa
|
from .copy import Copy # noqa
|
||||||
from .packages import Packages # noqa
|
from .packages import Packages # noqa
|
||||||
from .pip import Pip # noqa
|
from .pip import Pip # noqa
|
||||||
|
from .push import Push # noqa
|
||||||
from .run import Run # noqa
|
from .run import Run # noqa
|
||||||
from .tag import Tag # noqa
|
|
||||||
from .user import User # noqa
|
from .user import User # noqa
|
||||||
|
|||||||
48
podctl/visitors/commit.py
Normal file
48
podctl/visitors/commit.py
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
CI_VARS = (
|
||||||
|
# gitlab
|
||||||
|
'CI_COMMIT_SHORT_SHA',
|
||||||
|
'CI_COMMIT_REF_NAME',
|
||||||
|
'CI_COMMIT_TAG',
|
||||||
|
# CircleCI
|
||||||
|
'CIRCLE_SHA1',
|
||||||
|
'CIRCLE_TAG',
|
||||||
|
'CIRCLE_BRANCH',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class Commit:
|
||||||
|
def __init__(self, repo, tags=None, format=None, push=None):
|
||||||
|
self.repo = repo
|
||||||
|
self.format = format or 'oci'
|
||||||
|
self.push = push
|
||||||
|
self.tags = tags or []
|
||||||
|
if self.repo.startswith('docker.io/'):
|
||||||
|
self.format = 'docker'
|
||||||
|
|
||||||
|
if not self.tags:
|
||||||
|
for name in CI_VARS:
|
||||||
|
value = os.getenv(name)
|
||||||
|
if value:
|
||||||
|
self.tags.append(value)
|
||||||
|
|
||||||
|
self.tags = [t for t in self.tags if t is not None]
|
||||||
|
|
||||||
|
def post_build(self, script):
|
||||||
|
creds = None
|
||||||
|
'''
|
||||||
|
if 'DOCKER_USER' in os.environ:
|
||||||
|
creds = '--creds ' + os.getenv('DOCKER_USER')
|
||||||
|
if 'DOCKER_PASS' in os.environ:
|
||||||
|
creds += ':' + os.getenv('DOCKER_PASS')
|
||||||
|
'''
|
||||||
|
|
||||||
|
script.append(f'''
|
||||||
|
umounts
|
||||||
|
trap - 0
|
||||||
|
buildah commit --format={self.format} $ctr {self.repo}
|
||||||
|
''')
|
||||||
|
|
||||||
|
if self.tags:
|
||||||
|
script.append(f'buildah tag {self.repo} ' + ' '.join(self.tags))
|
||||||
@ -1,6 +0,0 @@
|
|||||||
class Tag:
|
|
||||||
def __init__(self, tag):
|
|
||||||
self.tag = tag
|
|
||||||
|
|
||||||
def post_build(self, script):
|
|
||||||
script.append(f'umounts && trap - 0 && buildah commit $ctr {self.tag}')
|
|
||||||
Loading…
x
Reference in New Issue
Block a user