From 102715e2d1112b872c333131c7f3c2fb901bb0e7 Mon Sep 17 00:00:00 2001 From: kiloreux Date: Tue, 13 Aug 2019 09:50:18 +0100 Subject: [PATCH] misc: Change cloud provider for master.tus.io (#300) * Change branch and change deployment method * Fix DA DOCKER FIIIIILE * Fix docker * Maybe just update deployment ? * Switch back to base64 * Remove useless lines and replace it by stable installation * Don't use /home/kiloreux * Added kubeconfig again * Replicate stuff * Final fixes * Avoid contacting server * remove quotes * Try again * Trigger * Use master --- .infra/kube/tusd-kube.yaml | 42 ++----------------- .scripts/{deploy_gcloud.sh => deploy_kube.sh} | 27 +++++------- .travis.yml | 8 +--- Dockerfile | 2 +- 4 files changed, 17 insertions(+), 62 deletions(-) rename .scripts/{deploy_gcloud.sh => deploy_kube.sh} (53%) diff --git a/.infra/kube/tusd-kube.yaml b/.infra/kube/tusd-kube.yaml index 35cf99f..f2d43cb 100644 --- a/.infra/kube/tusd-kube.yaml +++ b/.infra/kube/tusd-kube.yaml @@ -24,27 +24,15 @@ spec: name: tusd resources: limits: - memory: "2Gi" - # requests: - # memory: "1Gi" + memory: "1Gi" + requests: + memory: "1Gi" ports: - name: tusd-web containerPort: 8080 envFrom: - - configMapRef: - name: tusd-env - secretRef: - name: tusd-s3 - securityContext: - runAsUser: 0 - fsGroup: 0 - volumeMounts: - - name: tusd-account - mountPath: /gcs - volumes: - - name: tusd-account - secret: - secretName: gcs-account + name: tusd-env --- apiVersion: v1 kind: Service @@ -99,25 +87,3 @@ spec: backend: serviceName: tusd servicePort: 80 ---- -apiVersion: autoscaling/v1 -kind: HorizontalPodAutoscaler -metadata: - name: tusd - namespace: tus -spec: - scaleTargetRef: - apiVersion: apps/v1beta1 - kind: Deployment - name: tusd - minReplicas: 1 - maxReplicas: 5 - metrics: - - type: Resource - resource: - name: cpu - targetAverageUtilization: 80 - - type: Resource - resource: - name: memory - targetAverageValue: 1800Mi diff --git a/.scripts/deploy_gcloud.sh b/.scripts/deploy_kube.sh similarity index 53% rename from .scripts/deploy_gcloud.sh rename to .scripts/deploy_kube.sh index 612934b..abd52d6 100755 --- a/.scripts/deploy_gcloud.sh +++ b/.scripts/deploy_kube.sh @@ -8,30 +8,25 @@ set -o nounset __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" +curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl +chmod +x ./kubectl +sudo mv ./kubectl /usr/local/bin/kubectl #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 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-gke-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 +echo "Create directory..." +mkdir ${HOME}/.kube +echo "Writing KUBECONFIG to file..." +echo $KUBECONFIGVAR | python -m base64 -d > ${HOME}/.kube/config +echo "KUBECONFIG file written" sleep 10s # This cost me some precious debugging time. -kubectl apply --validate=false -f "${__root}/.infra/kube/tusd-kube.yaml" +kubectl apply -f "${__root}/.infra/kube/tusd-kube.yaml" kubectl set image deployment/tusd --namespace=tus tusd=docker.io/tusproject/tusd:$TRAVIS_COMMIT @@ -43,7 +38,7 @@ kubectl get deployment --namespace=tus function cleanup { printf "Cleaning up...\n" - rm -f ${HOME}/ca.crt + rm -f ${HOME}/.kube/config printf "Cleaning done." } diff --git a/.travis.yml b/.travis.yml index f1c94f6..a7b4f0c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,12 +27,6 @@ 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/d87ce93e1e287ece84d940dbfe09b0de493d9953/scripts/get | bash deploy: - provider: releases api_key: @@ -45,7 +39,7 @@ deploy: go: 1.12 repo: tus/tusd - provider: script - script: .scripts/deploy_gcloud.sh + script: .scripts/deploy_kube.sh on: branch: master go: 1.12 diff --git a/Dockerfile b/Dockerfile index ca0393b..1af9f27 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,7 +22,7 @@ FROM alpine:3.9 COPY --from=builder /go/bin/tusd /usr/local/bin/tusd -RUN apk add --no-cache ca-certificates jq \ +RUN apk add --no-cache ca-certificates jq gcc \ && addgroup -g 1000 tusd \ && adduser -u 1000 -G tusd -s /bin/sh -D tusd \ && mkdir -p /srv/tusd-hooks \