-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add travis file and smoke tests for CI
- Loading branch information
1 parent
0626c59
commit f0f2b1a
Showing
6 changed files
with
649 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
sudo: required | ||
|
||
language: bash | ||
|
||
services: | ||
- docker | ||
|
||
env: | ||
- CURRENT_VERSION=$(git describe --abbrev=0 --tags) WIREMOCK_LATEST_VERSION=$(git ls-remote --tags git://github.com/tomakehurst/wiremock.git | grep -e "refs/tags/[0-9]*\." | sort -t '/' -k 3 -V | tail -1 | cut -f3 -d '/') | ||
|
||
notifications: | ||
email: false | ||
slack: | ||
secure: "a/Dj2bFQXq6UGTgirG61u9O3dA/2Zh18ckR4coBqn4/Nrutgf7XHGi66YgkHAkmvMDiY5m40n/zE7FmAYBLGzQBIE7D8FOa81qSb5WpP6lJSTAGitiPzidw1e/cZvP+rhr5Zoa0rp7hSOyGRNGJaDSF10CeZLkm2wNaSrbFreaRg972EEh7jWZhSa7YUJLdD2kdZVWYHoHEg8QKKyAag5pq/UPiwZ2uM2D6C5SxS0NpdE1MbLNE5VoU8NHGV7amX5L3sb2iK3+AvhxqoLEWdojB9DAZhuMl8s/mL8zok+xomM5i/WYidBe3GO3iRQyvs4DoHoS5/5UELNouLY/Clj/m+5OZTxbe52JpbPPPTK95S9xvVbYI9bXy1PTv3K33be9A6FKKXeAUgWvWL51TeTyAWhgO3ccTkQX4en2M1+g+WWVXxF9Zj8WbmwzXzx7q/fVTvxeZ39A/nYDz9oblOm3Ld9bpMJVfrr0vcFx5f0OZnvyB7badqWn26fskFAjlbN8K/6A6+vXv6KfxJLnUI8Nvpf49OPIxcnqTNogB0hW9ODDczr8CJMyfp5kFDENa3NDI/VCSEagQxRysURbkl7OaJyljRm21zk/kxv05homxE4cLeQpQkp7G3lIUNT7IO8RBOV/LYJOcndGN479RgkXA27hZhLgBy0l3/HSg5hvQ=" | ||
|
||
before_install: | ||
- if [ "$CURRENT_VERSION" != "$WIREMOCK_LATEST_VERSION" ]; then git checkout master && ./project.sh release prepare $WIREMOCK_LATEST_VERSION ; fi | ||
- docker build -t wiremock . | ||
- docker build -t wiremock-alpine alpine | ||
- docker build -t wiremock-hello samples/hello | ||
- docker build -t wiremock-random samples/random | ||
|
||
install: | ||
- docker run --name wiremock -d wiremock | ||
- docker run --name wiremock-args -d wiremock --https-port 8443 --verbose | ||
- docker run --name wiremock-hello -d wiremock-hello | ||
- docker run --name wiremock-random -d wiremock-random | ||
- docker run --name wiremock-alpine -d wiremock-alpine | ||
|
||
script: | ||
- ./test.sh | ||
|
||
before_deploy: | ||
- if [ "$CURRENT_VERSION" = "$WIREMOCK_LATEST_VERSION" ]; then travis_terminate; fi | ||
- docker tag wiremock-alpine rodolpheche/wiremock:$WIREMOCK_LATEST_VERSION-alpine | ||
- docker tag wiremock rodolpheche/wiremock:$WIREMOCK_LATEST_VERSION | ||
- docker tag wiremock rodolpheche/wiremock:latest | ||
- echo "$DOCKER_PASSWORD" | docker login -u "rodolpheche" --password-stdin | ||
- docker push rodolpheche/wiremock:$WIREMOCK_LATEST_VERSION-alpine | ||
- docker push rodolpheche/wiremock:$WIREMOCK_LATEST_VERSION | ||
- docker push rodolpheche/wiremock:latest | ||
- git config --local user.name "rodolpheche" | ||
- git config --local user.email "$GIT_USER_EMAIL" | ||
- git add . | ||
- git commit -m "upgrade to version $WIREMOCK_LATEST_VERSION" | ||
- git tag ${WIREMOCK_LATEST_VERSION} | ||
- git remote set-url origin https://${GITHUB_API_KEY}@github.com/rodolpheche/wiremock-docker.git | ||
- git push origin master | ||
|
||
deploy: | ||
provider: releases | ||
api_key: "${GITHUB_API_KEY}" | ||
skip_cleanup: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,278 @@ | ||
#!/bin/bash | ||
|
||
. util.sh | ||
|
||
EXECUTION_OUTPUT=/dev/null | ||
|
||
usage() { | ||
cat << EOF | ||
Usage: $0 COMMAND [-v] | ||
Wiremock Docker image project | ||
Commands: | ||
build Build classic & alpine images | ||
test Test classic & alpine images | ||
release clean Clean workspace (revert readme & Dockerfiles) | ||
release prepare Prepare release (update version in readme.md, Dockerfile & alpine/Dockerfile files) | ||
release perform Perform release (docker push & git tag/push) | ||
Args: | ||
-v verbose mode | ||
-y force yes | ||
EOF | ||
exit | ||
} | ||
|
||
build() { | ||
################# | ||
# classic image # | ||
################# | ||
|
||
CURRENT_VERSION=$(cat Dockerfile | grep "ENV WIREMOCK_VERSION" | cut -d ' ' -f 3) | ||
title "Build Wiremock Docker image $CURRENT_VERSION" | ||
|
||
message "Build classic image" | ||
docker build -t ${IMAGE_NAME} . > ${EXECUTION_OUTPUT} | ||
assert_bash_ok $? | ||
|
||
################ | ||
# alpine image # | ||
################ | ||
|
||
CURRENT_VERSION=$(cat alpine/Dockerfile | grep "ENV WIREMOCK_VERSION" | cut -d ' ' -f 3) | ||
title "Build Wiremock Docker alpine image $CURRENT_VERSION" | ||
|
||
message "Build alpine image" | ||
docker build -t ${IMAGE_NAME}-alpine alpine > ${EXECUTION_OUTPUT} | ||
assert_bash_ok $? | ||
} | ||
|
||
test() { | ||
# remove running container | ||
docker rm -f wiremock-container > ${EXECUTION_OUTPUT} 2>&1 | ||
|
||
################# | ||
# classic image # | ||
################# | ||
|
||
# version message | ||
eval $(docker run --rm ${IMAGE_NAME}-alpine env | grep WIREMOCK_VERSION) | ||
title "Test Wiremock Docker image $WIREMOCK_VERSION" | ||
|
||
# default | ||
message "Test default run" | ||
CONTAINER_ID=$(docker run -d ${IMAGE_NAME}) | ||
CONTAINER_IP=$(docker inspect -f "{{ .NetworkSettings.IPAddress }}" ${CONTAINER_ID}) | ||
sleep 1 | ||
smoke_url_ok "http://$CONTAINER_IP:8080/__admin" | ||
smoke_assert_body "mappings" | ||
docker rm -f ${CONTAINER_ID} > ${EXECUTION_OUTPUT} | ||
|
||
# wiremock args | ||
message "Test Wiremock args" | ||
CONTAINER_ID=$(docker run -d ${IMAGE_NAME} --https-port 8443) | ||
CONTAINER_IP=$(docker inspect -f "{{ .NetworkSettings.IPAddress }}" ${CONTAINER_ID}) | ||
sleep 1 | ||
smoke_url_ok "https://$CONTAINER_IP:8443/__admin" | ||
smoke_assert_body "mappings" | ||
docker rm -f ${CONTAINER_ID} > ${EXECUTION_OUTPUT} | ||
|
||
# helloworld sample | ||
message "Test helloworld sample" | ||
docker build -t wiremock-hello samples/hello > ${EXECUTION_OUTPUT} | ||
CONTAINER_ID=$(docker run -d wiremock-hello) | ||
CONTAINER_IP=$(docker inspect -f "{{ .NetworkSettings.IPAddress }}" ${CONTAINER_ID}) | ||
sleep 1 | ||
smoke_url_ok "http://$CONTAINER_IP:8080/hello" | ||
smoke_assert_body "Hello World !" | ||
docker rm -f ${CONTAINER_ID} > ${EXECUTION_OUTPUT} | ||
|
||
# extension | ||
message "Test Wiremock extension" | ||
docker build -t wiremock-random samples/random > ${EXECUTION_OUTPUT} | ||
CONTAINER_ID=$(docker run -d wiremock-random) | ||
CONTAINER_IP=$(docker inspect -f "{{ .NetworkSettings.IPAddress }}" ${CONTAINER_ID}) | ||
sleep 1 | ||
smoke_url_ok "http://$CONTAINER_IP:8080/random" | ||
smoke_assert_body "randomInteger" | ||
docker rm -f ${CONTAINER_ID} > ${EXECUTION_OUTPUT} | ||
|
||
# file permission | ||
# TODO | ||
|
||
################ | ||
# alpine image # | ||
################ | ||
|
||
# version message | ||
eval $(docker run --rm ${IMAGE_NAME}-alpine env | grep WIREMOCK_VERSION) | ||
title "Test Wiremock Docker alpine image $WIREMOCK_VERSION" | ||
|
||
# default | ||
message "Test default run" | ||
CONTAINER_ID=$(docker run -d ${IMAGE_NAME}-alpine) | ||
CONTAINER_IP=$(docker inspect -f "{{ .NetworkSettings.IPAddress }}" ${CONTAINER_ID}) | ||
sleep 1 | ||
smoke_url_ok "http://$CONTAINER_IP:8080/__admin" | ||
smoke_assert_body "mappings" | ||
docker rm -f ${CONTAINER_ID} > ${EXECUTION_OUTPUT} | ||
|
||
# wiremock args | ||
message "Test Wiremock args" | ||
CONTAINER_ID=$(docker run -d ${IMAGE_NAME}-alpine --https-port 8443) | ||
CONTAINER_IP=$(docker inspect -f "{{ .NetworkSettings.IPAddress }}" ${CONTAINER_ID}) | ||
sleep 1 | ||
smoke_url_ok "https://$CONTAINER_IP:8443/__admin" | ||
smoke_assert_body "mappings" | ||
docker rm -f ${CONTAINER_ID} > ${EXECUTION_OUTPUT} | ||
|
||
# file permission | ||
# TODO | ||
} | ||
|
||
release_clean() { | ||
title "Clean workspace" | ||
|
||
message "Revert readme.md, Dockerfile & alpine/Dockerfile files" | ||
git checkout readme.md Dockerfile alpine/Dockerfile | ||
assert_bash_ok $? | ||
} | ||
|
||
release_prepare() { | ||
title "Prepare release" | ||
|
||
if [ "$1" = "" ] | ||
then | ||
echo "You must specify a version" | ||
exit 1 | ||
fi | ||
|
||
message "Revert readme.md, Dockerfile & alpine/Dockerfile files" | ||
git checkout readme.md Dockerfile alpine/Dockerfile | ||
assert_bash_ok $? | ||
|
||
message "Fetch tags from Github" | ||
git fetch -q origin -t | ||
assert_bash_ok $? | ||
|
||
message "Fetch last git tag" | ||
LAST_VERSION=$(git describe --tag --abbrev=0) | ||
LAST_MINOR_VERSION=${LAST_VERSION%.*} | ||
NEW_VERSION=$1 | ||
NEW_MINOR_VERSION=${1%.*} | ||
assert_bash_ok $? | ||
|
||
message "Sed version in readme.md, Dockerfile & alpine/Dockerfile files" | ||
sed -i s/${LAST_VERSION}/${NEW_VERSION}/g readme.md Dockerfile alpine/Dockerfile | ||
assert_bash_ok $? | ||
|
||
message "Sed minor version in readme.md file" | ||
sed -i s/${LAST_MINOR_VERSION}/${NEW_MINOR_VERSION}/g readme.md | ||
assert_bash_ok $? | ||
} | ||
|
||
release_perform() { | ||
title "Perform release" | ||
|
||
if [ "$FORCE_YES" != "true" ] | ||
then | ||
message "${red}The Docker image will be pushed to the HUB" | ||
message "The project code will be commit, tagged & pushed to GitHub${normal}" | ||
echo | ||
read -p " Are you sure? [Y/n] "œœ -n 1 -r | ||
echo | ||
if [[ $REPLY =~ ^[^Yy]$ ]] | ||
then | ||
exit 0 | ||
fi | ||
fi | ||
|
||
# docker build | ||
|
||
build | ||
|
||
# functionnal tests | ||
|
||
test | ||
|
||
# docker tag | ||
|
||
title "Tag Wiremock Docker image $CURRENT_VERSION" | ||
message "Tag classic image" | ||
docker tag ${IMAGE_NAME} ${IMAGE_NAME}:${CURRENT_VERSION} | ||
assert_bash_ok $? | ||
|
||
title "Tag Wiremock Docker alpine image $CURRENT_VERSION" | ||
message "Tag alpine image" | ||
docker tag ${IMAGE_NAME}-alpine ${IMAGE_NAME}-alpine:${CURRENT_VERSION} | ||
assert_bash_ok $? | ||
|
||
# # docker push | ||
# | ||
# title "Push Wiremock Docker image $CURRENT_VERSION" | ||
# message "Push classic image" | ||
# docker push ${IMAGE_NAME}:${CURRENT_VERSION} | ||
# assert_bash_ok $? | ||
# | ||
# title "Push Wiremock Docker alpine image $CURRENT_VERSION" | ||
# message "Push alpine image" | ||
# docker push ${IMAGE_NAME}-alpine:${CURRENT_VERSION} | ||
# assert_bash_ok $? | ||
# | ||
# # git commit | ||
# | ||
# # git tag | ||
# | ||
# # git push (with tags) | ||
} | ||
|
||
release() { | ||
case $1 in | ||
clean|prepare|perform) | ||
release_$1 $2 | ||
;; | ||
*) | ||
usage | ||
;; | ||
esac | ||
} | ||
|
||
# args extract | ||
|
||
SHORT_OPTS="vyh" | ||
LONG_OPTS="verbose,,help" | ||
ARGS=$(getopt -o ${SHORT_OPTS} -l ${LONG_OPTS} -n "$0" -- "$@") | ||
eval set -- "${ARGS}" | ||
while true | ||
do | ||
case $1 in | ||
-y) | ||
FORCE_YES="true" | ||
;; | ||
-v|--verbose) | ||
EXECUTION_OUTPUT=/dev/stdout | ||
;; | ||
-h|--help) | ||
usage | ||
exit | ||
;; | ||
--) | ||
break | ||
;; | ||
esac | ||
shift | ||
done | ||
shift | ||
|
||
# process | ||
|
||
case $1 in | ||
build|test|release) | ||
$@ | ||
smoke_report | ||
;; | ||
*) | ||
usage | ||
;; | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.