.gitlab-ci.yml 5.7 KB
Newer Older
1
2
variables:
  IMAGE_NAME: funkwhale/funkwhale
3
  IMAGE: $IMAGE_NAME:$CI_COMMIT_REF_NAME
4
  IMAGE_LATEST: $IMAGE_NAME:latest
5
  PIP_CACHE_DIR: "$CI_PROJECT_DIR/pip-cache"
6
  PYTHONDONTWRITEBYTECODE: "true"
7
8


Eliot Berriot's avatar
Attempt    
Eliot Berriot committed
9
stages:
10
  - review
11
  - lint
Eliot Berriot's avatar
Attempt    
Eliot Berriot committed
12
  - test
Eliot Berriot's avatar
Eliot Berriot committed
13
  - build
14
  - deploy
Eliot Berriot's avatar
Eliot Berriot committed
15

Eliot Berriot's avatar
Eliot Berriot committed
16
review_front:
17
18
19
20
21
  stage: review
  image: node:9
  when: manual
  allow_failure: true
  before_script:
Eliot Berriot's avatar
Eliot Berriot committed
22
23
    - curl -L -o /usr/local/bin/jq https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux64
    - chmod +x /usr/local/bin/jq
24
25
26
    - cd front
  script:
    - yarn install
27
    - yarn run i18n-compile
28
29
30
    # this is to ensure we don't have any errors in the output,
    # cf https://code.eliotberriot.com/funkwhale/funkwhale/issues/169
    - INSTANCE_URL=$REVIEW_INSTANCE_URL yarn run build | tee /dev/stderr | (! grep -i 'ERROR in')
Eliot Berriot's avatar
Eliot Berriot committed
31
32
    - mkdir -p /static/front/$CI_BUILD_REF_SLUG
    - cp -r dist/* /static/front/$CI_BUILD_REF_SLUG
33
34
35
36
37
38
  cache:
    key: "$CI_PROJECT_ID__front_dependencies"
    paths:
      - front/node_modules
      - front/yarn.lock
  environment:
Eliot Berriot's avatar
Eliot Berriot committed
39
40
41
    name: review/front-$CI_BUILD_REF_NAME
    url: http://front-$CI_BUILD_REF_SLUG.$REVIEW_DOMAIN
    on_stop: stop_front_review
42
  only:
43
    - branches
44
45
46
  tags:
    - funkwhale-review

Eliot Berriot's avatar
Eliot Berriot committed
47
stop_front_review:
48
49
  stage: review
  script:
Eliot Berriot's avatar
Eliot Berriot committed
50
    - rm -rf /static/front/$CI_BUILD_REF_SLUG/
51
52
53
  variables:
    GIT_STRATEGY: none
  when: manual
54
55
  only:
    - branches
56
  environment:
Eliot Berriot's avatar
Eliot Berriot committed
57
58
59
60
61
62
63
64
65
66
67
68
69
70
    name: review/front-$CI_BUILD_REF_NAME
    action: stop
  tags:
    - funkwhale-review

review_docs:
  stage: review
  image: python:3.6
  when: manual
  allow_failure: true
  variables:
    BUILD_PATH: "../public"
  before_script:
    - cd docs
71
72
73
74
    - apt-get update
    - apt-get install -y graphviz
    - pip install sphinx

Eliot Berriot's avatar
Eliot Berriot committed
75
76
77
78
79
80
81
82
83
84
85
86
87
  cache:
    key: "$CI_PROJECT_ID__sphinx"
    paths:
      - "$PIP_CACHE_DIR"
  script:
    - ./build_docs.sh
    - mkdir -p /static/docs/$CI_BUILD_REF_SLUG
    - cp -r $CI_PROJECT_DIR/public/* /static/docs/$CI_BUILD_REF_SLUG
  environment:
    name: review/docs-$CI_BUILD_REF_NAME
    url: http://docs-$CI_BUILD_REF_SLUG.$REVIEW_DOMAIN
    on_stop: stop_docs_review
  only:
88
    - branches
Eliot Berriot's avatar
Eliot Berriot committed
89
90
91
92
93
94
95
96
97
98
  tags:
    - funkwhale-review

stop_docs_review:
  stage: review
  script:
    - rm -rf /static/docs/$CI_BUILD_REF_SLUG/
  variables:
    GIT_STRATEGY: none
  when: manual
99
100
  only:
    - branches
Eliot Berriot's avatar
Eliot Berriot committed
101
102
  environment:
    name: review/docs-$CI_BUILD_REF_NAME
103
104
105
106
    action: stop
  tags:
    - funkwhale-review

107
108
109
black:
  image: python:3.6
  stage: lint
110
111
  variables:
    GIT_STRATEGY: fetch
112
113
114
  before_script:
    - pip install black
  script:
Eliot Berriot's avatar
Eliot Berriot committed
115
    - black --exclude "/(\.git|\.hg|\.mypy_cache|\.tox|\.venv|_build|buck-out|build|dist|migrations)/" --check --diff api/
116

Eliot Berriot's avatar
Eliot Berriot committed
117
118
119
120
121
122
123
124
flake8:
  image: python:3.6
  stage: lint
  variables:
    GIT_STRATEGY: fetch
  before_script:
    - pip install flake8
  script:
125
    - flake8 -v api
126
  cache:
Eliot Berriot's avatar
Eliot Berriot committed
127
    key: "$CI_PROJECT_ID__flake8_pip_cache"
128
129
    paths:
      - "$PIP_CACHE_DIR"
130

Eliot Berriot's avatar
Eliot Berriot committed
131
test_api:
Eliot Berriot's avatar
Eliot Berriot committed
132
133
  services:
    - postgres:9.4
Eliot Berriot's avatar
Eliot Berriot committed
134
    - redis:3
Eliot Berriot's avatar
Eliot Berriot committed
135
  stage: test
136
137
  image: funkwhale/funkwhale:latest
  cache:
Eliot Berriot's avatar
Eliot Berriot committed
138
    key: "$CI_PROJECT_ID__pip_cache"
139
140
    paths:
      - "$PIP_CACHE_DIR"
141
  variables:
142
    DJANGO_ALLOWED_HOSTS: "localhost"
Eliot Berriot's avatar
Eliot Berriot committed
143
    DATABASE_URL: "postgresql://postgres@postgres/postgres"
144
    FUNKWHALE_URL: "https://funkwhale.ci"
145
    CACHEOPS_ENABLED: "false"
Eliot Berriot's avatar
Eliot Berriot committed
146
    DJANGO_SETTINGS_MODULE: config.settings.local
147
148
  only:
    - branches
Eliot Berriot's avatar
Eliot Berriot committed
149
  before_script:
150
    - cd api
Eliot Berriot's avatar
Eliot Berriot committed
151
152
    - pip install -r requirements/base.txt
    - pip install -r requirements/local.txt
153
    - pip install -r requirements/test.txt
Eliot Berriot's avatar
Eliot Berriot committed
154
  script:
Eliot Berriot's avatar
Eliot Berriot committed
155
    - pytest --cov=funkwhale_api tests/
156
157
158
159
160
161
162
163
164
  tags:
    - docker


test_front:
  stage: test
  image: node:9
  before_script:
    - cd front
165
166
  only:
    - branches
167
168
169
  script:
    - yarn install
    - yarn run unit
170
  cache:
Eliot Berriot's avatar
Eliot Berriot committed
171
    key: "$CI_PROJECT_ID__front_dependencies"
172
    paths:
173
174
175
176
177
178
      - front/node_modules
      - front/yarn.lock
  artifacts:
    name: "front_${CI_COMMIT_REF_NAME}"
    paths:
      - front/dist/
Eliot Berriot's avatar
Eliot Berriot committed
179
  tags:
180
    - docker
Eliot Berriot's avatar
Eliot Berriot committed
181

182

Eliot Berriot's avatar
Eliot Berriot committed
183
184
build_front:
  stage: build
185
  image: node:9
Eliot Berriot's avatar
Eliot Berriot committed
186
  before_script:
Eliot Berriot's avatar
Eliot Berriot committed
187
188
    - curl -L -o /usr/local/bin/jq https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux64
    - chmod +x /usr/local/bin/jq
Eliot Berriot's avatar
Eliot Berriot committed
189
190
    - cd front
  script:
191
    - yarn install
192
    - yarn run i18n-compile
193
194
195
    # this is to ensure we don't have any errors in the output,
    # cf https://code.eliotberriot.com/funkwhale/funkwhale/issues/169
    - yarn run build | tee /dev/stderr | (! grep -i 'ERROR in')
Eliot Berriot's avatar
Eliot Berriot committed
196
    - chmod -R 750 dist
Eliot Berriot's avatar
Eliot Berriot committed
197
  cache:
Eliot Berriot's avatar
Eliot Berriot committed
198
    key: "$CI_PROJECT_ID__front_dependencies"
Eliot Berriot's avatar
Eliot Berriot committed
199
200
    paths:
      - front/node_modules
201
      - front/yarn.lock
Eliot Berriot's avatar
Eliot Berriot committed
202
203
204
205
206
  artifacts:
    name: "front_${CI_COMMIT_REF_NAME}"
    paths:
      - front/dist/
  only:
207
208
209
    - tags@funkwhale/funkwhale
    - master@funkwhale/funkwhale
    - develop@funkwhale/funkwhale
Eliot Berriot's avatar
Eliot Berriot committed
210
211
  tags:
    - docker
212

213

214
pages:
Eliot Berriot's avatar
Attempt    
Eliot Berriot committed
215
  stage: test
216
217
218
  image: python:3.6
  variables:
    BUILD_PATH: "../public"
219
220
  before_script:
    - cd docs
221
222
    - apt-get update
    - apt-get install -y graphviz
223
    - pip install sphinx
224
  script:
225
    - ./build_docs.sh
Eliot Berriot's avatar
Eliot Berriot committed
226
227
228
229
  cache:
    key: "$CI_PROJECT_ID__sphinx"
    paths:
      - "$PIP_CACHE_DIR"
230
231
232
233
  artifacts:
    paths:
      - public
  only:
234
    - develop@funkwhale/funkwhale
Eliot Berriot's avatar
Eliot Berriot committed
235
236
  tags:
    - docker
237

238
docker_release:
239
  stage: deploy
240
  before_script:
241
    - docker login -u $DOCKER_LOGIN -p $DOCKER_PASSWORD
242
    - cp -r front/dist api/frontend
243
244
    - cd api
  script:
245
246
    - docker build -t $IMAGE .
    - docker push $IMAGE
247
  only:
248
    - develop@funkwhale/funkwhale
249
    - tags@funkwhale/funkwhale
250
  tags:
251
    - docker-build
252

253
254
255
256
257
258
259
260
build_api:
  # Simply publish a zip containing api/ directory
  stage: deploy
  image: busybox
  artifacts:
    name: "api_${CI_COMMIT_REF_NAME}"
    paths:
      - api
261
262
263
  script:
    - chmod -R 750 api
    - echo Done!
264
  only:
265
266
267
    - tags@funkwhale/funkwhale
    - master@funkwhale/funkwhale
    - develop@funkwhale/funkwhale