From cada94ecc5ed89591383b137643c4db8118aedbf Mon Sep 17 00:00:00 2001 From: jpic Date: Thu, 8 Oct 2020 00:50:30 +0200 Subject: [PATCH] Fixing push --- .gitlab-ci.yml | 20 ++++++++++---------- shlax/image.py | 20 +++++++++++++------- shlax/targets/buildah.py | 6 ++++-- shlaxfile.py | 2 +- 4 files changed, 28 insertions(+), 20 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 90ddbee..fed323e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -5,17 +5,17 @@ build: image: yourlabs/buildah script: - pip3 install -U --user -e .[cli] - - CACHE_DIR=$(pwd)/.cache python3 ./shlaxfile.py build + - CACHE_DIR=$(pwd)/.cache python3 ./shlaxfile.py build push stage: build -# commenting until we have docker again -# build-itself: -# cache: -# key: cache -# paths: [.cache] -# image: shlax:$CI_COMMIT_SHORT_SHA -# script: python3 ./shlaxfile.py build -# stage: test -# + +build-itself: + cache: + key: cache + paths: [.cache] + image: quay.io/yourlabs/shlax:$CI_COMMIT_SHORT_SHA + script: python3 ./shlaxfile.py build + stage: test + test: image: yourlabs/python stage: build diff --git a/shlax/image.py b/shlax/image.py index 9aade3c..45ed9ec 100644 --- a/shlax/image.py +++ b/shlax/image.py @@ -74,13 +74,19 @@ class Image: def __str__(self): return f'{self.repository}:{self.tags[-1]}' - async def push(self, *args, **kwargs): - user = os.getenv('DOCKER_USER') - passwd = os.getenv('DOCKER_PASS') - action = kwargs.get('action', self) + async def push(self, target): + user = os.getenv('IMAGES_USER') + passwd = os.getenv('IMAGES_PASS') if user and passwd: - action.output.cmd('buildah login -u ... -p ...' + self.registry) - await action.exec('buildah', 'login', '-u', user, '-p', passwd, self.registry or 'docker.io', debug=False) + target.output.cmd('buildah login -u ... -p ...' + self.registry) + await target.parent.exec( + 'buildah', 'login', '-u', user, '-p', passwd, + self.registry or 'docker.io', debug=False) for tag in self.tags: - await action.exec('buildah', 'push', f'{self.repository}:{tag}') + await target.parent.exec( + 'buildah', + 'push', + self.repository + ':final', + f'{self.registry}/{self.repository}:{tag}' + ) diff --git a/shlax/targets/buildah.py b/shlax/targets/buildah.py index 5314a61..f5951e2 100644 --- a/shlax/targets/buildah.py +++ b/shlax/targets/buildah.py @@ -37,10 +37,12 @@ class Buildah(Target): return 'Replacing with: buildah unshare ' + ' '.join(sys.argv) return f'Buildah({self.image})' - async def __call__(self, *actions, target=None): + async def __call__(self, *actions, target=None, push: bool=False): if target: self.parent = target + self.push = push + if not self.is_runnable(): os.execvp('buildah', ['buildah', 'unshare'] + sys.argv) return # process has been replaced @@ -124,7 +126,7 @@ class Buildah(Target): if result.status == 'success' and self.ctr: await self.commit() - if os.getenv('BUILDAH_PUSH'): + if self.push: await self.image.push(target) if self.ctr is not None: diff --git a/shlaxfile.py b/shlaxfile.py index 7a87b23..3e019fb 100755 --- a/shlaxfile.py +++ b/shlaxfile.py @@ -11,7 +11,7 @@ shlax = Container( Copy('setup.py', 'shlax', '/app'), Pip('/app'), base='quay.io/podman/stable', - commit='shlax', + commit='quay.io/yourlabs/shlax', ), )