-
Notifications
You must be signed in to change notification settings - Fork 6
/
.gitlab-ci.yml
166 lines (146 loc) · 6.48 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
variables:
# Disable the Gradle daemon for Continuous Integration servers as correctness
# is usually a priority over speed in CI environments. Using a fresh
# runtime for each build is more reliable since the runtime is completely
# isolated from any previous builds.
GRADLE_OPTS: "-Dorg.gradle.daemon=false"
# When using dind service we need to instruct docker, to talk with the
# daemon started inside of the service. The daemon is available with
# a network connection instead of the default /var/run/docker.sock socket.
#
# The 'docker' hostname is the alias of the service container as described at
# https://docs.gitlab.com/ee/ci/docker/using_docker_images.html#accessing-the-services
#
# Note that if you're using Kubernetes executor, the variable should be set to
# tcp://localhost:2375 because of how Kubernetes executor connects services
# to the job container
DOCKER_HOST: tcp://docker:2375/
# When using dind, it's wise to use the overlayfs driver for
# improved performance.
DOCKER_DRIVER: overlay2
stages:
- frontend
- backend
- release
node:
image: circleci/node:6.11.1-browsers
stage: frontend
script: |
cd dashy
npm install
./node_modules/.bin/ng build --prod --progress false
./node_modules/.bin/ng lint
./node_modules/.bin/ng test --code-coverage --single-run --progress false
artifacts:
reports:
junit: dashy/build/junit/*.xml
paths:
- dashy/build/coverage
- dashy/dist
cache:
key: "frontend-$CI_COMMIT_REF_NAME"
paths:
- dashy/node_modules
java:
image: circleci/openjdk:8-jdk-browsers
stage: backend
services:
- docker:dind
before_script:
- export GRADLE_USER_HOME=`pwd`/.gradle
script: |
# setup docker-compose
set -x
sudo curl -L https://github.com/docker/compose/releases/download/1.16.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
# verify docker
docker version
docker info
docker-compose version
./gradlew --stacktrace --console=plain spotlessCheck
./gradlew --stacktrace --console=plain build integrationTest
# if [ "$CIRCLE_PR_NUMBER" = "" ]; then ./gradlew --stacktrace --console=plain sonarqube; else echo 'sonarqube analysis for PRs not available ATM'; fi
# sonar.login and sonar.github.oauth is needed even for PR analysis
# ./gradlew --stacktrace --console=plain sonarqube -Dsonar.analysis.mode=issues -Dsonar.github.pullRequest=$CIRCLE_PR_NUMBER -Dsonar.github.repository=$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME -Dsonar.github.oauth=$SONAR_GITHUB_OAUTH; fi
./gradlew --stacktrace --console=plain buildImage
# export build docker images
mkdir -p build/docker
docker save --output build/docker/harvester.tar reflectoring/harvester
docker save --output build/docker/quartermaster.tar reflectoring/quartermaster
docker pull mongo:3.2
docker pull openjdk:8-jdk-alpine
docker pull appropriate/curl
docker images
docker-compose up -d harvester
docker-compose up -d quartermaster
bash -c 'timeout -k 5 120 fgrep -q "waiting for connections on port" <(docker logs -f infiniboard_mongo_1)'
bash -c 'timeout -k 5 120 fgrep -q "Started HarvesterApplication in" <(docker logs -f infiniboard_harvester_1)'
bash -c 'timeout -k 5 120 fgrep -q "Started Quartermaster in" <(docker logs -f infiniboard_quartermaster_1)'
echo ">> quartermaster <<"
docker run --network container:infiniboard_quartermaster_1 appropriate/curl --retry 10 --retry-delay 1 --retry-connrefused http://localhost:8090/health
echo ">> harvester <<"
docker run --network container:infiniboard_harvester_1 appropriate/curl --retry 10 --retry-delay 1 --retry-connrefused http://localhost:9090/health
echo ">> REST API <<"
docker run --network container:infiniboard_quartermaster_1 appropriate/curl --retry 10 --retry-delay 1 --retry-connrefused http://localhost:8080/api/dashboards
echo ">> Frontend <<"
docker run --network container:infiniboard_quartermaster_1 appropriate/curl --retry 10 --retry-delay 1 --retry-connrefused http://localhost:8080/#/dashboards
echo "Running Docker containers"; docker ps -a
echo "Stopping all Docker containers"; docker stop $(docker ps -a -q)
mkdir -p build/docker-integration-test/
docker logs infiniboard_mongo_1 > build/docker-integration-test/mongo.log
docker logs infiniboard_harvester_1 > build/docker-integration-test/harvester.log
docker logs infiniboard_quartermaster_1 > build/docker-integration-test/quartermaster.log
artifacts:
reports:
junit: [harvester/build/test-results/test/*.xml, quartermaster/build/test-results/test/*.xml, packrat/build/test-results/test/*.xml]
paths:
- harvester/build/libs/harvester*.war
- quartermaster/build/libs/quartermaster*.war
- quartermaster/build/pages
- build/docker/harvester.tar
- build/docker/quartermaster.tar
- build/docker-integration-test/*.log
- packrat/build/reports/tests
- harvester/build/reports/tests
- quartermaster/build/reports/tests
cache:
key: "gradle-$CI_COMMIT_REF_NAME"
paths:
- .gradle
deploy:
stage: release
image: circleci/openjdk:8-jdk-browsers
services:
- docker:dind
before_script:
- export GRADLE_USER_HOME=`pwd`/.gradle
only:
- master
when: manual
script: |
if [ "$CI_MERGE_REQUEST_IID" = "" ]; then
# set git author info
git config --global user.name "reflectoring bot"
git config --global user.email $BOT_EMAIL
# update GitHub pages
./gradlew --stacktrace --console=plain gitPublishPush
# upload artifacts to bintray
./gradlew --stacktrace --console=plain :harvester:bintrayUpload :quartermaster:bintrayUpload
# import build docker images
docker load --input build/docker/harvester.tar
docker load --input build/docker/quartermaster.tar
# upload docker images to Docker Hub
docker login -u $DOCKER_USER -p $DOCKER_PASS
docker push reflectoring/harvester
docker push reflectoring/quartermaster
# extract release version and trim the output using awk
BASE_VERSION=$(./gradlew properties | grep -i baseVersion | cut -f 2 -d ':'|awk '{$1=$1};1')
# tag and publish the release on GitHub
./github-promote-release.sh $BASE_VERSION
else
echo 'Skipping deployment for PRs!'
fi
cache:
key: "gradle-$CI_COMMIT_REF_NAME"
paths:
- .gradle