.gitlab-ci.yml 6.1 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
  REVIEW_DOMAIN: preview.funkwhale.audio
  REVIEW_INSTANCE_URL: https://demo.funkwhale.audio
9

Eliot Berriot's avatar
Eliot Berriot committed
10
stages:
11
  - review
12
  - lint
Eliot Berriot's avatar
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')
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:
35
    key: "funkwhale__front_dependencies"
36 37 38 39
    paths:
      - front/node_modules
      - front/yarn.lock
  environment:
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:
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:
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
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:
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:
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:
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:
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:
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
  image: funkwhale/funkwhale:develop
138
  cache:
139
    key: "$CI_PROJECT_ID__pip_cache"
140 141
    paths:
      - "$PIP_CACHE_DIR"
142
  variables:
143
    DATABASE_URL: "postgresql://postgres@postgres/postgres"
144
    FUNKWHALE_URL: "https://funkwhale.ci"
Eliot Berriot's avatar
Eliot Berriot committed
145
    DJANGO_SETTINGS_MODULE: config.settings.local
146 147
  only:
    - branches
Eliot Berriot's avatar
Eliot Berriot committed
148
  before_script:
149
    - cd api
150 151
    - apt-get update
    - grep "^[^#;]" requirements.apt | grep -Fv "python3-dev" | xargs apt-get install -y --no-install-recommends
152 153
    - pip install -r requirements/base.txt
    - pip install -r requirements/local.txt
154
    - pip install -r requirements/test.txt
Eliot Berriot's avatar
Eliot Berriot committed
155
  script:
156
    - pytest --cov=funkwhale_api tests/
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
  script:
    - yarn install
169
    - yarn test:unit
170
  cache:
171
    key: "funkwhale__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 183

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

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

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

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