.gitlab-ci.yml 6 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"
ButterflyOfFire's avatar
ButterflyOfFire committed
7
8
  REVIEW_DOMAIN: preview.funkwhale.audio
  REVIEW_INSTANCE_URL: https://demo.funkwhale.audio
9

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

Eliot Berriot's avatar
Eliot Berriot committed
17
review_front:
18
19
20
21
22
  stage: review
  image: node:9
  when: manual
  allow_failure: true
  before_script:
Eliot Berriot's avatar
Eliot Berriot committed
23
24
    - 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
25
26
27
    - cd front
  script:
    - yarn install
28
    - yarn run i18n-compile
29
30
    # this is to ensure we don't have any errors in the output,
    # cf https://code.eliotberriot.com/funkwhale/funkwhale/issues/169
31
    - VUE_APP_INSTANCE_URL=$REVIEW_INSTANCE_URL yarn run build | tee /dev/stderr | (! grep -i 'ERROR in')
ButterflyOfFire's avatar
ButterflyOfFire committed
32
33
    - mkdir -p /static/front/$CI_PROJECT_PATH_SLUG-$CI_BUILD_REF_SLUG
    - cp -r dist/* /static/front/$CI_PROJECT_PATH_SLUG-$CI_BUILD_REF_SLUG
34
  cache:
ButterflyOfFire's avatar
ButterflyOfFire committed
35
    key: "funkwhale__front_dependencies"
36
37
38
39
    paths:
      - front/node_modules
      - front/yarn.lock
  environment:
ButterflyOfFire's avatar
ButterflyOfFire committed
40
41
    name: review/front/$CI_PROJECT_PATH_SLUG-$CI_BUILD_REF_SLUG
    url: http://front-$CI_PROJECT_PATH_SLUG-$CI_BUILD_REF_SLUG.$REVIEW_DOMAIN
Eliot Berriot's avatar
Eliot Berriot committed
42
    on_stop: stop_front_review
43
  only:
44
    - branches
45
46
47
  tags:
    - funkwhale-review

Eliot Berriot's avatar
Eliot Berriot committed
48
stop_front_review:
49
50
  stage: review
  script:
ButterflyOfFire's avatar
ButterflyOfFire committed
51
    - rm -rf /static/front/$CI_PROJECT_PATH_SLUG-$CI_BUILD_REF_SLUG/
52
53
54
  variables:
    GIT_STRATEGY: none
  when: manual
55
56
  only:
    - branches
57
  environment:
ButterflyOfFire's avatar
ButterflyOfFire committed
58
    name: review/front/$CI_PROJECT_PATH_SLUG-$CI_BUILD_REF_SLUG
Eliot Berriot's avatar
Eliot Berriot committed
59
60
61
62
63
64
65
66
67
68
69
70
71
    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
72
73
74
75
    - apt-get update
    - apt-get install -y graphviz
    - pip install sphinx

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

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

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

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

Eliot Berriot's avatar
Eliot Berriot committed
132
test_api:
Eliot Berriot's avatar
Eliot Berriot committed
133
134
  services:
    - postgres:9.4
Eliot Berriot's avatar
Eliot Berriot committed
135
    - redis:3
Eliot Berriot's avatar
Eliot Berriot committed
136
  stage: test
137
138
  image: funkwhale/funkwhale:latest
  cache:
Eliot Berriot's avatar
Eliot Berriot committed
139
    key: "$CI_PROJECT_ID__pip_cache"
140
141
    paths:
      - "$PIP_CACHE_DIR"
142
  variables:
143
    DJANGO_ALLOWED_HOSTS: "localhost"
Eliot Berriot's avatar
Eliot Berriot committed
144
    DATABASE_URL: "postgresql://postgres@postgres/postgres"
145
    FUNKWHALE_URL: "https://funkwhale.ci"
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
  tags:
    - docker

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

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

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

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

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