.gitlab-ci.yml 7.36 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 6
  ALL_IN_ONE_IMAGE_NAME: funkwhale/all-in-one
  ALL_IN_ONE_IMAGE: $ALL_IN_ONE_IMAGE_NAME:$CI_COMMIT_REF_NAME
7
  ALL_IN_ONE_IMAGE_LATEST: $ALL_IN_ONE_IMAGE_NAME:latest
8
  PIP_CACHE_DIR: "$CI_PROJECT_DIR/pip-cache"
9
  PYTHONDONTWRITEBYTECODE: "true"
10 11
  REVIEW_DOMAIN: preview.funkwhale.audio
  REVIEW_INSTANCE_URL: https://demo.funkwhale.audio
12

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

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

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

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

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

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

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

234 235 236 237 238 239 240 241 242 243 244
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:
245
    - if [[ ! -z "$CI_COMMIT_TAG" ]]; then (./docs/get-releases-json.py | scripts/is-docker-latest.py $CI_COMMIT_TAG -) && export DOCKER_LATEST_TAG="-t $ALL_IN_ONE_IMAGE_LATEST" || export DOCKER_LATEST_TAG=; fi
246 247 248 249 250 251 252
    - 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
253
    - docker build -t $ALL_IN_ONE_IMAGE $DOCKER_LATEST_TAG .
254
    - docker push $ALL_IN_ONE_IMAGE
255
    - if [[ ! -z "$DOCKER_LATEST_TAG" ]]; then docker push $ALL_IN_ONE_IMAGE_LATEST; fi
256 257 258 259 260 261
  only:
    - develop@funkwhale/funkwhale
    - tags@funkwhale/funkwhale
  tags:
    - docker-build

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