* Initial kube

* Added testing docker image

* Added docker building

* Deploy the branch

* Deploy to production

* hiddent maybe

* Faster build please

* One charachter

* We need to use yaml in standard way

* Bring test back again

* Added command arguments

* Move to tus project

* Domain expired

* Added King Marius recommendation

* Added pvc

* Change branch name

* Added HPA

* Extended memory @Acconut

* Separete gcloud from kubernetes

* remove test for quicker iteration

* Remove garbage ignore

* Move back to old trusty

* Debug base64

* Remove docker build and test again base64

* Bring it back

* Wrong

* we don't need helm

* Update domain

* Increase body size

* Add long timeouts because we don't want another nginx instance

* Get the tests running again
This commit is contained in:
kiloreux 2018-01-03 13:10:44 +01:00 committed by Kevin van Zonneveld
parent ef64437ccc
commit adddcf752d
9 changed files with 170 additions and 2 deletions

View File

@ -0,0 +1,5 @@
apiVersion: v1
kind: Namespace
metadata:
name: tus

View File

@ -0,0 +1,33 @@
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
resources:
limits:
cpu: 0.7
memory: "2Gi"
requests:
cpu: 0.5
memory: "1Gi"
ports:
- containerPort: 8080
volumeMounts:
- name: tusd-disk
mountPath: /srv/tusd-data
volumes:
- name: tusd-disk
persistentVolumeClaim:
claimName: tusd

14
.infra/kube/hpa.yaml Normal file
View File

@ -0,0 +1,14 @@
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
name: tusd
namespace: tus
spec:
scaleTargetRef:
apiVersion: apps/v1beta1
kind: Deployment
name: tusd
minReplicas: 1
maxReplicas: 5
targetCPUUtilizationPercentage: 90

View File

@ -0,0 +1,27 @@
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: tusd
namespace: tus
annotations:
kubernetes.io/tls-acme: "true"
kubernetes.io/ingress.class: "nginx"
ingress.kubernetes.io/proxy-request-buffering: 'off'
ingress.kubernetes.io/proxy-body-size: '400m'
ingress.kubernetes.io/proxy-connect-timeout: "300"
ingress.kubernetes.io/proxy-send-timeout: "300"
ingress.kubernetes.io/proxy-read-timeout: "300"
spec:
tls:
- hosts:
- tusd.kiloreux.me
secretName: tusd-tls
rules:
- host: tusd.kiloreux.me
http:
paths:
- path: /
backend:
serviceName: tusd
servicePort: 80

12
.infra/kube/pvc.yaml Normal file
View File

@ -0,0 +1,12 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: tusd
namespace: tus
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 50Gi
storageClassName: standard

13
.infra/kube/service.yaml Normal file
View File

@ -0,0 +1,13 @@
apiVersion: v1
kind: Service
metadata:
name: tusd
namespace: tus
spec:
ports:
- port: 80
targetPort: 8080
protocol: TCP
selector:
app: tusd

51
.scripts/deploy_gcloud.sh Executable file
View File

@ -0,0 +1,51 @@
#!/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)"
echo "Storing ca.crt inside HOME"
echo $CA_CRT | base64 --decode -i > ${HOME}/ca.crt
echo "ca.crt is saved"
#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;
gcloud config set container/use_client_certificate True
export CLOUDSDK_CONTAINER_USE_CLIENT_CERTIFICATE=True
kubectl config set-cluster transloadit-cluster --embed-certs=true --server=${CLUSTER_ENDPOINT} --certificate-authority=${HOME}/ca.crt
kubectl config set-credentials travis --token=$SA_TOKEN
kubectl config set-context travis --cluster=$CLUSTER_NAME --user=travis --namespace=tus
kubectl config use-context travis
kubectl apply -f "${__root}/.infra/kube/pvc.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"
printf "Cleaning done."
}
trap cleanup EXIT

View File

@ -6,11 +6,14 @@ go:
- 1.8
- 1.9
sudo: required
dist: trusty
group: deprecated-2017Q4
cache:
apt: true
directories:
- $HOME/.gimme
- $HOME/.frey
- "$HOME/google-cloud-sdk/"
env:
global:
- GO15VENDOREXPERIMENT=1
@ -25,6 +28,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 +51,9 @@ deploy:
branch: master
go: 1.8
repo: tus/tusd
- provider: script
script: .scripts/deploy_gcloud.sh
on:
branch: kube
go: 1.8
repo: tus/tusd

View File

@ -16,9 +16,7 @@ RUN addgroup -g 1000 tusd \
&& GOOS=linux GOARCH=amd64 go build \
-ldflags="-X github.com/tus/tusd/cmd/tusd/cli.VersionName=${version} -X github.com/tus/tusd/cmd/tusd/cli.GitCommit=${commit} -X 'github.com/tus/tusd/cmd/tusd/cli.BuildDate=$(date --utc)'" \
-o "/go/bin/tusd" ./cmd/tusd/main.go \
&& mkdir -p /srv/tusd-data \
&& mkdir -p /srv/tusd-hooks \
&& chown tusd:tusd /srv/tusd-data \
&& rm -r /go/src/* \
&& apk del git