-
Notifications
You must be signed in to change notification settings - Fork 3
/
.gitlab-ci.yml
99 lines (89 loc) · 2.72 KB
/
.gitlab-ci.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
image: pindar/gcloud-kubectl-docker:latest
# When using dind, it's wise to use the overlayfs driver for
# improved performance.
variables:
DOCKER_DRIVER: overlay
services:
- docker:dind
before_script:
- echo "$GCLOUD_GITLAB_CI_SERVICE_ACCOUNT_KEY" | base64 -d > gcloud.json
- gcloud auth activate-service-account "$GCLOUD_GITLAB_CI_SERVICE_ACCOUNT" --key-file=gcloud.json --project "$GCLOUD_PROJECT" --quiet
- export GOOGLE_APPLICATION_CREDENTIALS=$(pwd)/gcloud.json
- gcloud --quiet container clusters get-credentials $CLUSTER_NAME --zone $GCLOUD_ZONE
after_script:
# clean up
- rm -rf *
build:
stage: build
script:
- docker run -v $(pwd):/data -w /data -e NODE_ENV=development -i node:6.9-alpine /bin/sh -c "npm install && npm test && npm run-script test:coverage"
- docker run -v $(pwd):/data -w /data -e NODE_ENV=production -i node:6.9-alpine /bin/sh -c "npm prune --production"
- docker build --pull -t "$CI_REGISTRY_IMAGE:`echo $CI_BUILD_REF | head -c 8`" .
- gcloud docker -- push "$CI_REGISTRY_IMAGE:`echo $CI_BUILD_REF | head -c 8`"
except:
- tags
tag_build:
stage: build
script:
- gcloud docker -- pull "$CI_REGISTRY_IMAGE:`echo $CI_BUILD_REF | head -c 8`"
- docker tag "$CI_REGISTRY_IMAGE:`echo $CI_BUILD_REF | head -c 8`" "$CI_REGISTRY_IMAGE:${CI_BUILD_TAG}"
- gcloud docker -- push "$CI_REGISTRY_IMAGE:${CI_BUILD_TAG}"
only:
- tags
deploy_branch:
stage: deploy
script:
- chmod +x k8s/deploy.sh
- ./k8s/deploy.sh ${CI_BUILD_REF_SLUG}
- echo 'To access your environment run `kubectl proxy`'
- echo "Then access your service via http://localhost:8001/api/v1/proxy/namespaces/${CI_BUILD_REF_SLUG}/services/hello-deployment:80/"
environment:
name: review/$CI_BUILD_REF_NAME
url: http://localhost:8001/api/v1/proxy/namespaces/$CI_BUILD_REF_SLUG/services/hello-deployment:80/
on_stop: stop_review
only:
- branches
except:
- master
stop_review:
stage: deploy
variables:
GIT_STRATEGY: none
script:
- echo "Remove review app"
- kubectl delete namespaces ${CI_BUILD_REF_SLUG}
when: manual
environment:
name: review/$CI_BUILD_REF_NAME
action: stop
except:
- master
- tags
deploy_staging:
variables:
DOMAIN: ""
STAGING_ENV: "staging"
stage: deploy
script:
- chmod +x k8s/deploy.sh
- ./k8s/deploy.sh $STAGING_ENV
environment:
name: $STAGING_ENV
url: http://$STAGING_SUBDOMAIN.$DOMAIN
only:
- master
- tags
deploy_production:
variables:
DOMAIN: ""
STAGING_ENV: "production"
stage: deploy
script:
- chmod +x k8s/deploy.sh
- ./k8s/deploy.sh $STAGING_ENV
environment:
name: $STAGING_ENV
url: http://$PROD_SUBDOMAIN.$DOMAIN
when: manual
only:
- tags