.gitlab-ci.yml 5.48 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"
Agate's avatar
Agate committed
6
  PYTHONDONTWRITEBYTECODE: "true"
7 8


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

Agate's avatar
Agate committed
16
review_front:
17 18 19 20 21
  stage: review
  image: node:9
  when: manual
  allow_failure: true
  before_script:
22 23
    - apt-get update
    - apt-get install jq -y
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')
Agate's avatar
Agate 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:
Agate's avatar
Agate 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 43 44 45 46
  only:
    - branches@funkwhale/funkwhale
  tags:
    - funkwhale-review

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

Agate's avatar
Agate committed
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
  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:
    - branches@funkwhale/funkwhale
  tags:
    - funkwhale-review

stop_docs_review:
  stage: review
  script:
    - rm -rf /static/docs/$CI_BUILD_REF_SLUG/
  variables:
    GIT_STRATEGY: none
  when: manual
  environment:
    name: review/docs-$CI_BUILD_REF_NAME
99 100 101 102
    action: stop
  tags:
    - funkwhale-review

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

Agate's avatar
Agate committed
113 114 115 116 117 118 119 120
flake8:
  image: python:3.6
  stage: lint
  variables:
    GIT_STRATEGY: fetch
  before_script:
    - pip install flake8
  script:
121
    - flake8 -v api
Agate's avatar
Agate committed
122
  cache:
Agate's avatar
Agate committed
123
    key: "$CI_PROJECT_ID__flake8_pip_cache"
Agate's avatar
Agate committed
124 125
    paths:
      - "$PIP_CACHE_DIR"
126

Agate's avatar
Agate committed
127
test_api:
Agate's avatar
Agate committed
128 129
  services:
    - postgres:9.4
Agate's avatar
Agate committed
130
    - redis:3
Agate's avatar
Agate committed
131
  stage: test
132 133
  image: funkwhale/funkwhale:latest
  cache:
Agate's avatar
Agate committed
134
    key: "$CI_PROJECT_ID__pip_cache"
135 136
    paths:
      - "$PIP_CACHE_DIR"
137
  variables:
138
    DJANGO_ALLOWED_HOSTS: "localhost"
Agate's avatar
Agate committed
139
    DATABASE_URL: "postgresql://postgres@postgres/postgres"
140
    FUNKWHALE_URL: "https://funkwhale.ci"
141
    CACHEOPS_ENABLED: "false"
Agate's avatar
Agate committed
142
    DJANGO_SETTINGS_MODULE: config.settings.local
143

Agate's avatar
Agate committed
144
  before_script:
145
    - cd api
Agate's avatar
Agate committed
146 147
    - pip install -r requirements/base.txt
    - pip install -r requirements/local.txt
148
    - pip install -r requirements/test.txt
Agate's avatar
Agate committed
149
  script:
Agate's avatar
Agate committed
150
    - pytest --cov=funkwhale_api tests/
151 152 153 154 155 156 157 158 159 160 161 162 163
  tags:
    - docker


test_front:
  stage: test
  image: node:9
  before_script:
    - cd front

  script:
    - yarn install
    - yarn run unit
164
  cache:
Agate's avatar
Agate committed
165
    key: "$CI_PROJECT_ID__front_dependencies"
166
    paths:
167 168 169 170 171 172
      - front/node_modules
      - front/yarn.lock
  artifacts:
    name: "front_${CI_COMMIT_REF_NAME}"
    paths:
      - front/dist/
Agate's avatar
Agate committed
173
  tags:
174
    - docker
Agate's avatar
Agate committed
175

176

Agate's avatar
Agate committed
177 178
build_front:
  stage: build
179
  image: node:9
Agate's avatar
Agate committed
180
  before_script:
181 182
    - apt-get update
    - apt-get install jq -y
Agate's avatar
Agate committed
183 184
    - cd front
  script:
185
    - yarn install
186
    - yarn run i18n-compile
Agate's avatar
Agate committed
187 188 189
    # 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')
190
    - chmod -R 750 front/dist
Agate's avatar
Agate committed
191
  cache:
Agate's avatar
Agate committed
192
    key: "$CI_PROJECT_ID__front_dependencies"
Agate's avatar
Agate committed
193 194
    paths:
      - front/node_modules
195
      - front/yarn.lock
Agate's avatar
Agate committed
196 197 198 199 200
  artifacts:
    name: "front_${CI_COMMIT_REF_NAME}"
    paths:
      - front/dist/
  only:
201 202 203
    - tags@funkwhale/funkwhale
    - master@funkwhale/funkwhale
    - develop@funkwhale/funkwhale
Agate's avatar
Agate committed
204 205
  tags:
    - docker
206

207

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

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

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