Created
December 9, 2016 14:46
-
-
Save mbentley/e5f5d825c13d04eab9c762c2333fe814 to your computer and use it in GitHub Desktop.
CI Automation with UCP
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
#!/bin/bash | |
# create directory for bundle in persistent storage | |
cd /var/lib/jenkins | |
mkdir ucp-bundle | |
cd ucp-bundle | |
set -e | |
# set variables for getting client bundle | |
USERNAME="username" | |
PASSWORD="password" | |
UCP_FQDN="ucp.example.com" | |
# get auth token | |
echo -n "Retrieving auth token..." | |
AUTH_TOKEN="$(curl -sk -d '{"username":"'${USERNAME}'","password":"'${PASSWORD}'"}' https://${UCP_FQDN}/auth/login | jq -r .auth_token 2>/dev/null)" | |
# check to make sure we got a token | |
if [ -z "${AUTH_TOKEN}" ] | |
then | |
echo -e "error\nError connecting to ${UCP_FQDN}" | |
return 1 | |
fi | |
echo "done" | |
# download the client bundle | |
echo -n "Downloading client bundle for ${USERNAME}..." | |
curl -sk -H "Authorization: Bearer ${AUTH_TOKEN}" https://${UCP_FQDN}/api/clientbundle -o bundle.zip | |
echo "done" | |
# extract client bundle | |
unzip bundle.zip | |
# show the extracted client bundle | |
ls -l |
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
#!/bin/bash | |
# ^ we need to run using bash as the shell interpreter to be able to source the client bundle | |
set -e | |
set -x | |
# load client bundle from UCP | |
cd /var/lib/jenkins/ucp-bundle | |
eval $(<env.sh) | |
# go back to my jenkins workspace directory | |
cd ${WORKSPACE} | |
# update or create a docker service | |
if [ "$(docker service ls -f name=docker-demo-webapp | grep -v ^ID | awk '{print $2}' | grep ^docker-demo-webapp &>/dev/null; echo $?)" -eq "0" ] | |
then | |
echo "docker-demo-webapp service exists; updating..." | |
# update the existing docker service with the given image | |
docker service update \ | |
--image dtr-beta.demo.dckr.org/demo/docker-demo:tag \ | |
docker-demo-webapp | |
else | |
echo "service does not exist; creating..." | |
# create the docker service with the appropriate configuration and label and network to be routable using the new UCP 2.0 HTTP routing mesh | |
docker service create \ | |
-p 8080 \ | |
--replicas 4 \ | |
--update-delay 5s \ | |
--update-parallelism 2 \ | |
--update-failure-action continue \ | |
--env "TITLE=Docker Demo" \ | |
--env "DB_HOST=docker-demo-db" \ | |
--env "DB_PORT=5432" \ | |
--env "DB_USER=demo" \ | |
--env "DB_PASS=demo" \ | |
--env "DB_NAME=demo" \ | |
--env "DB_SSL_MODE=disable" \ | |
--label com.docker.ucp.access.label=docker-demo \ | |
--network docker-demo \ | |
--name docker-demo-webapp \ | |
--network ucp-hrm \ | |
--label com.docker.ucp.mesh.http=8080=http://docker-demo.betademo.dckr.org \ | |
dtr-beta.demo.dckr.org/demo/docker-demo:tag | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment