-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
154 lines (145 loc) · 3.54 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
image: python:3.6
stages:
- build
- test
- release
- deploy
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache"
KOZLEK_REGISTRY: registry.kozlek.net
DOCKER_IMAGE: $KOZLEK_REGISTRY/surirobot/api-emotions
test:
stage: test
before_script:
- pip install virtualenv
- virtualenv venv
- source venv/bin/activate
- pip install -r requirements.txt
script:
- pytest --cov=api
cache:
paths:
- .cache/
- venv/
except:
- schedules
- staging
- master
build_docker_image:
stage: build
image: docker:stable
services:
- docker:dind
before_script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $KOZLEK_REGISTRY
script:
- docker pull $DOCKER_IMAGE:ci || true
- docker build --cache-from $DOCKER_IMAGE:ci --tag $DOCKER_IMAGE:ci .
- docker push $DOCKER_IMAGE:ci
tags:
- docker
only:
- staging
- master
except:
- schedules
test_docker_image:
stage: test
image: docker:stable
services:
- docker:dind
before_script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $KOZLEK_REGISTRY
script:
- docker pull $DOCKER_IMAGE:ci
- docker run -e MICROSOFT_API_KEY=$MICROSOFT_API_KEY -e MICROSOFT_API_URL=$MICROSOFT_API_URL --entrypoint pytest $DOCKER_IMAGE:ci --cov=api -m "not externalapi"
tags:
- docker
only:
- staging
except:
- schedules
test_docker_image_full:
stage: test
image: docker:stable
services:
- docker:dind
before_script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $KOZLEK_REGISTRY
script:
- docker pull $DOCKER_IMAGE:ci
- docker run -e MICROSOFT_API_KEY=$MICROSOFT_API_KEY -e MICROSOFT_API_URL=$MICROSOFT_API_URL --entrypoint pytest $DOCKER_IMAGE:ci --cov=api
tags:
- docker
only:
- master
except:
- schedules
publish_docker_image:
stage: release
image: docker:stable
services:
- docker:dind
before_script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $KOZLEK_REGISTRY
script:
- docker pull $DOCKER_IMAGE:ci
- docker tag $DOCKER_IMAGE:ci $DOCKER_IMAGE:latest
- docker push $DOCKER_IMAGE:latest
tags:
- docker
only:
- master
except:
- schedules
mirror_to_github:
stage: release
script:
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
- mkdir -p ~/.ssh
- eval $(ssh-agent -s)
- ssh-add <(echo "$GITHUB_DEPLOY_KEY")
- ssh-keyscan -H github.com > ~/.ssh/known_hosts
- git remote rm github || true
- git remote add github $GITHUB_DEPLOY_URL
- git fetch github
- git push github HEAD:master --force
only:
- master
except:
- schedules
deploy_production:
stage: deploy
tags:
- deploy
script:
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
- mkdir -p ~/.ssh
- eval $(ssh-agent -s)
- echo -e "$SSH_CONFIG" > ~/.ssh/config
- ssh-add <(echo "$SSH_PRIVATE_KEY")
- pip install fabric3
- fab production deploy:docker_user=gitlab-ci-token,docker_passwd=$CI_JOB_TOKEN
cache:
paths:
- .cache/
- venv/
when: manual
only:
- master
except:
- schedules
test_externalapi:
stage: test
image: docker:stable
services:
- docker:dind
before_script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $KOZLEK_REGISTRY
script:
- docker pull $DOCKER_IMAGE:latest
- docker run -e MICROSOFT_API_KEY=$MICROSOFT_API_KEY -e MICROSOFT_API_URL=$MICROSOFT_API_URL --entrypoint pytest $DOCKER_IMAGE:ci --cov=api -m externalapi
tags:
- docker
only:
- schedules