-
Notifications
You must be signed in to change notification settings - Fork 9
/
.travis.yml
99 lines (83 loc) · 3.31 KB
/
.travis.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
language: minimal
# easy way to get your local config: cat ${HOME}/.kube/config | base64 | pbcopy
env:
global:
# Docker variables
- DOCKER_PUBLIC_USERNAME=${DOCKER_PUBLIC_USERNAME:-openstad}
- DOCKER_IMAGE_NAME=${DOCKER_IMAGE_NAME:-api}
# Gitops variables
- HELM_REPO_NAME=${HELM_REPO_NAME:-openstad-kubernetes}
- HELM_CHART_FOLDER=${HELM_CHART_FOLDER:-k8s/openstad}
- GITOPS_RELEASE_BRANCH=${GITOPS_RELEASE_BRANCH:-master}
- GITOPS_DEV_VALUES_FILE=${GITOPS_DEV_VALUES_FILE:-k8s/openstad/environments/dev.values.yaml}
- GITOPS_ACC_VALUES_FILE=${GITOPS_ACC_VALUES_FILE:-k8s/openstad/environments/acc.values.yaml}
- GITOPS_PROD_VALUES_FILE=${GITOPS_PROD_VALUES_FILE:-k8s/openstad/environments/prod.values.yaml}
- GIT_USER_EMAIL="[email protected]"
- GIT_USER_NAME="Travis CI"
- IMAGE_TAG=${DOCKER_PUBLIC_USERNAME}/${DOCKER_IMAGE_NAME}:${TRAVIS_BUILD_ID}
# k8s variables
- K8S_DEPLOYMENT_NAME=openstad-api
- K8S_NAMESPACE=openstad
services:
- docker
addons:
snaps:
- name: yq
confinement: classic
channel: v3/stable
before_install:
- docker build -t ${DOCKER_PUBLIC_USERNAME}/${DOCKER_IMAGE_NAME}:${TRAVIS_BUILD_ID} .
script:
- docker run -e CI=true ${DOCKER_PUBLIC_USERNAME}/${DOCKER_IMAGE_NAME}:${TRAVIS_BUILD_ID} env npm run test -- --coverage
stages:
- name: docker_push
if: branch = master
- name: docker_push_tag
if: tag IS present
- name: kubectl_deploy_dev
if: env(KUBE_CONFIG) IS present AND branch = devel
- name: kubectl_deploy_acc
if: env(KUBE_CONFIG) IS present AND branch = release
- name: kubectl_deploy_prod
if: env(KUBE_CONFIG) IS present AND branch = master
- name: gitops_dev
if: env(GITOPS) IS present AND branch =~ /development|feature\/.*/
- name: gitops_acc
if: env(GITOPS) IS present AND branch =~ /staging|release|release\/.*/
- name: gitops_prod
if: env(GITOPS) IS present AND tag IS present
jobs:
include:
- stage: docker_push
name: 'Publish new docker image'
script: bash docker_publish
- stage: docker_push_tag
name: 'Push new image with tag to docker'
script: bash docker_publish_tag
- stage: kubectl_deploy_dev
name: "Deploy: Kubectl set image to DEV environment"
script: bash docker_deploy
- stage: kubectl_deploy_acc
name: "Deploy: Kubectl set image to ACC environment"
script: bash docker_deploy
- stage: kubectl_deploy_prod
name: "Deploy: Kubectl set image to PROD environment"
script: bash docker_deploy
- stage: gitops_dev
name: "Release and commit new image tag to DEV environment"
env:
- IMAGE_TAG=${DOCKER_PUBLIC_USERNAME}/${DOCKER_IMAGE_NAME}:${TRAVIS_BUILD_ID}
- GITOPS_VALUES_FILE=${GITOPS_DEV_VALUES_FILE}
script: bash gitops_push
- stage: gitops_acc
name: "Release and commit new image tag to ACC environment"
env:
- IMAGE_TAG=${DOCKER_PUBLIC_USERNAME}/${DOCKER_IMAGE_NAME}:${TRAVIS_BUILD_ID}
- GITOPS_VALUES_FILE=${GITOPS_ACC_VALUES_FILE}
script: bash gitops_push
- stage: gitops_prod
name: "Release and commit new image tag to PROD environment"
env:
- IMAGE_TAG=${DOCKER_PUBLIC_USERNAME}/${DOCKER_IMAGE_NAME}:${TRAVIS_TAG}
- GITOPS_VALUES_FILE=${GITOPS_PROD_VALUES_FILE}
script: bash gitops_push