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..d0be4dd --- /dev/null +++ b/.infra/kube/deployment.yaml @@ -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 diff --git a/.infra/kube/hpa.yaml b/.infra/kube/hpa.yaml new file mode 100644 index 0000000..8054eea --- /dev/null +++ b/.infra/kube/hpa.yaml @@ -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 \ No newline at end of file diff --git a/.infra/kube/ingress-tls.yaml b/.infra/kube/ingress-tls.yaml new file mode 100644 index 0000000..fc111ec --- /dev/null +++ b/.infra/kube/ingress-tls.yaml @@ -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 + diff --git a/.infra/kube/pvc.yaml b/.infra/kube/pvc.yaml new file mode 100644 index 0000000..258ca77 --- /dev/null +++ b/.infra/kube/pvc.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: tusd + namespace: tus +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 50Gi + storageClassName: standard \ No newline at end of file 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..2b3ef06 --- /dev/null +++ b/.scripts/deploy_gcloud.sh @@ -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 diff --git a/.travis.yml b/.travis.yml index 769d1b5..c5b69ba 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/Dockerfile b/Dockerfile index 1c61c03..7b7b12d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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