Last active
October 15, 2019 10:23
-
-
Save JacopoDaeli/ea640f2bf2e300c08bc06cbbea351c85 to your computer and use it in GitHub Desktop.
TravisCI setup example for CI pipeline
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Use Dockerized infrastructure | |
sudo: false | |
# Use node_js environnement | |
language: node_js | |
node_js: | |
- "6" | |
# Cache Gcloud SDK between commands | |
cache: | |
directories: | |
- "$HOME/google-cloud-sdk/" | |
# Install services | |
services: | |
- docker | |
# Set env vars | |
env: | |
global: | |
- GOOGLE_APPLICATION_CREDENTIALS=~/gcloud-service-key.json | |
- PROJECT_NAME_STG=<YOUR_PROJECT_NAME> | |
- CLUSTER_NAME_STG=<YOUR_CLUSTER_NAME> | |
- PROJECT_NAME_PRD=<YOUR_PROJECT_NAME> | |
- CLUSTER_NAME_PRD=<YOUR_CLUSTER_NAME> | |
- CLOUDSDK_COMPUTE_ZONE=<YOUR_GCLOUD_COMPUTE_ZONE> | |
- DOCKER_IMAGE_NAME=appexample | |
- KUBE_DEPLOYMENT_NAME=appexample | |
- KUBE_DEPLOYMENT_CONTAINER_NAME=appexample | |
- NODE_ENV=CI | |
install: | |
- npm install | |
script: | |
- npm test | |
before_deploy: | |
- if [ ! -d "$HOME/google-cloud-sdk/bin" ]; then rm -rf $HOME/google-cloud-sdk; export CLOUDSDK_CORE_DISABLE_PROMPTS=1; 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 beta update | |
- gcloud --quiet components update kubectl | |
deploy: | |
- provider: script | |
script: ./deploy-staging.sh | |
skip_cleanup: true | |
on: | |
branch: development | |
- provider: script | |
script: ./deploy-production.sh | |
skip_cleanup: true | |
on: | |
branch: master |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
docker build -t gcr.io/${PROJECT_NAME_PRD}/${DOCKER_IMAGE_NAME}:$TRAVIS_COMMIT . | |
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 | |
gcloud docker push gcr.io/${PROJECT_NAME_PRD}/${DOCKER_IMAGE_NAME} | |
yes | gcloud beta container images add-tag gcr.io/${PROJECT_NAME_PRD}/${DOCKER_IMAGE_NAME}:$TRAVIS_COMMIT gcr.io/${PROJECT_NAME_PRD}/${DOCKER_IMAGE_NAME}:latest | |
kubectl config view | |
kubectl config current-context | |
kubectl set image deployment/${KUBE_DEPLOYMENT_NAME} ${KUBE_DEPLOYMENT_CONTAINER_NAME}=gcr.io/${PROJECT_NAME_PRD}/${DOCKER_IMAGE_NAME}:$TRAVIS_COMMIT | |
# sleep 30 | |
# npm run e2e_test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
docker build -t gcr.io/${PROJECT_NAME_STG}/${DOCKER_IMAGE_NAME}:$TRAVIS_COMMIT . | |
echo $GCLOUD_SERVICE_KEY_STG | 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_STG | |
gcloud --quiet config set container/cluster $CLUSTER_NAME_STG | |
gcloud --quiet config set compute/zone ${CLOUDSDK_COMPUTE_ZONE} | |
gcloud --quiet container clusters get-credentials $CLUSTER_NAME_STG | |
gcloud docker push gcr.io/${PROJECT_NAME_STG}/${DOCKER_IMAGE_NAME} | |
yes | gcloud beta container images add-tag gcr.io/${PROJECT_NAME_STG}/${DOCKER_IMAGE_NAME}:$TRAVIS_COMMIT gcr.io/${PROJECT_NAME_STG}/${DOCKER_IMAGE_NAME}:latest | |
kubectl config view | |
kubectl config current-context | |
kubectl set image deployment/${KUBE_DEPLOYMENT_NAME} ${KUBE_DEPLOYMENT_CONTAINER_NAME}=gcr.io/${PROJECT_NAME_STG}/${DOCKER_IMAGE_NAME}:$TRAVIS_COMMIT | |
# sleep 30 | |
# npm run e2e_test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment