Skip to content

Commit

Permalink
Merge pull request #61 from dduportal/gh-49-ci
Browse files Browse the repository at this point in the history
GH-49: Implementation proposal for CI and CD
  • Loading branch information
dduportal authored Apr 21, 2018
2 parents 193958f + 00d47ab commit a5ec151
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 27 deletions.
24 changes: 18 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
sudo: required

services:
- docker
- docker

script: bats ./tests/test_suite.bats
#
# deploy:
# provider: script
# script: curl -H "Content-Type: application/json" --data '{"build": true}' -X POST https://registry.hub.docker.com/u/dduportal/docker-asciidoctor/trigger/${DOCKER_HUB_TOKEN}/
env:
global:
- CURRENT_GIT_BRANCH=$TRAVIS_BRANCH

script:
- make build
- make test

# 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
deploy:
- provider: script
script: make deploy
on:
condition: $TRAVIS_PULL_REQUEST = false
28 changes: 28 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

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)
ASCIIDOCTOR_VERSION ?= 1.5.6.1
ASCIIDOCTOR_PDF_VERSION ?= 1.5.0.alpha.16
CURRENT_GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)

export DOCKER_IMAGE_NAME_TO_TEST ASCIIDOCTOR_VERSION ASCIIDOCTOR_PDF_VERSION

all: build test deploy

build:
docker build \
-t $(DOCKER_IMAGE_NAME_TO_TEST) \
-f Dockerfile \
$(CURDIR)/

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

deploy:
curl -H "Content-Type: application/json" \
--data '{"source_type": "Branch", "source_name": "$(CURRENT_GIT_BRANCH)"}' \
-X POST https://registry.hub.docker.com/u/$(DOCKERHUB_USERNAME)/$(DOCKER_IMAGE_NAME)/trigger/$(DOCKER_HUB_TOKEN)/

.PHONY: all build test deploy
41 changes: 20 additions & 21 deletions tests/test_suite.bats
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#!/usr/bin/env bats

DOCKER_IMAGE_NAME="docker-asciidoctor:test"
TMP_GENERATION_DIR="${BATS_TEST_DIRNAME}/tmp"
ASCIIDOCTOR_VERSION="1.5.6.1"
ASCIIDOCTOR_PDF_VERSION="1.5.0.alpha.16"

export TMP_GENERATION_DIR="${BATS_TEST_DIRNAME}/tmp"

clean_generated_files() {
docker run -t --rm -v "${BATS_TEST_DIRNAME}:${BATS_TEST_DIRNAME}" alpine \
Expand All @@ -20,57 +19,57 @@ teardown() {
}

@test "We can build successfully the standard Docker image" {
docker build -t "${DOCKER_IMAGE_NAME}" "${BATS_TEST_DIRNAME}/../"
docker build -t "${DOCKER_IMAGE_NAME_TO_TEST}" "${BATS_TEST_DIRNAME}/../"
}

@test "asciidoctor is installed and in version ${ASCIIDOCTOR_VERSION}" {
docker run -t --rm "${DOCKER_IMAGE_NAME}" asciidoctor -v \
docker run -t --rm "${DOCKER_IMAGE_NAME_TO_TEST}" asciidoctor -v \
| grep "Asciidoctor" | grep "${ASCIIDOCTOR_VERSION}"
}

@test "asciidoctor-pdf is installed and in version ${ASCIIDOCTOR_PDF_VERSION}" {
docker run -t --rm "${DOCKER_IMAGE_NAME}" asciidoctor-pdf -v \
docker run -t --rm "${DOCKER_IMAGE_NAME_TO_TEST}" asciidoctor-pdf -v \
| grep "Asciidoctor PDF" | grep "${ASCIIDOCTOR_VERSION}" \
| grep "${ASCIIDOCTOR_PDF_VERSION}"
}

@test "asciidoctor-revealjs is callable without error" {
docker run -t --rm "${DOCKER_IMAGE_NAME}" asciidoctor-revealjs -v
docker run -t --rm "${DOCKER_IMAGE_NAME_TO_TEST}" asciidoctor-revealjs -v
}

@test "make is installed and in the path" {
docker run -t --rm "${DOCKER_IMAGE_NAME}" which make
docker run -t --rm "${DOCKER_IMAGE_NAME_TO_TEST}" which make
}

@test "asciidoctor-epub3 is installed and in the path" {
docker run -t --rm "${DOCKER_IMAGE_NAME}" which asciidoctor-epub3
docker run -t --rm "${DOCKER_IMAGE_NAME_TO_TEST}" which asciidoctor-epub3
}

@test "curl is installed and in the path" {
docker run -t --rm "${DOCKER_IMAGE_NAME}" which curl
docker run -t --rm "${DOCKER_IMAGE_NAME_TO_TEST}" which curl
}

@test "bash is installed and in the path" {
docker run -t --rm "${DOCKER_IMAGE_NAME}" which bash
docker run -t --rm "${DOCKER_IMAGE_NAME_TO_TEST}" which bash
}

@test "java is installed, in the path, and executable" {
docker run -t --rm "${DOCKER_IMAGE_NAME}" which java
docker run -t --rm "${DOCKER_IMAGE_NAME}" java -version
docker run -t --rm "${DOCKER_IMAGE_NAME_TO_TEST}" which java
docker run -t --rm "${DOCKER_IMAGE_NAME_TO_TEST}" java -version
}

@test "dot (from Graphviz) is installed and in the path" {
docker run -t --rm "${DOCKER_IMAGE_NAME}" which dot
docker run -t --rm "${DOCKER_IMAGE_NAME_TO_TEST}" which dot
}

@test "asciidoctor-confluence is installed and in the path" {
docker run -t --rm "${DOCKER_IMAGE_NAME}" which asciidoctor-confluence
docker run -t --rm "${DOCKER_IMAGE_NAME_TO_TEST}" which asciidoctor-confluence
}

@test "We can generate an HTML document from basic example" {
docker run -t --rm \
-v "${BATS_TEST_DIRNAME}":/documents/ \
"${DOCKER_IMAGE_NAME}" \
"${DOCKER_IMAGE_NAME_TO_TEST}" \
asciidoctor -D /documents/tmp -r asciidoctor-mathematical \
/documents/fixtures/basic-example.adoc
grep '<html' ${TMP_GENERATION_DIR}/*html
Expand All @@ -79,15 +78,15 @@ teardown() {
@test "We can generate a PDF document from basic example" {
docker run -t --rm \
-v "${BATS_TEST_DIRNAME}":/documents/ \
"${DOCKER_IMAGE_NAME}" \
"${DOCKER_IMAGE_NAME_TO_TEST}" \
asciidoctor-pdf -D /documents/tmp -r asciidoctor-mathematical \
/documents/fixtures/basic-example.adoc
}

@test "We can generate an HTML document with a diagram with asciidoctor-diagram as backend" {
run docker run -t --rm \
-v "${BATS_TEST_DIRNAME}":/documents/ \
"${DOCKER_IMAGE_NAME}" \
"${DOCKER_IMAGE_NAME_TO_TEST}" \
asciidoctor -D /documents/tmp -r asciidoctor-diagram \
/documents/fixtures/sample-with-diagram.adoc

Expand All @@ -103,13 +102,13 @@ teardown() {
}

@test "Bakoma Fonts are installed to render correctly the square root from asciidoctor-mathematical" {
docker run -t --rm "${DOCKER_IMAGE_NAME}" apk info font-bakoma-ttf
docker run -t --rm "${DOCKER_IMAGE_NAME_TO_TEST}" apk info font-bakoma-ttf
}

@test "We can generate an HTML document with asciidoctor-mathematical as backend" {
run docker run -t --rm \
-v "${BATS_TEST_DIRNAME}":/documents/ \
"${DOCKER_IMAGE_NAME}" \
"${DOCKER_IMAGE_NAME_TO_TEST}" \
asciidoctor -D /documents/tmp -r asciidoctor-mathematical \
/documents/fixtures/sample-with-latex-math.adoc

Expand All @@ -127,7 +126,7 @@ teardown() {
@test "We can generate a PDF document with asciidoctor-mathematical as backend" {
run docker run -t --rm \
-v "${BATS_TEST_DIRNAME}":/documents/ \
"${DOCKER_IMAGE_NAME}" \
"${DOCKER_IMAGE_NAME_TO_TEST}" \
asciidoctor-pdf -D /documents/tmp -r asciidoctor-mathematical \
/documents/fixtures/sample-with-latex-math.adoc

Expand Down

0 comments on commit a5ec151

Please sign in to comment.