forked from CERT-Polska/mquery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
129 lines (108 loc) · 4.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
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
image: certpl/docker-ci-base:latest
services:
- docker:dind
stages:
- pretest
- build
- test
- deploy
before_script:
- echo "Start job $CI_BUILD_NAME" at `date +%Y-%m-%d-%H-%M-%S`
- echo "CI_PIPELINE_ID $CI_PIPELINE_ID"
- mkdir -p artifacts/test
- if command -v docker >/dev/null ; then docker info ; else echo Skipping Docker related commands on incompatible image ; fi
- if command -v docker >/dev/null ; then docker login -u $DOCKER_REGISTRY_LOGIN -p $DOCKER_REGISTRY_PASSWORD $DOCKER_REGISTRY ; fi
- if command -v ssh-agent >/dev/null ; then eval $(ssh-agent -s) ; else echo Skipping ssh-agent command on incomaptible image ; fi
- (if [ ! -z "$GIT_DEPLOY_KEY" ] ; then echo "$GIT_DEPLOY_KEY" | tr -d '\r' | ssh-add - > /dev/null ; fi)
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- echo "$VCS_SSH_KEYS" >> ~/.ssh/known_hosts
build_images:
stage: build
script:
- docker pull $DOCKER_REGISTRY/mquery_web:latest || true
- docker pull $DOCKER_REGISTRY/mquery_daemon:latest || true
- docker pull $DOCKER_REGISTRY/mquery_tests:latest || true
- (if [ ! -z "$GIT_DEPLOY_KEY" ] ; then cd src; git clone git@vcs.cert.pl:cert/mquery-plugins.git ; cat mquery-plugins/aux-config.py >> config.docker.py ; rm mquery-plugins/aux-config.py ; mv mquery-plugins/*.py metadata/ ; rm -rf mquery-plugins ; fi)
- docker build --cache-from $DOCKER_REGISTRY/mquery_web:latest -t $DOCKER_REGISTRY/mquery_web:$CI_PIPELINE_ID -t $DOCKER_REGISTRY/mquery_web:latest -t $DOCKER_REGISTRY/mquery_web:build-$CI_COMMIT_SHA -f deploy/docker/web.Dockerfile .
- docker build --cache-from $DOCKER_REGISTRY/mquery_daemon:latest -t $DOCKER_REGISTRY/mquery_daemon:$CI_PIPELINE_ID -t $DOCKER_REGISTRY/mquery_daemon:latest -t $DOCKER_REGISTRY/mquery_daemon:build-$CI_COMMIT_SHA -f deploy/docker/daemon.Dockerfile .
- docker build --cache-from $DOCKER_REGISTRY/mquery_tests:latest -t $DOCKER_REGISTRY/mquery_tests:$CI_PIPELINE_ID -t $DOCKER_REGISTRY/mquery_tests:latest -t $DOCKER_REGISTRY/mquery_tests:build-$CI_COMMIT_SHA -f src/tests/Dockerfile .
- docker images
- docker push $DOCKER_REGISTRY/mquery_web:$CI_PIPELINE_ID
- docker push $DOCKER_REGISTRY/mquery_web:build-$CI_COMMIT_SHA
- docker push $DOCKER_REGISTRY/mquery_web:latest
- docker push $DOCKER_REGISTRY/mquery_daemon:$CI_PIPELINE_ID
- docker push $DOCKER_REGISTRY/mquery_daemon:build-$CI_COMMIT_SHA
- docker push $DOCKER_REGISTRY/mquery_daemon:latest
- docker push $DOCKER_REGISTRY/mquery_tests:$CI_PIPELINE_ID
- docker push $DOCKER_REGISTRY/mquery_tests:build-$CI_COMMIT_SHA
- docker push $DOCKER_REGISTRY/mquery_tests:latest
after_script:
- docker-compose down | true
test_mquery:
stage: test
script:
- git submodule update --init --recursive
- URSADB_VERSION=$(git ls-tree $CI_COMMIT_SHA ursadb | cut -f3 "-d " | cut -f1)
- echo "URSADB_VERSION=$URSADB_VERSION"
- SECRET_KEY=$(date +%s | sha256sum | base64 | head -c 32)
- echo "SECRET_KEY=$SECRET_KEY" >> .env
- docker pull redis
- docker pull $DOCKER_REGISTRY/mquery_web:$CI_PIPELINE_ID
- docker pull $DOCKER_REGISTRY/mquery_daemon:$CI_PIPELINE_ID
- docker pull $DOCKER_REGISTRY/mquery_tests:$CI_PIPELINE_ID
- docker pull $DOCKER_REGISTRY/ursadb:build-$URSADB_VERSION
- docker tag $DOCKER_REGISTRY/mquery_web:$CI_PIPELINE_ID mquery_web:latest
- docker tag $DOCKER_REGISTRY/mquery_daemon:$CI_PIPELINE_ID mquery_daemon:latest
- docker tag $DOCKER_REGISTRY/mquery_tests:$CI_PIPELINE_ID mquery_tests:latest
- docker tag $DOCKER_REGISTRY/ursadb:build-$URSADB_VERSION mquery_ursadb:latest
- docker-compose up -d
- docker run --net mquery_default -v $(readlink -f ./samples):/mnt/samples mquery_tests
artifacts:
name: "$CI_JOB_NAME"
paths:
- artifacts/test/startup.log
when: always
expire_in: 1 week
after_script:
- docker-compose logs -t
- docker-compose logs -t > artifacts/test/startup.log
- docker-compose down | true
test_types:
stage: pretest
image: python:3.6
script:
- cp src/config.example.py src/config.py
- pip3 install mypy==0.770
- mypy src
test_style:
stage: pretest
image: python:3.6
script:
- cp src/config.example.py src/config.py
- pip3 install flake8==3.7.9
- flake8 "src/"
test_black:
stage: pretest
image: python:3.6
script:
- cp src/config.example.py src/config.py
- pip3 install black==2.0.2
- black --check "src/"
test_style_js:
stage: pretest
image: node:13
script:
- npm install -g prettier@2.0.2
- prettier --tab-width=4 --check "src/mqueryfront/src/**/*.js"
deploy_mquery:
stage: deploy
when: manual
only:
- master
environment:
name: prod
script:
- git clone "$VCS_DEPLOY_REPO_URL"
- cd "$VCS_DEPLOY_REPO_NAME"
- sh deploy_mquery.sh