.gitlab-ci.yml 6.65 KB
Newer Older
1 2
variables:
  IMAGE_NAME: funkwhale/funkwhale
3
  IMAGE: $IMAGE_NAME:$CI_COMMIT_REF_NAME
4 5
  ALL_IN_ONE_IMAGE_NAME: funkwhale/all-in-one
  ALL_IN_ONE_IMAGE: $ALL_IN_ONE_IMAGE_NAME:$CI_COMMIT_REF_NAME
6
  PIP_CACHE_DIR: "$CI_PROJECT_DIR/pip-cache"
7
  PYTHONDONTWRITEBYTECODE: "true"
8 9
  REVIEW_DOMAIN: preview.funkwhale.audio
  REVIEW_INSTANCE_URL: https://demo.funkwhale.audio
10

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

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

57

58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
review_docs:
  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
    - pip install sphinx
  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


91 92 93
black:
  image: python:3.6
  stage: lint
94 95
  variables:
    GIT_STRATEGY: fetch
96 97 98
  before_script:
    - pip install black
  script:
Eliot Berriot's avatar
Eliot Berriot committed
99
    - black --check --diff api/
100

Eliot Berriot's avatar
Eliot Berriot committed
101 102 103 104 105 106 107 108
flake8:
  image: python:3.6
  stage: lint
  variables:
    GIT_STRATEGY: fetch
  before_script:
    - pip install flake8
  script:
109
    - flake8 -v api
110
  cache:
Eliot Berriot's avatar
Eliot Berriot committed
111
    key: "$CI_PROJECT_ID__flake8_pip_cache"
112 113
    paths:
      - "$PIP_CACHE_DIR"
114

Eliot Berriot's avatar
Eliot Berriot committed
115
test_api:
116
  services:
117
    - postgres:11
Eliot Berriot's avatar
Eliot Berriot committed
118
    - redis:3
Eliot Berriot's avatar
Eliot Berriot committed
119
  stage: test
120
  image: funkwhale/funkwhale:develop
121
  cache:
122
    key: "$CI_PROJECT_ID__pip_cache"
123 124
    paths:
      - "$PIP_CACHE_DIR"
125
  variables:
126
    DATABASE_URL: "postgresql://postgres@postgres/postgres"
127
    FUNKWHALE_URL: "https://funkwhale.ci"
Eliot Berriot's avatar
Eliot Berriot committed
128
    DJANGO_SETTINGS_MODULE: config.settings.local
129
  only:
130
    - branches
Eliot Berriot's avatar
Eliot Berriot committed
131
  before_script:
132
    - cd api
Eliot Berriot's avatar
Eliot Berriot committed
133 134 135 136
    - sed -i '/Pillow/d' requirements/base.txt
    - 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
137
  script:
138
    - pytest --cov=funkwhale_api tests/
139 140 141 142 143 144 145 146
  tags:
    - docker

test_front:
  stage: test
  image: node:9
  before_script:
    - cd front
147
  only:
148
    - branches
149
  script:
150
    - yarn install --check-files
151
    - yarn test:unit
152
  cache:
153
    key: "funkwhale__front_dependencies"
154
    paths:
155 156 157 158 159 160
      - front/node_modules
      - front/yarn.lock
  artifacts:
    name: "front_${CI_COMMIT_REF_NAME}"
    paths:
      - front/dist/
Eliot Berriot's avatar
Eliot Berriot committed
161
  tags:
162
    - docker
Eliot Berriot's avatar
Eliot Berriot committed
163 164 165

build_front:
  stage: build
166
  image: node:9
Eliot Berriot's avatar
Eliot Berriot committed
167
  before_script:
Eliot Berriot's avatar
Eliot Berriot committed
168 169
    - 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
170 171
    - cd front
  script:
172
    - yarn install
173
    - yarn run i18n-compile
174
    # this is to ensure we don't have any errors in the output,
Eliot Berriot's avatar
Eliot Berriot committed
175
    # cf https://dev.funkwhale.audio/funkwhale/funkwhale/issues/169
176
    - yarn build | tee /dev/stderr | (! grep -i 'ERROR in')
177
    - chmod -R 755 dist
Eliot Berriot's avatar
Eliot Berriot committed
178 179 180 181 182
  artifacts:
    name: "front_${CI_COMMIT_REF_NAME}"
    paths:
      - front/dist/
  only:
183 184 185
    - tags@funkwhale/funkwhale
    - master@funkwhale/funkwhale
    - develop@funkwhale/funkwhale
186

Eliot Berriot's avatar
Eliot Berriot committed
187 188
  tags:
    - docker
189

190
pages:
Eliot Berriot's avatar
Eliot Berriot committed
191
  stage: test
192 193 194
  image: python:3.6
  variables:
    BUILD_PATH: "../public"
195 196
  before_script:
    - cd docs
197 198
    - apt-get update
    - apt-get install -y graphviz
199
    - pip install sphinx
200
  script:
201
    - ./build_docs.sh
Eliot Berriot's avatar
Eliot Berriot committed
202 203 204 205
  cache:
    key: "$CI_PROJECT_ID__sphinx"
    paths:
      - "$PIP_CACHE_DIR"
206 207 208 209
  artifacts:
    paths:
      - public
  only:
210
    - master@funkwhale/funkwhale
Eliot Berriot's avatar
Eliot Berriot committed
211 212
  tags:
    - docker
213

214
docker_release:
215
  stage: deploy
Eliot Berriot's avatar
Eliot Berriot committed
216
  image: bash
217
  before_script:
218
    - docker login -u $DOCKER_LOGIN -p $DOCKER_PASSWORD
219
    - cp -r front/dist api/frontend
Eliot Berriot's avatar
Eliot Berriot committed
220
    - (if [ "$CI_COMMIT_REF_NAME" == "develop" ]; then ./scripts/set-api-build-metadata.sh $(echo $CI_COMMIT_SHA | cut -c 1-8); fi);
221 222
    - cd api
  script:
223 224
    - docker build -t $IMAGE .
    - docker push $IMAGE
225
  only:
226
    - develop@funkwhale/funkwhale
227
    - tags@funkwhale/funkwhale
228
  tags:
229
    - docker-build
230

231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
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" ]; then ./scripts/set-api-build-metadata.sh $(echo $CI_COMMIT_SHA | cut -c 1-8); fi);
  script:
    - 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 push $ALL_IN_ONE_IMAGE
  only:
    - develop@funkwhale/funkwhale
    - tags@funkwhale/funkwhale
  tags:
    - docker-build

257 258 259
build_api:
  # Simply publish a zip containing api/ directory
  stage: deploy
Eliot Berriot's avatar
Eliot Berriot committed
260
  image: bash
261 262 263 264
  artifacts:
    name: "api_${CI_COMMIT_REF_NAME}"
    paths:
      - api
265
  script:
266
    - rm -rf api/tests
Eliot Berriot's avatar
Eliot Berriot committed
267
    - (if [ "$CI_COMMIT_REF_NAME" == "develop" ]; then ./scripts/set-api-build-metadata.sh $(echo $CI_COMMIT_SHA | cut -c 1-8); fi);
268 269
    - chmod -R 750 api
    - echo Done!
270
  only:
271 272 273
    - tags@funkwhale/funkwhale
    - master@funkwhale/funkwhale
    - develop@funkwhale/funkwhale