forked from ParabolInc/parabol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcircle.yml
191 lines (173 loc) · 6.56 KB
/
circle.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
version: 2
executorType: docker
containerInfo:
- image: node:8.5.0
- image: rethinkdb:2.3.5
- image: redis:3.2.8
- image: selenium/standalone-chrome:3.6.0
experimental:
notify:
branches:
only:
- staging
stages:
build:
workDir: /home/ubuntu/action
environment:
CODECOV_TOKEN: "ebdd735e-579a-4afd-85fc-f53907544c31"
DEVOPS_REPO: "[email protected]:ParabolInc/action-devops.git"
DEVOPS_WORKDIR: "/home/ubuntu/action-devops"
GITHUB_REMOTE_DEVELOPMENT: "[email protected]:web"
GITHUB_REMOTE_PRODUCTION: "[email protected]:web"
GITHUB_REMOTE_STAGING: "[email protected]:web"
PRODUCTION_BACKUP_VOLUME: "/mnt/volume-nyc1-01/action-production"
steps:
- type: add-ssh-keys
fingerprints:
- "53:a8:37:35:c3:7e:54:f5:19:f6:8e:a1:e0:78:52:da"
- type: shell
name: Slack setup
command: |
if [ "${CIRCLE_BRANCH}" == "production" ]; then
curl --ssl -X POST -H 'Content-type: application/json' --data '{"text":"Starting CI and Deployment..."}' $SLACK_PROD_URL
elif [ "${CIRCLE_BRANCH}" == "staging" ]; then
curl --ssl -X POST -H 'Content-type: application/json' --data '{"text":"Starting CI and Deployment..."}' $SLACK_STAGING_URL
elif [ "${CIRCLE_BRANCH}" == "development" ]; then
curl --ssl -X POST -H 'Content-type: application/json' --data '{"text":"Starting CI and Deployment..."}' $SLACK_DEV_URL
fi
- type: checkout
- type: cache-restore
key: action-{{ checksum "yarn.lock" }}
- type: shell
name: Install dependencies
command: |
apt-get update && apt-get -yq install build-essential
yarn
- type: cache-save
key: action-{{ checksum "yarn.lock" }}
paths:
- /home/ubuntu/action/node_modules
- type: shell
name: Database migration (testing)
command: |
if [ "${CIRCLE_BRANCH}" == "development" ]; then
echo "info: development server deploy, skipping"
else
npm run db:migrate-testing
fi
- type: shell
name: DevOps checkout
command: |
ssh-agent $(
ssh-add -D;
ssh-add ~/.ssh/id_rsa_53a83735c37e54f519f68ea1e07852da;
git clone $DEVOPS_REPO $DEVOPS_WORKDIR
)
- type: shell
name: E2E test dependencies
command: |
if [ "${CIRCLE_BRANCH}" == "development" ]; then
echo "info: development server deploy, skipping"
else
apt-get update && apt-get -yq install unzip libnss3 libgconf-2-4
npm run test:e2e-deps
fi
- type: shell
name: E2E test build
command: |
if [ "${CIRCLE_BRANCH}" == "development" ]; then
echo "info: development server deploy, skipping"
else
cp $DEVOPS_WORKDIR/environments/e2e ./.env
npm run db:migrate
npm run build
fi
- type: shell
name: NPM lint
command: |
if [ "${CIRCLE_BRANCH}" == "development" ]; then
echo "info: development server deploy, skipping"
else
npm run lint
fi
- type: shell
name: NPM run test
command: |
if [ "${CIRCLE_BRANCH}" == "development" ]; then
echo "info: development server deploy, skipping"
else
npm run test
mkdir test-report ; mv test-report.xml test-report
fi
- type: shell
name: E2E test run
command: |
if [ "${CIRCLE_BRANCH}" == "development" ]; then
echo "info: development server deploy, skipping"
else
export SELENIUM_REMOTE_URL='http://localhost:4444/wd/hub'
npm run test:e2e
fi
- type: shell
name: Pre-build environment configuration
command: |
if [ "${CIRCLE_BRANCH}" == "production" ]; then
export DEPLOY_ENV="production"
elif [ "${CIRCLE_BRANCH}" == "staging" ]; then
export DEPLOY_ENV="staging"
elif [ "${CIRCLE_BRANCH}" == "development" ]; then
export DEPLOY_ENV="development"
else
export DEPLOY_ENV="local"
fi
cp $DEVOPS_WORKDIR/environments/$DEPLOY_ENV ./.env
- type: shell
name: Build test
command: npm run build
- type: deploy
name: Possible deployment build
command: |
if [ "${CIRCLE_BRANCH}" == "production" ]; then
export GITHUB_REMOTE="${GITHUB_REMOTE_PRODUCTION}"
elif [ "${CIRCLE_BRANCH}" == "staging" ]; then
export GITHUB_REMOTE="${GITHUB_REMOTE_STAGING}"
elif [ "${CIRCLE_BRANCH}" == "development" ]; then
export GITHUB_REMOTE="${GITHUB_REMOTE_DEVELOPMENT}"
fi
if [ -n "${GITHUB_REMOTE}" ]; then
npm run build:deploy &&
export ACTION_VERSION="\
$([[ $(grep version package.json) =~ (([0-9]+\.?){3}) ]] && \
echo ${BASH_REMATCH[1]})"
git config --global user.name "Parabol CircleCI"
git config --global user.email "[email protected]"
git add build -f
git commit -m "build $ACTION_VERSION" build
fi
- type: deploy
name: Possible (production backup) and deployment
command: |
if [ "${CIRCLE_BRANCH}" == "production" ]; then
export GITHUB_REMOTE="${GITHUB_REMOTE_PRODUCTION}"
elif [ "${CIRCLE_BRANCH}" == "staging" ]; then
export GITHUB_REMOTE="${GITHUB_REMOTE_STAGING}"
elif [ "${CIRCLE_BRANCH}" == "development" ]; then
export GITHUB_REMOTE="${GITHUB_REMOTE_DEVELOPMENT}"
fi
if [ -n "${GITHUB_REMOTE}" ]; then
git remote add dokku $GITHUB_REMOTE
export SSH_DESTINATION=$(echo $GITHUB_REMOTE | cut -f1 -d:)
ssh -o StrictHostKeyChecking=no "${SSH_DESTINATION}" -T >/dev/null
fi &&
if [ "${GITHUB_REMOTE}" == "${GITHUB_REMOTE_PRODUCTION}" ]; then
$DEVOPS_WORKDIR/dokku/rethinkdb-backup.sh \
-s "${SSH_DESTINATION}" -d "${PRODUCTION_BACKUP_VOLUME}"
fi &&
if [ -n "${GITHUB_REMOTE}" ]; then
git push -f dokku $CIRCLE_BRANCH:master
fi
- type: artifacts-store
path: /home/ubuntu/action/build
destination: build
- type: test-results-store
path: /home/ubuntu/action/test-report