85 Commits
Author SHA1 Message Date
jpic ∞ 3b6650efdb Merge branch 'mostadvanced' into 'master'
Complete core rewrite, with documentation

See merge request oss/shlax!1
2021-04-24 13:07:37 +00:00
jpic 28bfef29b0 Fix dist 2021-04-24 14:50:10 +02:00
jpic bcbe66a37f Fix exit codes 2021-04-24 14:00:27 +02:00
jpic 44dd1bc6a6 Fix output in case of failed command 2021-04-24 13:35:29 +02:00
jpic 9846425b29 Push self built to COMMIT_REF 2021-04-24 13:24:34 +02:00
jpic a7cd98ffbb Fix base image 2021-04-24 13:12:19 +02:00
jpic 8544a76bf2 Install CLI dependencies 2021-04-24 13:12:19 +02:00
jpic 7467f79bd9 Fix layer caching in CI? 2021-04-24 13:12:19 +02:00
jpic 3cd3dae619 Fix old call 2021-04-24 13:12:19 +02:00
jpic d23b3945f3 Support DOCKER_USER and DOCKER_PASS 2021-04-24 13:12:19 +02:00
jpic 9e586de312 Cache layers in CI? 2021-04-24 13:12:19 +02:00
jpic 5c941d38d6 Push argument 2021-04-24 13:12:19 +02:00
jpic b206a1e107 Specify repository 2021-04-24 13:12:19 +02:00
jpic 92246fc7be Dont try to color non-utf8 2021-04-24 13:12:19 +02:00
jpic 94890226e6 Fixing docker support in CI 2021-04-24 13:12:19 +02:00
jpic 1221ac5016 Do not specify an image format for layers 2021-04-24 13:12:19 +02:00
jpic 84b1230146 Build for docker 2021-04-24 13:12:19 +02:00
jpic 78252a439c Use buildah copy to support workingdir 2021-04-24 13:12:19 +02:00
jpic ae2aa62d0e Glob support in Copy 2021-04-24 13:12:19 +02:00
jpic a80e3fb48c Add docker daemon support 2021-04-24 13:12:19 +02:00
jpic 77439b6dc3 Do not skip build/commit even if up to date 2021-04-24 13:12:19 +02:00
jpic cada94ecc5 Fixing push 2021-04-24 13:12:19 +02:00
jpic 0edd573f4a Fix up cmd 2021-04-24 13:12:19 +02:00
jpic f5765c08a9 Target level cleaning had been forgotten
... when action level cleaning was added

Test both while we're at it, as this is pretty critical for actions to
clean up properly
2021-04-24 13:12:19 +02:00
jpic c46b42b23a Commenting docker job for now 2021-04-24 13:12:19 +02:00
jpic 4fcabf1aed test 2021-04-24 13:12:19 +02:00
jpic b37e4c1aed Fix shlax.cli (finally) 2021-04-24 13:12:19 +02:00
jpic 4ea9783c93 Cache invalidation failures must not stop build
Images may still be in use by running containers
2021-04-24 13:12:19 +02:00
jpic 54e3266789 Prevent print traceback for failed commands 2021-04-24 13:12:19 +02:00
jpic 5c76ef3f2d Forward CLI arguments 2021-04-24 13:12:19 +02:00
jpic c5af902382 Fix Pod.build to unshare prior to building async 2021-04-24 13:12:19 +02:00
jpic ecabf6c9ce Add target argument only if present in sig 2021-04-24 13:12:19 +02:00
jpic 324a8f4962 Readability 2021-04-24 13:12:19 +02:00
jpic 61fb39ebea Add container inspect 2021-04-24 13:12:19 +02:00
jpic 5a20ccf2f7 Layers refactor 2021-04-24 13:12:19 +02:00
jpic d5544a6e85 Support configured containers in start 2021-04-24 13:12:19 +02:00
jpic ce931a2cc6 Fix TargetArgument implementation to stay optional 2021-04-24 13:12:18 +02:00
jpic 12edb5168f Add exec command 2021-04-24 13:12:18 +02:00
jpic d2c0694005 Skip report display for only one result 2021-04-24 13:12:18 +02:00
jpic 15c71a3bf7 Getting on par with docker-compose 2021-04-24 13:12:18 +02:00
jpic 6e7f957d49 Remove artificial centering from output labels 2021-04-24 13:12:18 +02:00
jpic 30798fc66c Name parallel executor 2021-04-24 13:12:18 +02:00
jpic 7408cf95c0 Add Buildah.Env and Buildah.Config 2021-04-24 13:12:18 +02:00
jpic 7f150ae17a New write with bash heredoc 2021-04-24 13:12:18 +02:00
jpic 073c3713c1 Let an action mark itself as skipped 2021-04-24 13:12:18 +02:00
jpic 1ce27e1cd1 Container: support not having a build job and new methods 2021-04-24 13:12:18 +02:00
jpic 9235ffcd27 Fix user action 2021-04-24 13:12:18 +02:00
jpic 07a6c5b628 Run(root) 2021-04-24 13:12:18 +02:00
jpic 47740f01f9 Test build-itself 2021-04-24 13:12:18 +02:00
jpic 9330125208 Update TargetArgument docs 2021-04-24 13:12:18 +02:00
jpic afc1823e54 Mention command line 2021-04-24 13:12:18 +02:00
jpic f07787d865 Fix title order 2021-04-24 13:12:18 +02:00
jpic 84b10ce143 Lolnote 2021-04-24 13:12:18 +02:00
jpic ae61e1b8cf Going to maintain a little news at the top of the README 2021-04-24 13:12:18 +02:00
jpic 6a0b60d68a Do not try to commit a container that has not been created because layers are uptodate 2021-04-24 13:12:18 +02:00
jpic 63e610ca4f Fixing container config support 2021-04-24 13:12:18 +02:00
jpic 4f5326c81b Commiting build-itself job until i re-implement docker commiting 2021-04-24 13:12:18 +02:00
jpic 224608878e Clean on KeyboardInterrupt, proper call in shlax Command 2021-04-24 13:12:18 +02:00
jpic eafa371617 Package action working both on SSH host and Buildah guest now 2021-04-24 13:12:18 +02:00
jpic b6fa18d82a Added ssh target 2021-04-24 13:12:18 +02:00
jpic 754227d2d1 Silence pip output 2021-04-24 13:12:18 +02:00
jpic 62299da7c1 A bit of work on the command line 2021-04-24 13:12:18 +02:00
jpic 0929b37b36 Tag/build/push refactor 2021-04-24 13:12:18 +02:00
jpic 8dd4fa52ac Typo in ci 2021-04-24 13:12:18 +02:00
jpic 0ac1764464 Try more build 2021-04-24 13:12:18 +02:00
jpic 70e354dd02 Fix CI command to build 2021-04-24 13:12:18 +02:00
jpic 0a983340b8 Buildah __str__ 2021-04-24 13:12:18 +02:00
jpic c6bc849574 Missing await in test function 2021-04-24 13:12:18 +02:00
jpic 2e1bbf098a Pass status directly to clean 2021-04-24 13:12:18 +02:00
jpic c6d7eedde2 Improve Buildah clean method 2021-04-24 13:12:18 +02:00
jpic 93b95a1f50 Set the action result prior to calling clean 2021-04-24 13:12:18 +02:00
jpic a07d9c5e67 Pip action implementation 2021-04-24 13:12:18 +02:00
jpic c570f0fd6d Bugfix: legacy code would prevent containers from shuting down after build 2021-04-24 13:12:18 +02:00
jpic 5caf9d92e3 Proper cache invalidation 2021-04-24 13:12:18 +02:00
jpic c58d1618ed Proper traceback prints 2021-04-24 13:12:18 +02:00
jpic 4af938fab0 Copy action: refactor, caching, filtering 2021-04-24 13:12:18 +02:00
jpic 7a61b405ae Work on the CLI story 2021-04-24 13:12:18 +02:00
jpic 600043ae64 Adding Copy/User/Pip actions again 2021-04-24 13:12:18 +02:00
jpic b2169ff7eb Add CLI to execute Actions on the fly 2021-04-24 13:12:18 +02:00
jpic f374d77c21 Proper render method actions 2021-04-24 13:12:18 +02:00
jpic b6bb06054d fixup! Add layer caching 2021-04-24 13:12:18 +02:00
jpic 1b1a121a24 Replace Localhost with plain Target, ensure parent presence 2021-04-24 13:12:18 +02:00
jpic 1d5e8ab1c8 Add layer caching 2021-04-24 13:12:18 +02:00
jpic e62d44514a Add Proc.quiet 2021-04-24 13:12:18 +02:00
jpic b044dd015e Add Package.upgrade option 2021-04-24 13:12:18 +02:00
15 changed files with 105 additions and 35 deletions
+12 -6
View File
@@ -1,21 +1,27 @@
build: build:
cache: cache:
key: cache key: cache
paths: [.cache] paths: [.cache, /var/lib/containers/]
image: yourlabs/buildah image: yourlabs/buildah
script: script:
- pip3 install -U --user -e .[cli] - pip3 install -U --user .[cli]
- CACHE_DIR=$(pwd)/.cache python3 ./shlaxfile.py build push - CACHE_DIR=$(pwd)/.cache python3 ./shlaxfile.py build push=docker://docker.io/yourlabs/shlax:$CI_COMMIT_SHORT_SHA
stage: build stage: build
build-itself: build-itself:
cache: cache:
key: cache key: cache
paths: [.cache] paths: [.cache, /var/lib/containers/]
image: quay.io/yourlabs/shlax:$CI_COMMIT_SHORT_SHA image: yourlabs/shlax:$CI_COMMIT_SHORT_SHA
script: python3 ./shlaxfile.py build script: python3 ./shlaxfile.py build push=docker://docker.io/yourlabs/shlax:$CI_COMMIT_REF
stage: test stage: test
test-exitcode:
image: yourlabs/shlax:$CI_COMMIT_SHORT_SHA
script:
- tests/shlaxfail.py build || [ $? -eq 1 ]
- tests/shlaxsuccess.py build
test: test:
image: yourlabs/python image: yourlabs/python
stage: build stage: build
View File
View File
+8 -1
View File
@@ -1,12 +1,19 @@
import asyncio import asyncio
import binascii import binascii
import glob
import os import os
class Copy: class Copy:
def __init__(self, *args): def __init__(self, *args):
self.src = args[:-1]
self.dst = args[-1] self.dst = args[-1]
self.src = []
for src in args[:-1]:
if '*' in src:
self.src += glob.glob(src)
else:
self.src.append(src)
def listfiles(self): def listfiles(self):
if getattr(self, '_listfiles', None): if getattr(self, '_listfiles', None):
+4
View File
@@ -61,6 +61,10 @@ class Command(cli2.Command):
# just output the failure without TB, as command was already # just output the failure without TB, as command was already
# printed anyway # printed anyway
pass pass
if self['target'].value.results:
if self['target'].value.results[-1].status == 'failure':
self.exit_code = 1
self['target'].value.output.results(self['target'].value) self['target'].value.output.results(self['target'].value)
return result return result
View File
+9 -7
View File
@@ -60,9 +60,11 @@ class Image:
setattr(self, k, v) setattr(self, k, v)
# docker.io currently has issues with oci format # docker.io currently has issues with oci format
self.format = format or 'oci'
if self.registry == 'docker.io': if self.registry == 'docker.io':
self.format = 'docker' self.backend = 'docker'
if not self.format:
self.format = 'docker' if self.backend == 'docker' else 'oci'
# filter out tags which resolved to None # filter out tags which resolved to None
self.tags = [t for t in self.tags if t] self.tags = [t for t in self.tags if t]
@@ -74,19 +76,19 @@ class Image:
def __str__(self): def __str__(self):
return f'{self.repository}:{self.tags[-1]}' return f'{self.repository}:{self.tags[-1]}'
async def push(self, target): async def push(self, target, name=None):
user = os.getenv('IMAGES_USER') user = os.getenv('IMAGES_USER', os.getenv('DOCKER_USER'))
passwd = os.getenv('IMAGES_PASS') passwd = os.getenv('IMAGES_PASS', os.getenv('DOCKER_PASS'))
if user and passwd: if user and passwd:
target.output.cmd('buildah login -u ... -p ...' + self.registry) target.output.cmd('buildah login -u ... -p ...' + self.registry)
await target.parent.exec( await target.parent.exec(
'buildah', 'login', '-u', user, '-p', passwd, 'buildah', 'login', '-u', user, '-p', passwd,
self.registry or 'docker.io', debug=False) self.registry or 'docker.io', quiet=True)
for tag in self.tags: for tag in self.tags:
await target.parent.exec( await target.parent.exec(
'buildah', 'buildah',
'push', 'push',
self.repository + ':final', self.repository + ':final',
f'{self.registry}/{self.repository}:{tag}' name if isinstance(name, str) else f'{self.registry}/{self.repository}:{tag}'
) )
+5 -1
View File
@@ -101,7 +101,11 @@ class Output:
) )
def highlight(self, line, highlight=True): def highlight(self, line, highlight=True):
line = line.decode('utf8') if isinstance(line, bytes) else line try:
line = line.decode('utf8') if isinstance(line, bytes) else line
except UnicodeDecodeError:
highlight = False
if not highlight or ( if not highlight or (
'\x1b[' in line '\x1b[' in line
or '\033[' in line or '\033[' in line
View File
View File
+14 -8
View File
@@ -6,7 +6,7 @@ import re
import sys import sys
from ..output import Output from ..output import Output
from ..proc import Proc from ..proc import Proc, ProcFailure
from ..result import Result, Results from ..result import Result, Results
@@ -68,13 +68,19 @@ class Target:
self.output.fail(action, e) self.output.fail(action, e)
result.status = 'failure' result.status = 'failure'
result.exception = e result.exception = e
if reraise:
# nested call, re-raise if not isinstance(e, ProcFailure):
raise # no need to reraise in case of command error
else: # because the command has been printed
import traceback
traceback.print_exception(type(e), e, sys.exc_info()[2]) if reraise:
return True # nested call, re-raise
raise
else:
import traceback
traceback.print_exception(type(e), e, sys.exc_info()[2])
return True # because it failed
else: else:
if getattr(action, 'skipped', False): if getattr(action, 'skipped', False):
self.output.skip(action) self.output.skip(action)
+15 -9
View File
@@ -37,7 +37,7 @@ class Buildah(Target):
return 'Replacing with: buildah unshare ' + ' '.join(sys.argv) return 'Replacing with: buildah unshare ' + ' '.join(sys.argv)
return f'Buildah({self.image})' return f'Buildah({self.image})'
async def __call__(self, *actions, target=None, push: bool=False): async def __call__(self, *actions, target=None, push: str=False):
if target: if target:
self.parent = target self.parent = target
@@ -57,12 +57,8 @@ class Buildah(Target):
if actions: if actions:
actions = actions[len(keep):] actions = actions[len(keep):]
if not actions:
return self.output.success('Image up to date')
else: else:
self.actions = self.actions[len(keep):] self.actions = self.actions[len(keep):]
if not self.actions:
return self.output.success('Image up to date')
self.ctr = (await self.parent.exec('buildah', 'from', self.base)).out self.ctr = (await self.parent.exec('buildah', 'from', self.base)).out
self.root = Path((await self.parent.exec('buildah', 'mount', self.ctr)).out) self.root = Path((await self.parent.exec('buildah', 'mount', self.ctr)).out)
@@ -111,7 +107,6 @@ class Buildah(Target):
await self.parent.exec( await self.parent.exec(
'buildah', 'buildah',
'commit', 'commit',
'--format=' + action_image.format,
self.ctr, self.ctr,
action_image, action_image,
) )
@@ -127,7 +122,7 @@ class Buildah(Target):
if result.status == 'success' and self.ctr: if result.status == 'success' and self.ctr:
await self.commit() await self.commit()
if self.push: if self.push:
await self.image.push(target) await self.image.push(target, self.push)
if self.ctr is not None: if self.ctr is not None:
await self.parent.exec('buildah', 'rm', self.ctr) await self.parent.exec('buildah', 'rm', self.ctr)
@@ -149,8 +144,19 @@ class Buildah(Target):
async def commit(self): async def commit(self):
await self.parent.exec( await self.parent.exec(
f'buildah commit {self.ctr} {self.image.repository}:final' 'buildah',
'commit',
f'--format={self.image.format}',
self.ctr,
f'{self.image.repository}:final',
) )
if self.image.backend == 'docker':
await self.parent.exec(
'buildah',
'push',
f'{self.image.repository}:final',
f'docker-daemon:{self.image.repository}:latest'
)
ENV_TAGS = ( ENV_TAGS = (
# gitlab # gitlab
@@ -181,7 +187,7 @@ class Buildah(Target):
return await self.parent.mkdir(*[self.path(path) for path in paths]) return await self.parent.mkdir(*[self.path(path) for path in paths])
async def copy(self, *args): async def copy(self, *args):
return await self.parent.copy(*args[:-1], self.path(args[-1])) return await self.parent.exec('buildah', 'copy', self.ctr, *args)
async def write(self, path, content): async def write(self, path, content):
return await self.write(path, content) return await self.write(path, content)
+3 -3
View File
@@ -9,9 +9,9 @@ shlax = Container(
build=Buildah( build=Buildah(
Packages('python38', 'buildah', 'unzip', 'findutils', upgrade=False), Packages('python38', 'buildah', 'unzip', 'findutils', upgrade=False),
Copy('setup.py', 'shlax', '/app'), Copy('setup.py', 'shlax', '/app'),
Pip('/app'), Pip('/app[cli]'),
base='quay.io/podman/stable', base='quay.io/buildah/stable',
commit='quay.io/yourlabs/shlax', commit='docker://docker.io/yourlabs/shlax',
), ),
) )
+18
View File
@@ -0,0 +1,18 @@
#!/usr/bin/env python
"""
Shlaxfile for shlax itself.
"""
from shlax.shortcuts import *
shlax = Container(
build=Buildah(
Packages('prout', upgrade=False),
base='alpine',
commit='shlaxfail',
),
)
if __name__ == '__main__':
print(Group(doc=__doc__).load(shlax).entry_point())
+17
View File
@@ -0,0 +1,17 @@
#!/usr/bin/env python
"""
Shlaxfile for shlax itself.
"""
from shlax.shortcuts import *
shlax = Container(
build=Buildah(
base='alpine',
commit='shlaxsuccess',
),
)
if __name__ == '__main__':
print(Group(doc=__doc__).load(shlax).entry_point())