From 66887c14e00b17c81f3ead2375c61812002c8d87 Mon Sep 17 00:00:00 2001 From: Kevin van Zonneveld Date: Wed, 29 Nov 2017 11:21:34 +0100 Subject: [PATCH] Revert "Revert "[wip] K8s (#162)"" This reverts commit a7dd6a51604080599d7ef152513f5e5f62759c8a. --- .infra/kube/00-namespace.yaml | 5 ++++ .infra/kube/deployment.yaml | 19 ++++++++++++++ .infra/kube/ingress-tls.yaml | 22 ++++++++++++++++ .infra/kube/service.yaml | 13 ++++++++++ .scripts/deploy_gcloud.sh | 47 +++++++++++++++++++++++++++++++++++ .travis.yml | 13 ++++++++++ 6 files changed, 119 insertions(+) create mode 100644 .infra/kube/00-namespace.yaml create mode 100644 .infra/kube/deployment.yaml create mode 100644 .infra/kube/ingress-tls.yaml create mode 100644 .infra/kube/service.yaml create mode 100755 .scripts/deploy_gcloud.sh diff --git a/.infra/kube/00-namespace.yaml b/.infra/kube/00-namespace.yaml new file mode 100644 index 0000000..da874a3 --- /dev/null +++ b/.infra/kube/00-namespace.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: tus + diff --git a/.infra/kube/deployment.yaml b/.infra/kube/deployment.yaml new file mode 100644 index 0000000..e170349 --- /dev/null +++ b/.infra/kube/deployment.yaml @@ -0,0 +1,19 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: tusd + namespace: tus +spec: + replicas: 1 + template: + metadata: + labels: + app: tusd + spec: + containers: + - image: docker.io/tusproject/tusd:latest + imagePullPolicy: Always + args: ["-port=8080","-behind-proxy","-max-size=1000000000"] + name: tusd + ports: + - containerPort: 8080 diff --git a/.infra/kube/ingress-tls.yaml b/.infra/kube/ingress-tls.yaml new file mode 100644 index 0000000..c2dddc2 --- /dev/null +++ b/.infra/kube/ingress-tls.yaml @@ -0,0 +1,22 @@ +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: tusd + namespace: tus + annotations: + kubernetes.io/tls-acme: "true" + kubernetes.io/ingress.class: "nginx" +spec: + tls: + - hosts: + - thesocialcactus.com + secretName: tusd-tls + rules: + - host: thesocialcactus.com + http: + paths: + - path: / + backend: + serviceName: tusd + servicePort: 80 + diff --git a/.infra/kube/service.yaml b/.infra/kube/service.yaml new file mode 100644 index 0000000..b6c6c83 --- /dev/null +++ b/.infra/kube/service.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: Service +metadata: + name: tusd + namespace: tus +spec: + ports: + - port: 80 + targetPort: 8080 + protocol: TCP + selector: + app: tusd + diff --git a/.scripts/deploy_gcloud.sh b/.scripts/deploy_gcloud.sh new file mode 100755 index 0000000..7759ab3 --- /dev/null +++ b/.scripts/deploy_gcloud.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash +set -o pipefail +set -o errexit +set -o nounset +# set -o xtrace + +# Set magic variables for current FILE & DIR +__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +__root="$(cd "$(dirname "${__dir}")" && pwd)" + +# Store the new image in docker hub +docker build --quiet -t tusproject/tusd:latest -t tusproject/tusd:$TRAVIS_COMMIT ${__root}; +docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"; +docker push tusproject/tusd:$TRAVIS_COMMIT; +docker push tusproject/tusd:latest; + +echo $GCLOUD_KEY | base64 --decode -i > ${HOME}/gcloud-service-key.json +gcloud auth activate-service-account --key-file ${HOME}/gcloud-service-key.json + +gcloud --quiet config set project $PROJECT_NAME +gcloud --quiet config set container/cluster $CLUSTER_NAME +gcloud --quiet config set compute/zone ${COMPUTE_ZONE} +gcloud --quiet container clusters get-credentials $CLUSTER_NAME + +kubectl config current-context + +helm init --service-account tiller --upgrade + +kubectl apply -f "${__root}/.infra/kube/00-namespace.yaml" +kubectl apply -f "${__root}/.infra/kube/deployment.yaml" +kubectl apply -f "${__root}/.infra/kube/service.yaml" +kubectl apply -f "${__root}/.infra/kube/ingress-tls.yaml" + +kubectl set image deployment/tusd --namespace=tus tusd=docker.io/tusproject/tusd:$TRAVIS_COMMIT + +kubectl get pods --namespace=tus +kubectl get service --namespace=tus +kubectl get deployment --namespace=tus + + +function cleanup { + printf "Cleaning up...\n" + rm -vf "${HOME}/gcloud-service-key.json" + printf "Cleaning done." +} + +trap cleanup EXIT diff --git a/.travis.yml b/.travis.yml index 769d1b5..5871433 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,7 @@ cache: directories: - $HOME/.gimme - $HOME/.frey + - "$HOME/google-cloud-sdk/" env: global: - GO15VENDOREXPERIMENT=1 @@ -25,6 +26,12 @@ script: - ./.scripts/test_all.sh before_deploy: - if [[ "$TRAVIS_TAG" != "" ]]; then ./.scripts/build_all.sh; fi +- if [ ! -d "$HOME/google-cloud-sdk/bin" ]; then rm -rf $HOME/google-cloud-sdk; curl https://sdk.cloud.google.com | bash; fi +- source /home/travis/google-cloud-sdk/path.bash.inc +- gcloud --quiet version +- gcloud --quiet components update +- gcloud --quiet components update kubectl +- curl https://raw.githubusercontent.com/kubernetes/helm/8478fb4fc723885b155c924d1c8c410b7a9444e6/scripts/get | bash deploy: - provider: releases api_key: @@ -42,3 +49,9 @@ deploy: branch: master go: 1.8 repo: tus/tusd +- provider: script + script: .scripts/deploy_gcloud.sh + on: + branch: k8s + go: 1.8 + repo: tus/tusd