File: docker.py

package info (click to toggle)
circuits 3.2.3-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,980 kB
  • sloc: python: 17,583; javascript: 3,226; makefile: 100
file content (52 lines) | stat: -rw-r--r-- 1,074 bytes parent folder | download | duplicates (2)
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))