Skip to content

Commit

Permalink
Allow Git tags to generate Docker tagged images (#128)
Browse files Browse the repository at this point in the history
* Fixing Makefile to allow tag builds

Signed-off-by: dduportal <[email protected]>

wip travis

Signed-off-by: dduportal <[email protected]>

Fix docker image tag variable

Signed-off-by: dduportal <[email protected]>

Support of branches or tags with a slash

Signed-off-by: dduportal <[email protected]>

wip

Signed-off-by: dduportal <[email protected]>

* Allow travis deploy on all branches

Signed-off-by: dduportal <[email protected]>
  • Loading branch information
dduportal authored Feb 10, 2020
1 parent 6823da5 commit 11eddee
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
23 changes: 12 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,24 @@ services:

env:
global:
- CURRENT_GIT_BRANCH=$TRAVIS_BRANCH
- CURRENT_GIT_REF="${TRAVIS_BRANCH}" # Pass the tag, or target branch for a PR, or the branch

script:
- make build
- make test
- make build
- make test

before_deploy:
# Set up git user name before generating README.md as part of deploy
- git config --local user.name "travis-build"
- git config --local user.email "[email protected]"

deploy:
- provider: script
script: make README.md deploy
# Do not deploy if Pull Request
# If a contributor want to deploy on its own DockerHub account:
# 1 - Enable Travis on the forked repository
# 2 - Set the environment variable DOCKERHUB_USERNAME in Travis Settings
on:
condition: $TRAVIS_PULL_REQUEST = false
- provider: script
script: make README.md deploy
# Do not deploy if Pull Request
# If a contributor want to deploy on its own DockerHub account:
# 1 - Enable Travis on the forked repository
# 2 - Set the environment variable DOCKERHUB_USERNAME in Travis Settings
on:
all_branches: true
condition: $TRAVIS_PULL_REQUEST = false
13 changes: 7 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@

DOCKER_IMAGE_NAME ?= docker-asciidoctor
DOCKERHUB_USERNAME ?= asciidoctor
DOCKER_IMAGE_TEST_TAG ?= $(shell git rev-parse --short HEAD)
DOCKER_IMAGE_NAME_TO_TEST ?= $(DOCKERHUB_USERNAME)/$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TEST_TAG)
CURRENT_GIT_REF ?= $(shell git rev-parse --abbrev-ref HEAD) # Default to current branch
DOCKER_IMAGE_TAG ?= $(shell echo $(CURRENT_GIT_REF) | sed 's/\//-/' )
DOCKER_IMAGE_NAME_TO_TEST ?= $(DOCKERHUB_USERNAME)/$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)
ASCIIDOCTOR_VERSION ?= 2.0.10
ASCIIDOCTOR_CONFLUENCE_VERSION ?= 0.0.2
ASCIIDOCTOR_PDF_VERSION ?= 1.5.0.rc.3
Expand All @@ -11,7 +12,6 @@ ASCIIDOCTOR_EPUB3_VERSION ?= 1.5.0.alpha.12
ASCIIDOCTOR_MATHEMATICAL_VERSION ?= 0.3.1
ASCIIDOCTOR_REVEALJS_VERSION ?= 3.1.0
KRAMDOWN_ASCIIDOC_VERSION ?= 1.0.1
CURRENT_GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)

export DOCKER_IMAGE_NAME_TO_TEST \
ASCIIDOCTOR_VERSION \
Expand All @@ -27,17 +27,18 @@ all: build test deploy

build:
docker build \
-t $(DOCKER_IMAGE_NAME_TO_TEST) \
-f Dockerfile \
--tag="$(DOCKER_IMAGE_NAME_TO_TEST)" \
--file=Dockerfile \
$(CURDIR)/

test:
bats $(CURDIR)/tests/*.bats

deploy:
ifdef DOCKER_HUB_TRIGGER_URL

curl --verbose --header "Content-Type: application/json" \
--data '{"source_type": "Branch", "source_name": "$(CURRENT_GIT_BRANCH)"}' \
--data '{"source_type": "$(shell [ -n "${TRAVIS_TAG}" ] && echo Tag || echo Branch)", "source_name": "$(CURRENT_GIT_REF)"}' \
-X POST $(DOCKER_HUB_TRIGGER_URL)
else
@echo 'Unable to deploy: Please define $$DOCKER_HUB_TRIGGER_URL'
Expand Down

0 comments on commit 11eddee

Please sign in to comment.