Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions taskboot/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def build_image(target, args):
'''
Build a docker image and allow save/push
'''
docker = Docker()
docker = Docker(cache=args.cache)

# Load config from file/secret
config = Configuration(args)
Expand Down Expand Up @@ -67,7 +67,7 @@ def build_compose(target, args):
Read a compose file and build each image described as buildable
'''
assert args.build_retries > 0, 'Build retries must be a positive integer'
docker = Docker()
docker = Docker(cache=args.cache)

# Check the dockerfile is available in target
composefile = target.check_path(args.composefile)
Expand Down
7 changes: 6 additions & 1 deletion taskboot/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def main():
parser.add_argument(
'--config',
type=open,
help='Path to local condfiguration/secrets file',
help='Path to local configuration/secrets file',
)
parser.add_argument(
'--secret',
Expand All @@ -42,6 +42,11 @@ def main():
type=str,
help='Target directory to use a local project',
)
parser.add_argument(
'--cache',
type=str,
help='Path to a local folder used to cache build processes',
)
commands = parser.add_subparsers(help='sub-command help')
parser.set_defaults(func=usage)

Expand Down
20 changes: 18 additions & 2 deletions taskboot/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import tarfile
import json


logger = logging.getLogger(__name__)


Expand All @@ -28,15 +29,24 @@ class Docker(Tool):
'''
Interface to the img tool, replacing docker daemon
'''
def __init__(self):
def __init__(self, cache=None):
super().__init__('img')

# Setup img state, using or creating a cache folder
if cache is not None:
self.state = os.path.join(os.path.realpath(cache), 'img')
os.makedirs(self.state, exist_ok=True)
else:
self.state = tempfile.mkdtemp('-img')
logger.info('Docker state is using {}'.format(self.state))

def login(self, registry, username, password):
'''
Login on remote registry
'''
cmd = [
'login',
'--state', self.state,
'--password-stdin',
'-u', username,
registry,
Expand All @@ -48,6 +58,7 @@ def build(self, context_dir, dockerfile, tag):
logger.info('Building docker image {}'.format(dockerfile))
self.run([
'build',
'--state', self.state,
'--no-console',
'--tag', tag,
'--file', dockerfile,
Expand All @@ -59,13 +70,18 @@ def save(self, tag, path):
logger.info('Saving image {} to {}'.format(tag, path))
self.run([
'save',
'--state', self.state,
'--output', path,
tag,
])

def push(self, tag):
logger.info('Pushing image {}'.format(tag))
self.run(['push', tag])
self.run([
'push',
'--state', self.state,
tag,
])


class Skopeo(Tool):
Expand Down