-
Notifications
You must be signed in to change notification settings - Fork 48
/
.gitlab-ci.yml
76 lines (68 loc) · 1.99 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
cache:
key: "${CI_BUILD_REF_NAME} node:8-alpine"
paths:
- node_modules/
stages:
- test
- release
- deploy
test:
stage: test
image: node:8-alpine
variables:
NODE_ENV: "development"
DATABASE_TEST_URL: "mongodb://mongo/FeathersVueTest"
services:
- mongo
before_script:
- apk add --update bash
- apk add --update git && rm -rf /tmp/* /var/cache/apk/*
- npm install
script:
- npm run build
- export NODE_ENV=test
- npm run test
artifacts:
paths:
- server/
- public/
release:
stage: release
image: docker:latest
only:
- "feathers-2"
- "master"
services:
- docker:dind
variables:
DOCKER_DRIVER: "overlay"
before_script:
- docker version
- "docker info"
- "docker login -u $CI_REGISTRY_USER -p $CI_BUILD_TOKEN $CI_REGISTRY"
script:
- "docker build -t ${CI_REGISTRY}/${CI_PROJECT_PATH}:latest -f Dockerfile-production ."
- "docker push ${CI_REGISTRY}/${CI_PROJECT_PATH}:latest"
after_script:
- "docker logout ${CI_REGISTRY}"
deploy:
stage: deploy
image: gitlab/dind:latest
only:
- "feathers-2"
- "master"
environment: production
services:
- docker:dind
before_script:
- mkdir -p ~/.ssh
- echo "$DEPLOY_SERVER_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
- eval "$(ssh-agent -s)"
- ssh-add ~/.ssh/id_rsa
- ssh-keyscan -H $DEPLOY_SERVER_IP >> ~/.ssh/known_hosts
script:
- printf "DATABASE_URL=${DATABASE_URL}\nPORT=80\nGMAIL=$GMAIL\nGMAIL_PASSWORD=$GMAIL_PASSWORD\nFEATHERS_AUTH_SECRET=$FEATHERS_AUTH_SECRET" > environment.env
- printf "LETS_ENCRYPT_EMAIL=${LETS_ENCRYPT_EMAIL}\nLETS_ENCRYPT_DOMAIN=${LETS_ENCRYPT_DOMAIN}" > .env
- scp -r environment.env .env production.yml root@${DEPLOY_SERVER_IP}:~/
- ssh root@$DEPLOY_SERVER_IP "docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY}; env $(cat .env | grep ^[A-Z] | xargs) docker stack deploy -c production.yml --with-registry-auth $STACK_NAME"