1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
"""Docker Tasks"""
from fabric.api import local, task
from .utils import msg, requires, tobool
TAG = 'prologic/circuits'
@task(default=True)
@requires('docker')
def build(**options):
"""
Build Docker Image
Options can be provided to customize the build.
The following options are supported:
- rebuild -> Whether to rebuild without a cache.
- version -> Specific version to tag the image with (Default: latest)
"""
rebuild = tobool(options.get('rebuild', False))
version = options.get('version', 'latest')
tag = f'{TAG:s}:{version:s}'
args = ['docker', 'build', '-t', tag, '.']
if rebuild:
args.insert(-1, '--no-cache')
with msg('Building Image'):
local(' '.join(args))
@task()
@requires('docker')
def publish():
"""Publish Docker Image"""
args = ['docker', 'push', TAG]
with msg('Pushing Image'):
local(' '.join(args))
@task()
@requires('docker')
def run():
"""Run Docker Container"""
args = ['docker', 'run', '-i', '-t', '--rm', TAG]
local(' '.join(args))
|