.gitlab-ci.yml 9.17 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
6
  ALL_IN_ONE_IMAGE_NAME: funkwhale/all-in-one
  ALL_IN_ONE_IMAGE: $ALL_IN_ONE_IMAGE_NAME:$CI_COMMIT_REF_NAME
7
  ALL_IN_ONE_IMAGE_LATEST: $ALL_IN_ONE_IMAGE_NAME:latest
8
  PIP_CACHE_DIR: "$CI_PROJECT_DIR/pip-cache"
9
  PYTHONDONTWRITEBYTECODE: "true"
ButterflyOfFire's avatar
ButterflyOfFire committed
10
11
  REVIEW_DOMAIN: preview.funkwhale.audio
  REVIEW_INSTANCE_URL: https://demo.funkwhale.audio
12

Eliot Berriot's avatar
Attempt    
Eliot Berriot committed
13
stages:
14
  - review
15
  - lint
Eliot Berriot's avatar
Eliot Berriot committed
16
  - build
17
  - test
18
  - deploy
19
  - deps
Eliot Berriot's avatar
Eliot Berriot committed
20

Eliot Berriot's avatar
Eliot Berriot committed
21
review_front:
Eliot Berriot's avatar
Eliot Berriot committed
22
  interruptible: true
23
  stage: review
24
  image: node:12-buster
25
26
  when: manual
  allow_failure: true
27
28
29
30
  variables:
    BASE_URL: /-/$CI_PROJECT_NAME/-/jobs/$CI_JOB_ID/artifacts/front-review/
    VUE_APP_ROUTER_BASE_URL: /-/$CI_PROJECT_NAME/-/jobs/$CI_JOB_ID/artifacts/front-review/
    VUE_APP_INSTANCE_URL: $REVIEW_INSTANCE_URL
31
  before_script:
Eliot Berriot's avatar
Eliot Berriot committed
32
33
    - 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
34
35
    - rm -rf front-review
    - mkdir front-review
36
37
38
    - cd front
  script:
    - yarn install
39
    - yarn run i18n-compile
40
    # this is to ensure we don't have any errors in the output,
Eliot Berriot's avatar
Eliot Berriot committed
41
    # cf https://dev.funkwhale.audio/funkwhale/funkwhale/issues/169
42
43
44
45
46
47
    - yarn run build | tee /dev/stderr | (! grep -i 'ERROR in')
    - cp -r dist/* ../front-review
  artifacts:
    expire_in: 2 weeks
    paths:
      - front-review
48
  cache:
ButterflyOfFire's avatar
ButterflyOfFire committed
49
    key: "funkwhale__front_dependencies"
50
51
52
53
    paths:
      - front/node_modules
      - front/yarn.lock
  only:
54
    - branches
55
  tags:
56
    - docker
Eliot Berriot's avatar
Eliot Berriot committed
57
  environment:
58
59
    name: review/front/$CI_COMMIT_REF_NAME
    url: http://$CI_PROJECT_NAMESPACE.pages.funkwhale.audio/-/$CI_PROJECT_NAME/-/jobs/$CI_JOB_ID/artifacts/front-review/index.html
Eliot Berriot's avatar
Eliot Berriot committed
60

Eliot Berriot's avatar
Eliot Berriot committed
61
review_docs:
Eliot Berriot's avatar
Eliot Berriot committed
62
  interruptible: true
Eliot Berriot's avatar
Eliot Berriot committed
63
64
65
66
67
68
69
70
71
72
73
74
  stage: review
  when: manual
  allow_failure: true
  image: python:3.6
  variables:
    BUILD_PATH: "../docs-review"
  before_script:
    - rm -rf docs-review
    - mkdir docs-review
    - cd docs
    - apt-get update
    - apt-get install -y graphviz
Agate's avatar
Agate committed
75
    - pip install sphinx sphinx_rtd_theme django-environ django
Eliot Berriot's avatar
Eliot Berriot committed
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
  script:
    - ./build_docs.sh
  cache:
    key: "$CI_PROJECT_ID__sphinx"
    paths:
      - "$PIP_CACHE_DIR"
  artifacts:
    expire_in: 2 weeks
    paths:
      - docs-review
  only:
    - branches
  tags:
    - docker
  environment:
    name: review/docs/$CI_COMMIT_REF_NAME
    url: http://$CI_PROJECT_NAMESPACE.pages.funkwhale.audio/-/$CI_PROJECT_NAME/-/jobs/$CI_JOB_ID/artifacts/docs-review/index.html

94
black:
Eliot Berriot's avatar
Eliot Berriot committed
95
  interruptible: true
96
97
  image: python:3.6
  stage: lint
98
99
  variables:
    GIT_STRATEGY: fetch
100
  before_script:
Agate's avatar
Agate committed
101
    - pip install black==19.10b0
102
  script:
Eliot Berriot's avatar
Eliot Berriot committed
103
    - black --check --diff api/
104

Eliot Berriot's avatar
Eliot Berriot committed
105
flake8:
Eliot Berriot's avatar
Eliot Berriot committed
106
  interruptible: true
Eliot Berriot's avatar
Eliot Berriot committed
107
108
109
110
111
  image: python:3.6
  stage: lint
  variables:
    GIT_STRATEGY: fetch
  before_script:
Agate's avatar
Agate committed
112
    - pip install 'flake8<3.7'
Eliot Berriot's avatar
Eliot Berriot committed
113
  script:
114
    - flake8 -v api
115
  cache:
Eliot Berriot's avatar
Eliot Berriot committed
116
    key: "$CI_PROJECT_ID__flake8_pip_cache"
117
118
    paths:
      - "$PIP_CACHE_DIR"
119

Eliot Berriot's avatar
Eliot Berriot committed
120
test_api:
Eliot Berriot's avatar
Eliot Berriot committed
121
  interruptible: true
Eliot Berriot's avatar
Eliot Berriot committed
122
  services:
123
    - postgres:11
124
    - redis:5
Eliot Berriot's avatar
Eliot Berriot committed
125
  stage: test
126
  image: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
127
  cache:
Eliot Berriot's avatar
Eliot Berriot committed
128
    key: "$CI_PROJECT_ID__pip_cache"
129
130
    paths:
      - "$PIP_CACHE_DIR"
131
  variables:
Eliot Berriot's avatar
Eliot Berriot committed
132
    DATABASE_URL: "postgresql://postgres@postgres/postgres"
133
    FUNKWHALE_URL: "https://funkwhale.ci"
Eliot Berriot's avatar
Eliot Berriot committed
134
    DJANGO_SETTINGS_MODULE: config.settings.local
135
    POSTGRES_HOST_AUTH_METHOD: trust
136
  only:
137
    - branches
Eliot Berriot's avatar
Eliot Berriot committed
138
  before_script:
139
    - apk add make git gcc python3-dev musl-dev python3-dev openssl-dev cargo
140
    - apk add postgresql-dev py3-psycopg2 libldap libffi-dev make zlib-dev jpeg-dev openldap-dev
141
    - cd api
Eliot Berriot's avatar
Eliot Berriot committed
142
143
144
    - pip3 install -r requirements/base.txt
    - pip3 install -r requirements/local.txt
    - pip3 install -r requirements/test.txt
Eliot Berriot's avatar
Eliot Berriot committed
145
  script:
146
    - pytest --cov-report xml --cov=funkwhale_api --junitxml=report.xml tests/
147
148
  tags:
    - docker
149
150
151
  artifacts:
    when: always
    reports:
Georg Krause's avatar
Georg Krause committed
152
      junit: api/report.xml
153
      cobertura: api/coverage.xml
154
155

test_front:
Eliot Berriot's avatar
Eliot Berriot committed
156
  interruptible: true
157
  stage: test
158
  image: node:12-buster
159
160
  before_script:
    - cd front
161
  only:
162
    - branches
163
  script:
164
    - yarn install --check-files
165
    - yarn test:unit
166
  cache:
ButterflyOfFire's avatar
ButterflyOfFire committed
167
    key: "funkwhale__front_dependencies"
168
    paths:
169
170
171
172
173
174
      - front/node_modules
      - front/yarn.lock
  artifacts:
    name: "front_${CI_COMMIT_REF_NAME}"
    paths:
      - front/dist/
175
176
    reports:
      junit: front/test-results.xml
Eliot Berriot's avatar
Eliot Berriot committed
177
  tags:
178
    - docker
Eliot Berriot's avatar
Eliot Berriot committed
179
180
181

build_front:
  stage: build
182
  image: node:12-buster
Eliot Berriot's avatar
Eliot Berriot committed
183
  before_script:
Eliot Berriot's avatar
Eliot Berriot committed
184
185
    - 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
186
187
    - cd front
  script:
188
    - yarn install
189
    - yarn run i18n-compile
190
    # this is to ensure we don't have any errors in the output,
Eliot Berriot's avatar
Eliot Berriot committed
191
    # cf https://dev.funkwhale.audio/funkwhale/funkwhale/issues/169
192
    - yarn build | tee /dev/stderr | (! grep -i 'ERROR in')
193
    - chmod -R 755 dist
Eliot Berriot's avatar
Eliot Berriot committed
194
195
196
197
198
  artifacts:
    name: "front_${CI_COMMIT_REF_NAME}"
    paths:
      - front/dist/
  only:
199
200
201
    - tags@funkwhale/funkwhale
    - master@funkwhale/funkwhale
    - develop@funkwhale/funkwhale
Eliot Berriot's avatar
Eliot Berriot committed
202
203
  tags:
    - docker
204

205
206
207
208
209
210
211
build_backend:
  stage: build
  image: bash
  before_script:
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
  script:
    - cd api
212
213
    - docker build -t $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME .
    - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
214
215
216
  tags:
    - docker-build

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

241
docker_release:
242
  stage: deploy
Eliot Berriot's avatar
Eliot Berriot committed
243
  image: bash
244
  before_script:
245
    - docker login -u $DOCKER_LOGIN -p $DOCKER_PASSWORD
246
    - cp -r front/dist api/frontend
Agate's avatar
Agate committed
247
    - (if [ "$CI_COMMIT_REF_NAME" == "develop" ] || [ "$CI_COMMIT_REF_NAME" == "master" ]; then ./scripts/set-api-build-metadata.sh $(echo $CI_COMMIT_SHA | cut -c 1-8); fi);
248
  script:
249
250
251
    - if [[ ! -z "$CI_COMMIT_TAG" ]]; then (./docs/get-releases-json.py | scripts/is-docker-latest.py $CI_COMMIT_TAG -) && export DOCKER_LATEST_TAG="-t $IMAGE_LATEST" || export DOCKER_LATEST_TAG=; fi
    - cd api
    - docker build -t $IMAGE $DOCKER_LATEST_TAG .
252
    - docker push $IMAGE
253
    - if [[ ! -z "$DOCKER_LATEST_TAG" ]]; then docker push $IMAGE_LATEST; fi
254
  only:
255
    - develop@funkwhale/funkwhale
Agate's avatar
Agate committed
256
    - master@funkwhale/funkwhale
257
    - tags@funkwhale/funkwhale
258
  tags:
259
    - docker-build
260

261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
#docker_all_in_one_release:
#  stage: deploy
#  image: bash
#  variables:
#    ALL_IN_ONE_REF: master
#    ALL_IN_ONE_ARTIFACT_URL: https://github.com/thetarkus/docker-funkwhale/archive/$ALL_IN_ONE_REF.zip
#    BUILD_PATH: all_in_one
#  before_script:
#    - docker login -u $DOCKER_LOGIN -p $DOCKER_PASSWORD
#    - (if [ "$CI_COMMIT_REF_NAME" == "develop" ] || [ "$CI_COMMIT_REF_NAME" == "master" ]; then ./scripts/set-api-build-metadata.sh $(echo $CI_COMMIT_SHA | cut -c 1-8); fi);
#  script:
#    - if [[ ! -z "$CI_COMMIT_TAG" ]]; then (./docs/get-releases-json.py | scripts/is-docker-latest.py $CI_COMMIT_TAG -) && export DOCKER_LATEST_TAG="-t $ALL_IN_ONE_IMAGE_LATEST" || export DOCKER_LATEST_TAG=; fi
#    - wget $ALL_IN_ONE_ARTIFACT_URL -O all_in_one.zip
#    - unzip -o all_in_one.zip -d tmpdir
#    - mv tmpdir/docker-funkwhale-$ALL_IN_ONE_REF $BUILD_PATH && rmdir tmpdir
#    - cp -r api $BUILD_PATH/src/api
#    - cp -r front $BUILD_PATH/src/front
#    - cd $BUILD_PATH
#    - ./scripts/download-nginx-template.sh src/ $CI_COMMIT_REF_NAME
#    - docker build -t $ALL_IN_ONE_IMAGE $DOCKER_LATEST_TAG .
#    - docker push $ALL_IN_ONE_IMAGE
#    - if [[ ! -z "$DOCKER_LATEST_TAG" ]]; then docker push $ALL_IN_ONE_IMAGE_LATEST; fi
#  only:
#    - develop@funkwhale/funkwhale
#    - master@funkwhale/funkwhale
#    - tags@funkwhale/funkwhale
#  tags:
#    - docker-build
289

290
291
292
build_api:
  # Simply publish a zip containing api/ directory
  stage: deploy
Eliot Berriot's avatar
Eliot Berriot committed
293
  image: bash
294
295
296
297
  artifacts:
    name: "api_${CI_COMMIT_REF_NAME}"
    paths:
      - api
298
  script:
299
    - rm -rf api/tests
Agate's avatar
Agate committed
300
    - (if [ "$CI_COMMIT_REF_NAME" == "develop" ] || [ "$CI_COMMIT_REF_NAME" == "master" ]; then ./scripts/set-api-build-metadata.sh $(echo $CI_COMMIT_SHA | cut -c 1-8); fi);
301
302
    - chmod -R 750 api
    - echo Done!
303
  only:
304
305
306
    - tags@funkwhale/funkwhale
    - master@funkwhale/funkwhale
    - develop@funkwhale/funkwhale
307

308
309
310
check_api_dependencies:
  interruptible: true
  stage: deps
311
  image: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
  cache:
    key: "$CI_PROJECT_ID__pip_cache"
    paths:
      - "$PIP_CACHE_DIR"
  variables:
    DJANGO_SETTINGS_MODULE: config.settings.local
    POSTGRES_HOST_AUTH_METHOD: trust
  only:
    - branches
  before_script:
    - apk add make git gcc python3-dev musl-dev
    - apk add postgresql-dev py3-psycopg2 libldap libffi-dev make zlib-dev jpeg-dev openldap-dev
    - cd api
    - pip3 install -r requirements/base.txt
    - pip3 install -r requirements/local.txt
    - pip3 install -r requirements/test.txt
  script:
    - $CI_PROJECT_DIR/scripts/check-api-deps.sh
  tags:
    - docker
  allow_failure: true