.gitlab-ci.yml 6.13 KB
Newer Older
1 2
variables:
  IMAGE_NAME: funkwhale/funkwhale
Agate's avatar
Agate committed
3
  IMAGE: $IMAGE_NAME:$CI_COMMIT_REF_NAME
4
  IMAGE_LATEST: $IMAGE_NAME:latest
5
  PIP_CACHE_DIR: "$CI_PROJECT_DIR/pip-cache"
Agate's avatar
Agate committed
6
  PYTHONDONTWRITEBYTECODE: "true"
ButterflyOfFire's avatar
ButterflyOfFire committed
7 8
  REVIEW_DOMAIN: preview.funkwhale.audio
  REVIEW_INSTANCE_URL: https://demo.funkwhale.audio
9

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

Agate's avatar
Agate committed
17
review_front:
Agate's avatar
Agate committed
18 19 20 21 22
  stage: review
  image: node:9
  when: manual
  allow_failure: true
  before_script:
Agate's avatar
Agate 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
Agate's avatar
Agate committed
25 26 27
    - cd front
  script:
    - yarn install
28
    - yarn run i18n-compile
Agate's avatar
Agate committed
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
Agate's avatar
Agate committed
34
  cache:
ButterflyOfFire's avatar
ButterflyOfFire committed
35
    key: "funkwhale__front_dependencies"
Agate's avatar
Agate committed
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
Agate's avatar
Agate committed
42
    on_stop: stop_front_review
Agate's avatar
Agate committed
43
  only:
Agate's avatar
Agate committed
44
    - branches
Agate's avatar
Agate committed
45 46 47
  tags:
    - funkwhale-review

Agate's avatar
Agate committed
48
stop_front_review:
Agate's avatar
Agate committed
49 50
  stage: review
  script:
ButterflyOfFire's avatar
ButterflyOfFire committed
51
    - rm -rf /static/front/$CI_PROJECT_PATH_SLUG-$CI_BUILD_REF_SLUG/
Agate's avatar
Agate committed
52 53 54
  variables:
    GIT_STRATEGY: none
  when: manual
Agate's avatar
Agate committed
55 56
  only:
    - branches
Agate's avatar
Agate committed
57
  environment:
ButterflyOfFire's avatar
ButterflyOfFire committed
58
    name: review/front/$CI_PROJECT_PATH_SLUG-$CI_BUILD_REF_SLUG
Agate's avatar
Agate 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

Agate's avatar
Agate 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
Agate's avatar
Agate 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
Agate's avatar
Agate committed
87 88
    on_stop: stop_docs_review
  only:
Agate's avatar
Agate committed
89
    - branches
Agate's avatar
Agate 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/
Agate's avatar
Agate committed
97 98 99
  variables:
    GIT_STRATEGY: none
  when: manual
Agate's avatar
Agate committed
100 101
  only:
    - branches
Agate's avatar
Agate committed
102
  environment:
ButterflyOfFire's avatar
ButterflyOfFire committed
103
    name: review/docs/$CI_PROJECT_PATH_SLUG-$CI_BUILD_REF_SLUG
Agate's avatar
Agate committed
104 105 106 107
    action: stop
  tags:
    - funkwhale-review

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

Agate's avatar
Agate 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
Agate's avatar
Agate committed
127
  cache:
Agate's avatar
Agate committed
128
    key: "$CI_PROJECT_ID__flake8_pip_cache"
Agate's avatar
Agate committed
129 130
    paths:
      - "$PIP_CACHE_DIR"
131

Agate's avatar
Agate committed
132
test_api:
Agate's avatar
Agate committed
133 134
  services:
    - postgres:9.4
Agate's avatar
Agate committed
135
    - redis:3
Agate's avatar
Agate committed
136
  stage: test
137
  image: funkwhale/funkwhale:develop
138
  cache:
Agate's avatar
Agate committed
139
    key: "$CI_PROJECT_ID__pip_cache"
140 141
    paths:
      - "$PIP_CACHE_DIR"
142
  variables:
143
    DJANGO_ALLOWED_HOSTS: "localhost"
Agate's avatar
Agate committed
144
    DATABASE_URL: "postgresql://postgres@postgres/postgres"
145
    FUNKWHALE_URL: "https://funkwhale.ci"
Agate's avatar
Agate committed
146
    DJANGO_SETTINGS_MODULE: config.settings.local
Agate's avatar
Agate committed
147 148
  only:
    - branches
Agate's avatar
Agate committed
149
  before_script:
150
    - cd api
151 152
    - apt-get update
    - grep "^[^#;]" requirements.apt | grep -Fv "python3-dev" | xargs apt-get install -y --no-install-recommends
Agate's avatar
Agate committed
153 154
    - pip install -r requirements/base.txt
    - pip install -r requirements/local.txt
155
    - pip install -r requirements/test.txt
Agate's avatar
Agate committed
156
  script:
Agate's avatar
Agate committed
157
    - pytest --cov=funkwhale_api tests/
158 159 160 161 162 163 164 165
  tags:
    - docker

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

build_front:
  stage: build
185
  image: node:9
Agate's avatar
Agate committed
186
  before_script:
Agate's avatar
Agate 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
Agate's avatar
Agate committed
189 190
    - cd front
  script:
191
    - yarn install
Agate's avatar
Agate committed
192
    - yarn run i18n-compile
Agate's avatar
Agate committed
193 194
    # this is to ensure we don't have any errors in the output,
    # cf https://code.eliotberriot.com/funkwhale/funkwhale/issues/169
195
    - yarn build | tee /dev/stderr | (! grep -i 'ERROR in')
196
    - chmod -R 755 dist
Agate's avatar
Agate committed
197
  cache:
ButterflyOfFire's avatar
ButterflyOfFire committed
198
    key: "funkwhale__front_dependencies"
Agate's avatar
Agate committed
199 200
    paths:
      - front/node_modules
201
      - front/yarn.lock
Agate's avatar
Agate 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
Agate's avatar
Agate committed
210 211
  tags:
    - docker
212

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

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

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