Skip to content

Commit

Permalink
Publish docker image(s) from Travis
Browse files Browse the repository at this point in the history
  • Loading branch information
Jairo Llopis authored and yajo committed Jan 15, 2020
1 parent d8d8836 commit 5d2131b
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 10 deletions.
8 changes: 7 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ sudo: required
language: python

python:
- "3.6"
- "3.8"

services:
- docker
Expand Down Expand Up @@ -41,3 +41,9 @@ install:

script:
- python -m unittest -v tests

deploy:
provider: script
script: ./hooks/push
on:
branch: master
34 changes: 25 additions & 9 deletions hooks/build
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
#!/bin/bash
set -ex
#!/usr/bin/env python3
from plumbum import FG, local

# See http://label-schema.org/rc1/#build-time-labels
time docker image build \
--build-arg VCS_REF="$GIT_SHA1" \
--build-arg BUILD_DATE="$(date --rfc-3339 ns)" \
--build-arg VERSION="$DOCKER_TAG" \
--tag "$IMAGE_NAME" \
.
COMMIT = local.env.get("GIT_SHA1", local.env.get("TRAVIS_COMMIT", ""))
IMAGE_NAME = local.env["IMAGE_NAME"]
ROOT = local.path(__file__).up(2)
VERSION = IMAGE_NAME.split(":")[1]

# Shortcuts
build = local["time"]["docker", "image", "build"]
date = local["date"]["--rfc-3339", "ns"]
tag = local["docker"]["image", "tag"]

# Build base and onbuild images
build[
"--tag",
IMAGE_NAME,
# See http://label-schema.org/rc1/#build-time-labels
"--build-arg",
"VCS_REF=%s" % COMMIT,
"--build-arg",
"BUILD_DATE=%s" % date().strip(),
"--build-arg",
"VERSION=%s" % VERSION,
ROOT,
] & FG
21 changes: 21 additions & 0 deletions hooks/push
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env python3
from plumbum import FG, local
from plumbum.cmd import docker # noqa pylint: disable=import-error

IMAGE_NAME = local.env["IMAGE_NAME"]
REPO = IMAGE_NAME.split(":")[0]

# Log all locally available images; will help to pin images
docker["image", "ls", "--digests", REPO] & FG

# Login in Docker Hub
docker(
"login",
"--username",
local.env["DOCKER_HUB_USERNAME"],
"--password",
local.env["DOCKER_HUB_TOKEN"],
)

# Push built image
docker["image", "push", IMAGE_NAME] & FG
1 change: 1 addition & 0 deletions requirements-ci.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
docker
plumbum

0 comments on commit 5d2131b

Please sign in to comment.