-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
149 lines (136 loc) · 3.86 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
cache:
untracked: true
key: $CI_COMMIT_REF_NAME
paths:
- .yarn-cache/
variables:
# From the docs: https://docs.gitlab.com/ee/ci/yaml/#git-strategy
# „fetch is faster as it re-uses the project workspace (falling back
# to clone if it doesn't exist). git clean is used to undo any changes
# made by the last job, and git fetch is used to retrieve commits
# made since the last job ran.“
GIT_STRATEGY: fetch
# https://medium.com/@gajus/making-docker-in-docker-builds-x2-faster-using-docker-cache-from-option-c01febd8ef84
# The 'latest' image. Used as a base to cache from
# when building the $BUILD_IMAGE.
SERVICE_NAME: blockchain-watcher
SERVER_HOSTNAME: brickblock-cloud.io
stages:
- setup
- test
- deploy
before_script:
- eval export REGISTRY_URL="eu.gcr.io/sonorous-cacao-185213/$SERVICE_NAME"
- eval export SHORT_GIT_SHA=$(git rev-parse --short HEAD)
- eval export SANITIZED_BRANCH_NAME=$(echo $CI_COMMIT_REF_NAME | sed -e "s/\//-/g")
# The image tag of this build
- eval export BUILD_IMAGE=${REGISTRY_URL}:${SANITIZED_BRANCH_NAME}-${SHORT_GIT_SHA}
- eval export CACHE_TAG=${REGISTRY_URL}:cache
# The fqdn of the gitlab server is not available in the standard env vars so we cut it out of this URL
- eval export GITLAB_HOSTNAME=$(echo $CI_PROJECT_URL | awk -F/ '{print $3}')
#########
# SETUP #
#########
setup:
tags:
- google
stage: setup
cache:
key: $CI_COMMIT_REF_NAME
paths:
- node_modules/
artifacts:
expire_in: 3d
paths:
- node_modules
script:
- yarn install --pure-lockfile --cache-folder .yarn-cache
#########
# TESTS #
#########
flow:
tags:
- google
stage: test
cache:
policy: pull
script:
- yarn flow
test:
tags:
- google
stage: test
cache:
policy: pull
script:
- yarn test
#########
# BUILD #
#########
build:
tags:
- google
stage: test
cache:
policy: pull
script:
- yarn build
# TODO: We do this `yarn install:prod` here because in .dockerignore "node_modules" is not listed
# This is only due to @brickblock/smart-contracts being a closed source npm package that is
# needed for production build. Once this is open sourced, we can `yarn install:prod` in the Dockerfile
- yarn install:prod
- gcloud docker --authorize-only
- docker build
--pull
--tag $BUILD_IMAGE
--cache-from $CACHE_TAG
.
# Push container to GitLab docker registry
- docker push $BUILD_IMAGE
- docker tag $BUILD_IMAGE $CACHE_TAG
- docker push $CACHE_TAG
###########
# STAGING #
###########
deploy-staging:
tags:
- google
stage: deploy
environment:
name: staging
only:
- master
variables:
CONTRACT_ADDRESS: "0xcbf23082233ebf2b97a986b4d05669472d744e3c"
CONTRACT_DEPLOYED_AT_BLOCK: "2080918"
KUBERNETES_REPLICAS: 1
POSTGRES_INSTANCE: sonorous-cacao-185213:europe-west1:testing-blockchain-watcher
cache:
policy: pull
script:
- git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@${GITLAB_HOSTNAME}/infrastructure/infra.git
- /bin/sh $(pwd)/infra/k8s/deploy.sh staging-${SERVICE_NAME} with-postgres
##############
# PRODUCTION #
##############
deploy-production:
tags:
- google
stage: deploy
environment:
name: production
cache:
policy: pull
variables:
CONTRACT_ADDRESS: "0x0000000000000000000000000000000000000000"
CONTRACT_DEPLOYED_AT_BLOCK: "2080918"
KUBERNETES_REPLICAS: 1
POSTGRES_INSTANCE: sonorous-cacao-185213:europe-west1:production-blockchain-watcher
script:
- git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@${GITLAB_HOSTNAME}/infrastructure/infra.git
- /bin/sh $(pwd)/infra/k8s/deploy.sh production-${SERVICE_NAME} with-postgres
# These two 'onlys' give us AND logic. The commit should both be in master AND be tagged. NB. this is git tagging. not 'gitlab' tagging.
only:
- master
only:
- tags