Skip to content

Instantly share code, notes, and snippets.

@theraaz
Created July 13, 2019 15:40
Show Gist options
  • Save theraaz/35cb8e593b8bc3fffd0f8119faf34c45 to your computer and use it in GitHub Desktop.
Save theraaz/35cb8e593b8bc3fffd0f8119faf34c45 to your computer and use it in GitHub Desktop.
Kubernetes + Travis CI/CD with DigitalOcean - https://medium.com/p/c0c4058b7734
# Use Dockerized infrastructure
sudo: false
language: generic
cache:
bundler: true
git:
depth: 10
node_js:
- "9"
services:
- docker
# only whitelisting these branches for branch-update, so that if any update or PR
# merged in these branches then build otherwise ignore pushes to same branches
# https://stackoverflow.com/q/31882306/2037323
branches:
only:
- development
- production
- master
before_install:
# we'll use Platform repo to hold Raz Platform wide common configs etc
- sudo service mysql stop
- pip install --user awscli
- export PATH=$PATH:$HOME/.local/bin
- export IMAGE_NAME=raz4/raz4api
- export REPO_URL=123.dkr.ecr.eu-west-2.amazonaws.com # your AWS ECR repo
- export GIT_REPO_NAME=$(echo $TRAVIS_REPO_SLUG | grep -oE "[^/]+$")
- export GIT_SHA_TS=$(git log -1 --format=%ai)
- export GIT_SHA=$(git rev-parse HEAD)
# i use a separate repo for secrets and config for all the projects
- git clone https://$GITHUB_TOKEN@github.com/username/repo.git ../Platform
install:
- eval $(aws ecr get-login --region eu-west-2 --no-include-email)
- sudo apt-get update && sudo apt-get -y install gettext-base
# - docker pull $REPO_URL/$IMAGE_NAME:latest
- docker-compose -f ./dev/docker-compose.yml up --remove-orphans -d
- docker build --build-arg GIT_SHA=$GIT_SHA --build-arg GIT_SHA_TS="$GIT_SHA_TS" -t $REPO_URL/$IMAGE_NAME:latest .
- docker tag $REPO_URL/$IMAGE_NAME:latest $REPO_URL/$IMAGE_NAME:$TRAVIS_COMMIT
- docker tag $REPO_URL/$IMAGE_NAME:latest $REPO_URL/$IMAGE_NAME:$TRAVIS_BRANCH
script:
# next two lines optional. I'm running my tests here
- docker run --env-file ./dev/.test.env --net dev_raz_test_network $REPO_URL/$IMAGE_NAME npm run lint || travis_terminate 1
- docker run --env-file ./dev/.test.env -e CODECOV_TOKEN=$CODECOV_TOKEN --net dev_raz_test_network $REPO_URL/$IMAGE_NAME npm run test:cov || travis_terminate 1
- docker push $REPO_URL/$IMAGE_NAME:latest
- docker push $REPO_URL/$IMAGE_NAME:$TRAVIS_COMMIT
- docker push $REPO_URL/$IMAGE_NAME:$TRAVIS_BRANCH
- cp -r ../Platform/k8s/. ../$GIT_REPO_NAME/dev
deploy:
skip_cleanup: true
provider: script
script: ./dev/ci-deploy.sh
on:
all_branches: true
condition: $TRAVIS_BRANCH =~ ^development|master|production$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment