diff --git a/.gitignore b/.gitignore index 30e479a2..91400122 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .DS_Store .env .env.production +.env.staging .vscode/ node_modules/ npm-debug.log diff --git a/.travis.yml b/.travis.yml index 3de6635a..729c5e26 100644 --- a/.travis.yml +++ b/.travis.yml @@ -38,6 +38,11 @@ deploy: skip_cleanup: true on: branch: master + - provider: script + script: ./deploy-staging.sh + skip_cleanup: true + on: + branch: feature/public-api env: global: diff --git a/deploy_staging.sh b/deploy_staging.sh new file mode 100755 index 00000000..032116ff --- /dev/null +++ b/deploy_staging.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +set -e + +docker-compose build --no-cache +docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD" +docker tag $APP_IMAGE_NAME $DOCKER_USERNAME/$DOCKER_STAGING_REPOSITORY:$TRAVIS_COMMIT +docker tag $APP_IMAGE_NAME $DOCKER_USERNAME/$DOCKER_STAGING_REPOSITORY:latest +docker push $DOCKER_USERNAME/$DOCKER_STAGING_REPOSITORY:$TRAVIS_COMMIT +docker push $DOCKER_USERNAME/$DOCKER_STAGING_REPOSITORY:latest + +echo $GCLOUD_SERVICE_KEY_PRD | 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_PRD +gcloud --quiet config set container/cluster $CLUSTER_NAME_PRD +gcloud --quiet config set compute/zone ${CLOUDSDK_COMPUTE_ZONE} +gcloud --quiet container clusters get-credentials $CLUSTER_NAME_PRD + +kubectl config view +kubectl config current-context + +kubectl set image deployment/${KUBE_DEPLOYMENT_NAME} ${KUBE_DEPLOYMENT_CONTAINER_NAME}=index.docker.io/$DOCKER_USERNAME/$DOCKER_STAGING_REPOSITORY:$TRAVIS_COMMIT --namespace=staging diff --git a/kubernetes_app.yml b/kubernetes_app.yml index 7ec9fbb7..edc1cde4 100644 --- a/kubernetes_app.yml +++ b/kubernetes_app.yml @@ -118,3 +118,65 @@ spec: # - secretRef: # name: web-editor-credentials # restartPolicy: Never +--- +apiVersion: v1 +kind: Namespace +metadata: + name: staging + labels: + name: staging +--- +apiVersion: v1 +kind: Service +metadata: + name: web-editor-node + namespace: staging + labels: + app: web-editor +spec: + # if your cluster supports it, uncomment the following to automatically create + # an external load-balanced IP for the frontend service. + type: LoadBalancer + # type: NodePort + ports: + - port: 8001 + targetPort: 8000 + selector: + app: web-editor +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: web-editor-node + namespace: staging +spec: + selector: + matchLabels: + app: web-editor + replicas: 1 + template: + metadata: + labels: + app: web-editor + spec: + containers: + - name: web-editor-app + image: index.docker.io/catarak/p5.js-web-editor:latest + # temp, just to test kubernetes + # envFrom: + # - configMapRef: + # name: web-editor-env + envFrom: + - secretRef: + name: web-editor-credentials + imagePullPolicy: Always + resources: + requests: + cpu: 100m + memory: 100Mi + ports: + - containerPort: 8000 + readinessProbe: + httpGet: + path: /health + port: 8000