devscripts - ae6rt/decap GitHub Wiki
Common dev scripts
In the examples below we source a common file commonrc that looks like this. Adjust the values per your cluster.
set -ux
USER=vagrant
PASSWORD=vagrant
MASTER_IP=10.245.1.2
We also use jq, which is a JSON parser tool that also formats JSON responses. It has many other uses, and is required to create the AWS resources (see the main Decap README). You should be able to install it using Homebrew.
$ jq --version
jq-1.5
Get teams
#!/bin/bash
. commonrc
curl -s -u ${USER}:${PASSWORD} -k https://${MASTER_IP}/api/v1/proxy/namespaces/decap-system/services/decap/api/v1/teams | jq .
Get projects
#!/bin/bash
. commonrc
curl -s -u ${USER}:${PASSWORD} -k https://${MASTER_IP}/api/v1/proxy/namespaces/decap-system/services/decap/api/v1/projects | jq .
Reload build-scripts
#!/bin/bash
. commonrc
curl -i -k -u ${USER}:${PASSWORD} -d "anyvalue" https://${MASTER_IP}/api/v1/proxy/namespaces/decap-system/services/decap/hooks/buildscripts
Manually execute a build
#!/bin/bash
. commonrc
curl -i -k -u ${USER}:${PASSWORD} -X POST https://${MASTER_IP}/api/v1/proxy/namespaces/decap-system/services/decap/api/v1/builds/ae6rt/hello-world-java?branch=master
Get builds on a project
#!/bin/bash
. commonrc
curl -s -u ${USER}:${PASSWORD} -k https://${MASTER_IP}/api/v1/proxy/namespaces/decap-system/services/decap/api/v1/builds/ae6rt/dynamodb-lab?since=0 | jq .
Get refs on a project
#!/bin/bash
. commonrc
curl -s -k -u ${USER}:${PASSWORD} https://${MASTER_IP}/api/v1/proxy/namespaces/decap-system/services/decap/api/v1/projects/ae6rt/hello-world-java/refs | jq .
Simulate a git-push to induce a build
#!/bin/bash
. commonrc
curl -i -k -u ${USER}:${PASSWORD} --data-binary @github-master.json -H"X-Github-Event: push" https://${MASTER_IP}/api/v1/proxy/namespaces/decap-system/services/decap/hooks/github
Adjust the github-master.json input per your needs. We use
{
"ref": "refs/heads/master",
"repository": {
"id": 35129377,
"name": "hello-world-java",
"full_name": "ae6rt/hello-world-java",
"owner": {
"name": "ae6rt",
"email": "[email protected]"
}
}
}
Tail the webapp container logs
#!/bin/bash
set -ux
kubectl --namespace=decap-system get --no-headers pods | awk '{if ($3 == "Running") { print "kubectl --namespace=decap-system logs -f " $1 " -c decap" } else { print $3 } }' | sh
The manual way of doing this is to get the decap pod name, then tail the log
$ kubectl --namespace=decap-system get pods
NAME READY STATUS RESTARTS AGE
decap-0xmhn 2/2 Running 0 13h
$ kubectl --namespace=decap-system logs -f decap-0xmhn -c decap
2015/10/05 23:17:29 main.go:36: Version: 0.1, Commit: fc620ae, Date: Mon Oct 5 05:36:17 PDT 2015, Go SDK: go version go1.5.1 darwin/amd64
2015/10/05 23:17:29 k8shelper.go:400: Successfully read secret /etc/secrets/aws-key from the filesystem
2015/10/05 23:17:29 k8shelper.go:400: Successfully read secret /etc/secrets/aws-secret from the filesystem
...
Tail a build pod log
When decap launches a build, it will log the pod name to its log
$ kubectl --namespace=decap-system logs -f decap-0xmhn -c decap
2015/10/05 23:17:29 main.go:36: Version: 0.1, Commit: fc620ae, Date: Mon Oct 5 05:36:17 PDT 2015, Go SDK: go version go1.5.1 darwin/amd64
2015/10/05 23:17:29 k8shelper.go:400: Successfully read secret /etc/secrets/aws-key from the filesystem
2015/10/05 23:17:29 k8shelper.go:400: Successfully read secret /etc/secrets/aws-secret from the filesystem
...
2015/10/06 00:39:49 k8shelper.go:227: Acquired lock on build d2951dd5-3c01-466d-a68d-066e89ed8818 with key 61653672742f64796e616d6f64622d6c61622f6d6173746572
2015/10/06 00:39:49 k8shelper.go:236: Created pod=d2951dd5-3c01-466d-a68d-066e89ed8818
Then tail this build log to watch the build in real time
$ kubectl --namespace=decap logs -f d2951dd5-3c01-466d-a68d-066e89ed8818 -c build-server
+ env
+ sort
AWS_ACCESS_KEY_ID=thekey
AWS_DEFAULT_REGION=us-west-1
AWS_SECRET_ACCESS_KEY=thesecret
BRANCH_TO_BUILD=master
BUILD_ID=d2951dd5-3c01-466d-a68d-066e89ed8818
BUILD_LOCK_KEY=61653672742f64796e616d6f64622d6c61622f6d6173746572
HOME=/root
HOSTNAME=d2951dd5-3c01-466d-a68d-066e89ed8818
KUBERNETES_PORT=tcp://10.247.0.1:443
KUBERNETES_PORT_443_TCP=tcp://10.247.0.1:443
KUBERNETES_PORT_443_TCP_ADDR=10.247.0.1
KUBERNETES_PORT_443_TCP_PORT=443
KUBERNETES_PORT_443_TCP_PROTO=tcp
KUBERNETES_SERVICE_HOST=10.247.0.1
KUBERNETES_SERVICE_PORT=443
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PROJECT_KEY=ae6rt/dynamodb-lab
PWD=/
SHLVL=1
_=/usr/bin/env
+ '[' 0 -eq 0 ']'
+ TAR=archive.tar
+ ARTIFACTS=/build-artifacts
+ WORKSPACE=/home/decap/workspace
+ CONSOLE=/tmp/console.log
++ date +%s
+ START=1444091997
+ pushd /home/decap/workspace
/home/decap/workspace /
+ sh /home/decap/buildscripts/decap-build-scripts/ae6rt/dynamodb-lab/build.sh
...
Redeploy the webapp
Presumably you have pushed a new webapp container to Dockerhub and now you want to deploy it. Because the webapp container tag is latest, and Kubernetes will by default pull any latest container when the pod starts, we can simply scale the replication controller to 0 replicas of the webapp pod, then back to 1 replicas to redeploy. This creates a new decap pod, so any commands for log tailing of the pod in your bash history will have to be updated with the new pod name.
#!/bin/bash
set -ux
kubectl --namespace=decap-system scale --replicas=0 rc decap
sleep 1
kubectl --namespace=decap-system scale --replicas=1 rc decap