-
Notifications
You must be signed in to change notification settings - Fork 1
/
.gitlab-ci.yml
101 lines (89 loc) · 3.74 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
image: docker:latest
services:
- docker:dind
variables:
DOCKER_DRIVER: overlay2
CI_DEBUG_TRACE: $CI_DEBUG_TRACE
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- ${CI_PROJECT_DIR}/webapp/node_modules
before_script:
- docker login registry.gitlab.com -u gitlab-ci-token -p $CI_BUILD_TOKEN
- 'which ssh-agent || ( apt-get install -qq openssh-client )'
- eval $(ssh-agent -s)
#
# Add the SSH key stored in SSH_PRIVATE_KEY variable to the agent store
# We're using tr to fix line endings which makes ed25519 keys work
# without extra base64 encoding.
# https://gitlab.com/gitlab-examples/ssh-private-key/issues/1#note_48526556
#
- echo "$QA_SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
#
# Create the SSH directory and give it the right permissions
#
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
- cd webapp
- echo ${CI_COMMIT_REF_SLUG}
- echo fs.inotify.max_user_watches=524288 | tee -a /etc/sysctl.conf && sysctl -p
stages:
- build
- install_dependencies
- test
- metrics
- deploy
build:
stage: build
script:
- docker build . -t registry.gitlab.com/marabesi/testable-github:$CI_COMMIT_REF_SLUG --build-arg REACT_APP_FIREBASE_JSON=$REACT_APP_FIREBASE_JSON --build-arg REACT_APP_RANKING_API=$REACT_APP_RANKING_API --build-arg REACT_APP_SHOW_SURVEY=$REACT_APP_SHOW_SURVEY --build-arg REACT_APP_SURVEY_URL=$REACT_APP_SURVEY_URL
- docker push registry.gitlab.com/marabesi/testable-github:$CI_COMMIT_REF_SLUG
install_dependencies:
stage: install_dependencies
script:
- docker run -v ${CI_PROJECT_DIR}/webapp/node_modules:/var/www/app/node_modules registry.gitlab.com/marabesi/testable-github:$CI_COMMIT_REF_SLUG npm install --legacy-peer-deps
test:
stage: test
script:
- docker pull registry.gitlab.com/marabesi/testable-github:$CI_COMMIT_REF_SLUG
- docker run -v ${CI_PROJECT_DIR}/webapp/node_modules:/var/www/app/node_modules -e REACT_APP_SURVEY_URL=$REACT_APP_SURVEY_URL registry.gitlab.com/marabesi/testable-github:$CI_COMMIT_REF_SLUG npm run test -- --ci --watchAll=false
lint_report:
stage: metrics
script:
- docker pull registry.gitlab.com/marabesi/testable-github:$CI_COMMIT_REF_SLUG
- docker run -v ${CI_PROJECT_DIR}/webapp/node_modules:/var/www/app/node_modules -v ${CI_PROJECT_DIR}/webapp/eslint:/var/www/app/eslint registry.gitlab.com/marabesi/testable-github:$CI_COMMIT_REF_SLUG npm run lint-report
artifacts:
paths:
- ${CI_PROJECT_DIR}/webapp/eslint
code_coverage:
stage: metrics
script:
- docker pull registry.gitlab.com/marabesi/testable-github:$CI_COMMIT_REF_SLUG
- docker run -v ${CI_PROJECT_DIR}/webapp/coverage:/var/www/app/coverage -e REACT_APP_SURVEY_URL=$REACT_APP_SURVEY_URL registry.gitlab.com/marabesi/testable-github:$CI_COMMIT_REF_SLUG npm run coverage
artifacts:
paths:
- ${CI_PROJECT_DIR}/webapp/coverage
deploy:
when: manual
stage: deploy
script:
- ssh $QA_SERVER_USER@$QA_SERVER_IP
- ssh $QA_SERVER_USER@$QA_SERVER_IP "docker pull registry.gitlab.com/marabesi/testable-github:${CI_COMMIT_REF_SLUG}"
- ssh $QA_SERVER_USER@$QA_SERVER_IP "docker stop testable || true && docker rm testable || true"
- |
echo -e "
ssh $QA_SERVER_USER@$QA_SERVER_IP 'docker run \
--name testable \
-e REACT_APP_FIREBASE_JSON=$REACT_APP_FIREBASE_JSON \
-e REACT_APP_RANKING_API=$REACT_APP_RANKING_API \
-e REACT_APP_SHOW_SURVEY=$REACT_APP_SHOW_SURVEY \
-e REACT_APP_SURVEY_URL=$REACT_APP_SURVEY_URL \
-d \
-p 80:5000 \
registry.gitlab.com/marabesi/testable-github:master \
npm run serve'
" | sh
- ssh $QA_SERVER_USER@$QA_SERVER_IP "docker system prune --force"
only:
- master