Skip to content

Commit

Permalink
Merge pull request #17 from autopilotpattern/shippable
Browse files Browse the repository at this point in the history
Test on shippable
  • Loading branch information
tgross authored Aug 12, 2016
2 parents 96fdd00 + b8ec61a commit ab7a495
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 61 deletions.
161 changes: 104 additions & 57 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,77 +1,124 @@
NODE_VERSION=6.0.0
JSON_VERSION=9.0.3
NODEENV_VERSION=0.13.6
TRITON_VERSION=4.11.0
DOCKER_CERT_PATH ?=
DOCKER_HOST ?=
DOCKER_TLS_VERIFY ?=
LOG_LEVEL ?= INFO
SDC_ACCOUNT ?=

ifeq ($(DOCKER_CERT_PATH),)
DOCKER_CTX := -v /var/run/docker.sock:/var/run/docker.sock
else
DOCKER_CTX := -e DOCKER_TLS_VERIFY=1 -e DOCKER_CERT_PATH=$(DOCKER_CERT_PATH:$(HOME)%=%) -e DOCKER_HOST=$(DOCKER_HOST)
endif
SHELL := /bin/bash
.PHONY: build ship test

## Display this help message
help:
@echo "'make localnode' builds and activates a local nodejs ${NODE_VERSION} environment"
@echo "under venv/ directory."
@echo
@echo "'source venv/bin/activate' to activate the virtualenv"
@echo "'deactivate' to disable the virtualenv"
@echo "'make clean' to destroy virtualenv"
@echo
@echo "'make build' to build docker environment"
@echo "'make ship' to docker push"
@awk '/^##.*$$/,/[a-zA-Z_-]+:/' $(MAKEFILE_LIST) | awk '!(NR%2){print $$0p}{p=$$0}' | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' | sort

# ------------------------------------------------
# Container builds

# we get these from shippable if available, otherwise from git
COMMIT ?= $(shell git rev-parse --short HEAD)
BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
TAG := $(BRANCH)-$(COMMIT)

## Builds the application container images
build:
docker-compose -f local-compose.yml build
docker tag workshop_nginx autopilotpattern/workshop-nginx
docker tag workshop_customers autopilotpattern/workshop-customers
docker tag workshop_sales autopilotpattern/workshop-sales
docker build -f tests/Dockerfile -t="test" .
docker build -f customers/Dockerfile -t=autopilotpattern/workshop-customers:$(TAG) customers
docker build -f sales/Dockerfile -t=autopilotpattern/workshop-sales:$(TAG) sales
docker build -f nginx/Dockerfile -t=autopilotpattern/workshop-nginx:$(TAG) nginx

## Pushes the application container images to the Docker Hub
ship:
docker push autopilotpattern/workshop-nginx
docker push autopilotpattern/workshop-customers
docker push autopilotpattern/workshop-sales

# Run tests by running the test container. Currently only runs locally
# but takes your DOCKER environment vars to use as the test runner's
# environment (ex. the test runner runs locally but starts containers
# on Triton if you're pointed to Triton)
TEST_RUN := python -m trace
ifeq ($(TRACE),)
TEST_RUN := python
endif

test:
unset DOCKER_HOST \
&& unset DOCKER_CERT_PATH \
&& unset DOCKER_TLS_VERIFY \
&& docker run --rm $(DOCKER_CTX) \
-e LOG_LEVEL=$(LOG_LEVEL) \
-e COMPOSE_HTTP_TIMEOUT=300 \
-v ${HOME}/.triton:/.triton \
-v ${HOME}/src/autopilotpattern/testing/testcases.py:/usr/lib/python2.7/site-packages/testcases.py \
-v $(shell pwd)/tests/tests.py:/src/tests.py \
-w /src test $(TEST_RUN) tests.py
docker push autopilotpattern/workshop-nginx:$(TAG)
docker push autopilotpattern/workshop-customers:$(TAG)
docker push autopilotpattern/workshop-sales:$(TAG)


# ------------------------------------------------
# Test running

LOG_LEVEL ?= INFO
KEY := ~/.ssh/TritonTestingKey

# if you pass `TRACE=1` into the call to `make` then the Python tests will
# run under the `trace` module (provides detailed call logging)
PYTHON := $(shell if [ -z ${TRACE} ]; then echo "python"; else echo "python -m trace"; fi)

# sets up the Docker context for running the build container locally
# `make test` runs in the build container on Shippable where the boot script
# will pull the source from GitHub first, but if we want to debug locally
# we'll need to mount the local source into the container.
# TODO: remove mount to ~/src/autopilotpattern/testing
LOCALRUN := \
-e PATH=/root/venv/3.5/bin:/usr/bin \
-e COMPOSE_HTTP_TIMEOUT=300 \
-w /src \
-v ~/.triton:/root/.triton \
-v ~/src/autopilotpattern/testing/testcases.py:/root/venv/3.5/lib/python3.5/site-packages/testcases.py \
-v $(shell pwd)/tests:/tests \
-v $(shell pwd)/docker-compose.yml:/docker-compose.yml \
-v $(shell pwd)/Makefile:/Makefile \
joyent/test


## Build the test running container
test-runner:
docker build -f tests/Dockerfile -t="joyent/test" .

# configure triton profile
~/.triton/profiles.d/us-sw-1.json:
{ \
cp /tmp/ssh/TritonTestingKey $(KEY) ;\
ssh-keygen -y -f $(KEY) > $(KEY).pub ;\
FINGERPRINT=$$(ssh-keygen -l -f $(KEY) | awk '{print $$2}' | sed 's/MD5://') ;\
printf '{"url": "https://us-sw-1.api.joyent.com", "name": "TritonTesting", "account": "timgross", "keyId": "%s"}' $${FINGERPRINT} > profile.json ;\
}
cat profile.json | triton profile create -f -
-rm profile.json

# TODO: replace this user w/ a user specifically for testing
## Run the build container (on Shippable) and deploy tests on Triton
test: ~/.triton/profiles.d/us-sw-1.json
cp tests/tests.py . && \
DOCKER_TLS_VERIFY=1 \
DOCKER_CERT_PATH=/root/.triton/docker/timgross@us-sw-1_api_joyent_com \
DOCKER_HOST=tcp://us-sw-1.docker.joyent.com:2376 \
COMPOSE_HTTP_TIMEOUT=300 \
PATH=/root/venv/3.5/bin:/usr/bin \
$(PYTHON) tests.py

## Run the build container locally and deploy tests on Triton.
test-local-triton: ~/.triton/profiles.d/us-sw-1.json
docker run -it --rm \
-e DOCKER_TLS_VERIFY=1 \
-e DOCKER_CERT_PATH=/root/.triton/docker/timgross@us-sw-1_api_joyent_com \
-e DOCKER_HOST=tcp://us-sw-1.docker.joyent.com:2376 \
$(LOCALRUN) $(PYTHON) tests.py


## Run the build container locally and deploy tests on local Docker too.
test-local-docker:
docker run -it --rm \
-v /var/run/docker.sock:/var/run/docker.sock \
$(LOCALRUN) $(PYTHON) tests.py

## Run the build container locally but run a Python shell
shell:
docker run -it --rm $(DOCKER_CTX) \
-e LOG_LEVEL=$(LOG_LEVEL) \
-v $(shell pwd):/src \
-w /src test python
docker run -it --rm \
-v /var/run/docker.sock:/var/run/docker.sock \
$(LOCALRUN) python


# ------------------------------------------------
# Node.js local development environment helpers

NODE_VERSION=6.0.0
JSON_VERSION=9.0.3
NODEENV_VERSION=0.13.6
TRITON_VERSION=4.11.0


## Build and activate a local Node.js environment
localnode: venv/bin/json venv/bin/triton
@echo
@echo
@echo "'source venv/bin/activate' to activate the virtualenv"
@echo "'deactivate' to disable the virtualenv"
@echo

## Destroy Node.js virtualenv
clean:
rm -rf venv

Expand Down
41 changes: 41 additions & 0 deletions shippable.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
language: none

build:
pre_ci:
- make test-runner

pre_ci_boot:
image_name: joyent/test
image_tag: latest
pull: false
options: "-e LOG_LEVEL=INFO"

# run integration tests using Docker Compose
ci:
- make build
- make test

# send the containers to the Docker Hub
on_success:
- make ship

integrations:
hub:
- integrationName: DockerHub
type: docker

key:
- integrationName: TritonTestingKey
type: ssh-key

notifications:
- integrationName: joyent-slack-blueprints
type: slack
recipients:
- "#blueprints"
branches:
only:
- master
- shippable
on_success: always
on_failure: always
23 changes: 20 additions & 3 deletions tests/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
FROM autopilotpattern/testing
COPY tests/tests.py /src
COPY docker-compose.yml /src
FROM drydock/u14pyt:prod

RUN apt-get update \
&& apt-get install -y apt-transport-https ca-certificates \
&& echo "deb https://apt.dockerproject.org/repo ubuntu-trusty main" > /etc/apt/sources.list.d/docker.list \
&& apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D \
&& apt-get update \
&& apt-get install -y nodejs git docker-engine \
&& rm -rf /var/lib/apt/lists/*

RUN npm install -g triton json

RUN git clone https://github.com/autopilotpattern/testing.git \
&& cd testing \
&& git checkout python3 \
&& . $HOME/venv/3.5/bin/activate ; pip install -r requirements.txt \
&& . $HOME/venv/3.5/bin/activate; python setup.py install

COPY tests/tests.py /src/tests.py
COPY docker-compose.yml /src/docker-compose.yml
1 change: 0 additions & 1 deletion tests/tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
import re
import time
import unittest
Expand Down

0 comments on commit ab7a495

Please sign in to comment.