Navigation Menu

Skip to content

Commit

Permalink
Added separate docker fabric module to generalize docker build, publi…
Browse files Browse the repository at this point in the history
…sh and run development task(s)
  • Loading branch information
prologic committed Jun 4, 2014
1 parent f4e2f1f commit 60055dc
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 12 deletions.
14 changes: 2 additions & 12 deletions fabfile/__init__.py
Expand Up @@ -19,6 +19,8 @@

import help # noqa
import docs # noqa
import docker # noqa

from .utils import msg, pip, requires, tobool


Expand Down Expand Up @@ -72,18 +74,6 @@ def test():
local("python setup.py test")


@task()
@requires("docker")
def docker():
"""Build and Publish Docker Image"""

with msg("Building Image"):
local("docker build -t prologic/circuits .")

with msg("Pushing Image"):
local("docker push prologic/circuits")


@task()
@hosts("localhost")
def release():
Expand Down
61 changes: 61 additions & 0 deletions fabfile/docker.py
@@ -0,0 +1,61 @@
# Module: docker
# Date: 24th May 2014
# Author: James Mills, j dot mills at griffith dot edu dot au


"""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 = "{0:s}:{1:s}".format(TAG, version)
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))

0 comments on commit 60055dc

Please sign in to comment.