Skip to content

Commit

Permalink
Merge pull request #27 from titouanfreville/issue-4-add-CI
Browse files Browse the repository at this point in the history
add CI step test-build-push-deployement
  • Loading branch information
Clément authored Mar 6, 2017
2 parents 63ef944 + e44b8e9 commit 18568f5
Show file tree
Hide file tree
Showing 2 changed files with 163 additions and 30 deletions.
47 changes: 17 additions & 30 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,35 +33,22 @@ script:
fi
done
after_success:
- >-
if [ "$TRAVIS_BRANCH" == "master" ]; then
docker login -u="$DOCKER_USER" -p="$DOCKER_PWD" $DOCKER_REGISTRY;
docker build -t go_base -f docker/gobase.Dockerfile .;
docker tag go_base $DOCKER_REGISTRY/go:base;
docker push $DOCKER_REGISTRY/go:base;
docker tag go_base $DOCKER_REGISTRY/popcubeapi:latest;
docker push $DOCKER_REGISTRY/popcubeapi:latest;
docker build -t $DOCKER_REGISTRY/popcubeapidocs:latest -f docker/docs.Dockerfile .;
docker push $DOCKER_REGISTRY/popcubeapidocs:latest;
curl -X POST --header 'Content-Type: application/json' --header "X-AUTH-TOKEN: ${DEPLOY_TOKEN}" -d '{ "Image": "registry.le-corre.eu:5000/popcubeapi:latest", "Env": [ "VIRTUAL_NETWORK=nginx-proxy", "LETSENCRYPT_HOST=api.popcube.xyz", "LETSENCRYPT_EMAIL=clement@popcube.xyz", "VIRTUAL_HOST=api.popcube.xyz", "VIRTUAL_PORT=8080" ], "Hostname": "popcube_api" }' http://${DEPLOY_URL}/deploy;
curl -X POST --header 'Content-Type: application/json' --header "X-AUTH-TOKEN: ${DEPLOY_TOKEN}" -d '{ "Image": "registry.le-corre.eu:5000/popcubeapidocs:latest", "Env": [ "VIRTUAL_NETWORK=nginx-proxy", "LETSENCRYPT_HOST=docs.popcube.xyz", "LETSENCRYPT_EMAIL=clement@popcube.xyz", "VIRTUAL_HOST=docs.popcube.xyz" ], "Hostname": "docs" }' http://${DEPLOY_URL}/deploy;
fi
- >-
if [ "$TRAVIS_BRANCH" == "development" ]; then
docker login -u="$DOCKER_USER" -p="$DOCKER_PWD" $DOCKER_REGISTRY;
docker build -t go_base -f docker/gobase.Dockerfile .;
docker tag go_base $DOCKER_REGISTRY/go:base-dev;
docker push $DOCKER_REGISTRY/go:base-dev;
docker build -t nginx_front -f docker/nginx_front.Dockerfile .;
docker tag go_base $DOCKER_REGISTRY/popcubeapi:dev;
docker push $DOCKER_REGISTRY/popcubeapi:dev;
docker build -t $DOCKER_REGISTRY/popcubeapidocs:dev -f docker/docs.Dockerfile .;
docker push $DOCKER_REGISTRY/popcubeapidocs:dev;
curl -X POST --header 'Content-Type: application/json' --header "X-AUTH-TOKEN: ${DEPLOY_TOKEN}" -d '{ "Image": "registry.le-corre.eu:5000/popcubeapi:dev", "Env": [ "VIRTUAL_NETWORK=nginx-proxy", "LETSENCRYPT_HOST=api-dev.popcube.xyz", "LETSENCRYPT_EMAIL=clement@popcube.xyz", "VIRTUAL_HOST=api-dev.popcube.xyz", "VIRTUAL_PORT=8080" ], "Hostname": "popcube_api_dev" }' http://${DEPLOY_URL}/deploy;
curl -X POST --header 'Content-Type: application/json' --header "X-AUTH-TOKEN: ${DEPLOY_TOKEN}" -d '{ "Image": "registry.le-corre.eu:5000/popcubeapidocs:dev", "Env": [ "VIRTUAL_HOST=docs-dev.popcube.xyz" ], "Hostname": "docs-dev" }' http://${DEPLOY_URL}/deploy;
fi
deploy:
# build-push develop to the staging environment
- provider: script
script: scripts/deploy.sh --branch=develop
on:
branch: develop
# build-push master to production
- provider: script
script: scripts/deploy.sh --branch=master
on:
branch: master
# build-push-deploy release to production
- provider: script
script: scripts/deploy.sh --tag=$TRAVIS_TAG --deploy=true
on:
tags: true

notifications:
slack: societyco:T1mHeYKrOtopvRjIZ68MqOQo
146 changes: 146 additions & 0 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
#!/bin/bash
#
# Popcube Release branch and deployement
# MAINTAINER - Clément LE CORRE
DEPLOY=false
REPO="registry.le-corre.eu:5000"

function usage(){
echo "Popcube Release branch and deployement"
echo ""
echo ""
echo -e "$0"
echo -e "\t-h --help"
echo -e "\t--deploy=$DEPLOY"
echo -e "\t--branch=$BRANCH"
echo -e "\t--tag=$TAG"
echo ""
}
function build_images() {
# First args is tags
docker build --no-cache -t ${REPO}/popcubedocs:$1 -f docker/slateserver.Dockerfile .
docker build --no-cache -t ${REPO}/popcubedb:$1 -f docker/database.Dockerfile .
docker build --no-cache -t ${REPO}/popcubeapi:$1 -f docker/gobase.Dockerfile .
}
function push_images() {
# First args is tags
docker push ${REPO}/popcubedocs:$1
docker push ${REPO}/popcubedb:$1
docker push ${REPO}/popcubeapi:$1
}
function deployement() {

curl -X POST --header 'Content-Type: application/json' \
--header "X-AUTH-TOKEN: ${DEPLOY_TOKEN}" -d \
"{
\"Image\": \"${REPO}/popcubedocs:$1\",
\"Env\": [
\"VIRTUAL_NETWORK=nginx-proxy\",
\"VIRTUAL_HOST=docs-alpha.popcube.xyz\",
\"VIRTUAL_PORT=4567\"
],
\"Hostname\": \"popcube_alpha_docs\" }" \
http://${DEPLOY_URL}/deploy;

curl -X POST --header 'Content-Type: application/json' \
--header "X-AUTH-TOKEN: ${DEPLOY_TOKEN}" -d \
"{
\"Image\": \"${REPO}/popcubedb:$1\",
\"Env\": [
\"MYSQL_PASSWORD=test\",
\"MYSQL_ROOT_PASSWORD=popcube_dev\",
\"MYSQL_USER=test_user\",
\"MYSQL_DATABASE=popcube_test\"
],
\"Hostname\": \"popcube_alpha_database\" }" \
http://${DEPLOY_URL}/deploy;

# API BACK
curl -X POST --header 'Content-Type: application/json' \
--header "X-AUTH-TOKEN: ${DEPLOY_TOKEN}" -d \
"{
\"Image\": \"${REPO}/popcubeapi:$1\",
\"Env\": [
\"VIRTUAL_NETWORK=nginx-proxy\",
\"VIRTUAL_HOST=alpha-api.popcube.xyz\",
\"VIRTUAL_PORT=3000\"
],
\"HostConfig\": {
\"Links\": [
\"/popcube_alpha_database:/popcube_alpha_api/database\"
]
},
\"Hostname\": \"popcube_alpha_api\" }" \
http://${DEPLOY_URL}/deploy;
}
if [ "$#" -eq 0 ]; then
usage
exit 0
fi
while [ "$1" != "" ]; do
PARAM=`echo $1 | awk -F= '{print $1}'`
VALUE=`echo $1 | awk -F= '{print $2}'`
case $PARAM in
-h | --help)
usage
exit
;;
--tag)
TAG=$VALUE
;;
--branch)
BRANCH=$VALUE
;;
--deploy)
DEPLOY=$VALUE
;;
*)
echo "ERROR: unknown parameter \"$PARAM\""
usage
exit 1
;;
esac
shift
done


if [ ${TAG+x} ] && [ ${BRANCH+x} ];
then
echo "TAG and BRANCH is not compatible :("
exit 1
fi
if [ ${TAG+x} ];
then
echo "TAG is set to '$TAG'";
build_images "$TAG"
push_images "$TAG"
elif [ ${BRANCH+x} ];
then
echo "BRANCH is set to '$BRANCH'";
if [ ${BRANCH} = "master" ];
then
echo "branch develop : OK"
build_images "master"
push_images "master"
build_images "latest"
push_images "latest"
elif [ ${BRANCH} = "develop" ];
then
echo "branch develop : OK"
build_images "dev"
push_images "dev"
else
echo "Release branch not found.."
fi
fi
if [ ${DEPLOY} = "true" ];
then
if [ ${TAG+x} ];
then
deployement "${TAG}"
else
echo "tag branch not found.."
fi
else
echo "Deployement is disable"
fi

0 comments on commit 18568f5

Please sign in to comment.