.gitlab-ci.yml 7.79 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"
Agate's avatar
Agate committed
9
  PYTHONDONTWRITEBYTECODE: "true"
ButterflyOfFire's avatar
ButterflyOfFire committed
10 11
  REVIEW_DOMAIN: preview.funkwhale.audio
  REVIEW_INSTANCE_URL: https://demo.funkwhale.audio
12

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

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

Agate's avatar
Agate committed
60
review_docs:
Agate's avatar
Agate committed
61
  interruptible: true
Agate's avatar
Agate committed
62 63 64 65 66 67 68 69 70 71 72 73
  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
Agate's avatar
Agate committed
74
    - pip install sphinx sphinx_rtd_theme django-environ django
Agate's avatar
Agate committed
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
  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

93
black:
Agate's avatar
Agate committed
94
  interruptible: true
95 96
  image: python:3.6
  stage: lint
Agate's avatar
Agate committed
97 98
  variables:
    GIT_STRATEGY: fetch
99 100 101
  before_script:
    - pip install black
  script:
Agate's avatar
Agate committed
102
    - black --check --diff api/
103

Agate's avatar
Agate committed
104
flake8:
Agate's avatar
Agate committed
105
  interruptible: true
Agate's avatar
Agate committed
106 107 108 109 110
  image: python:3.6
  stage: lint
  variables:
    GIT_STRATEGY: fetch
  before_script:
Agate's avatar
Agate committed
111
    - pip install 'flake8<3.7'
Agate's avatar
Agate committed
112
  script:
113
    - flake8 -v api
Agate's avatar
Agate committed
114
  cache:
Agate's avatar
Agate committed
115
    key: "$CI_PROJECT_ID__flake8_pip_cache"
Agate's avatar
Agate committed
116 117
    paths:
      - "$PIP_CACHE_DIR"
118

Agate's avatar
Agate committed
119
test_api:
Agate's avatar
Agate committed
120
  interruptible: true
Agate's avatar
Agate committed
121
  services:
122
    - postgres:11
123
    - redis:5
Agate's avatar
Agate committed
124
  stage: test
125
  image: funkwhale/funkwhale:develop
126
  cache:
Agate's avatar
Agate committed
127
    key: "$CI_PROJECT_ID__pip_cache"
128 129
    paths:
      - "$PIP_CACHE_DIR"
130
  variables:
Agate's avatar
Agate committed
131
    DATABASE_URL: "postgresql://postgres@postgres/postgres"
132
    FUNKWHALE_URL: "https://funkwhale.ci"
Agate's avatar
Agate committed
133
    DJANGO_SETTINGS_MODULE: config.settings.local
Agate's avatar
Agate committed
134
    POSTGRES_HOST_AUTH_METHOD: trust
135
  only:
136
    - branches
Agate's avatar
Agate committed
137
  before_script:
Agate's avatar
Agate committed
138
    - apk add make git gcc python3-dev musl-dev
139
    - cd api
Agate's avatar
Agate committed
140 141 142
    - pip3 install -r requirements/base.txt
    - pip3 install -r requirements/local.txt
    - pip3 install -r requirements/test.txt
Agate's avatar
Agate committed
143
  script:
Agate's avatar
Agate committed
144
    - pytest --cov=funkwhale_api tests/
145 146 147 148
  tags:
    - docker

test_front:
Agate's avatar
Agate committed
149
  interruptible: true
150
  stage: test
151
  image: node:12-buster
152 153
  before_script:
    - cd front
154
  only:
155
    - branches
156
  script:
157
    - yarn install --check-files
158
    - yarn test:unit
159
  cache:
ButterflyOfFire's avatar
ButterflyOfFire committed
160
    key: "funkwhale__front_dependencies"
161
    paths:
162 163 164 165 166 167
      - front/node_modules
      - front/yarn.lock
  artifacts:
    name: "front_${CI_COMMIT_REF_NAME}"
    paths:
      - front/dist/
Agate's avatar
Agate committed
168
  tags:
169
    - docker
Agate's avatar
Agate committed
170 171 172

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

Agate's avatar
Agate committed
194 195
  tags:
    - docker
196

Agate's avatar
Agate committed
197
pages:
Agate's avatar
Agate committed
198
  stage: test
Agate's avatar
Agate committed
199 200 201
  image: python:3.6
  variables:
    BUILD_PATH: "../public"
Agate's avatar
Agate committed
202 203
  before_script:
    - cd docs
204 205
    - apt-get update
    - apt-get install -y graphviz
Agate's avatar
Agate committed
206
    - pip install sphinx sphinx_rtd_theme django-environ django
207
  script:
Agate's avatar
Agate committed
208
    - ./build_docs.sh
Agate's avatar
Agate committed
209 210 211 212
  cache:
    key: "$CI_PROJECT_ID__sphinx"
    paths:
      - "$PIP_CACHE_DIR"
Agate's avatar
Agate committed
213 214 215 216
  artifacts:
    paths:
      - public
  only:
217
    - master@funkwhale/funkwhale
Agate's avatar
Agate committed
218 219
  tags:
    - docker
220

221
docker_release:
Agate's avatar
Agate committed
222
  stage: deploy
Agate's avatar
Agate committed
223
  image: bash
224
  before_script:
Agate's avatar
Agate committed
225
    - docker login -u $DOCKER_LOGIN -p $DOCKER_PASSWORD
Agate's avatar
Agate committed
226
    - cp -r front/dist api/frontend
227
    - (if [ "$CI_COMMIT_REF_NAME" == "develop" ] || [ "$CI_COMMIT_REF_NAME" == "master" ]; then ./scripts/set-api-build-metadata.sh $(echo $CI_COMMIT_SHA | cut -c 1-8); fi);
228
  script:
229 230 231
    - 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 .
232
    - docker push $IMAGE
233
    - if [[ ! -z "$DOCKER_LATEST_TAG" ]]; then docker push $IMAGE_LATEST; fi
234
  only:
235
    - develop@funkwhale/funkwhale
236
    - master@funkwhale/funkwhale
237
    - tags@funkwhale/funkwhale
238
  tags:
239
    - docker-build
240

241 242 243 244 245 246 247 248 249
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
250
    - (if [ "$CI_COMMIT_REF_NAME" == "develop" ] || [ "$CI_COMMIT_REF_NAME" == "master" ]; then ./scripts/set-api-build-metadata.sh $(echo $CI_COMMIT_SHA | cut -c 1-8); fi);
251
  script:
252
    - 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
253 254 255 256 257 258 259
    - 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
260
    - docker build -t $ALL_IN_ONE_IMAGE $DOCKER_LATEST_TAG .
261
    - docker push $ALL_IN_ONE_IMAGE
262
    - if [[ ! -z "$DOCKER_LATEST_TAG" ]]; then docker push $ALL_IN_ONE_IMAGE_LATEST; fi
263 264
  only:
    - develop@funkwhale/funkwhale
265
    - master@funkwhale/funkwhale
266 267 268 269
    - tags@funkwhale/funkwhale
  tags:
    - docker-build

270 271 272
build_api:
  # Simply publish a zip containing api/ directory
  stage: deploy
Agate's avatar
Agate committed
273
  image: bash
274 275 276 277
  artifacts:
    name: "api_${CI_COMMIT_REF_NAME}"
    paths:
      - api
278
  script:
Agate's avatar
Agate committed
279
    - rm -rf api/tests
280
    - (if [ "$CI_COMMIT_REF_NAME" == "develop" ] || [ "$CI_COMMIT_REF_NAME" == "master" ]; then ./scripts/set-api-build-metadata.sh $(echo $CI_COMMIT_SHA | cut -c 1-8); fi);
281 282
    - chmod -R 750 api
    - echo Done!
283
  only:
284 285 286
    - tags@funkwhale/funkwhale
    - master@funkwhale/funkwhale
    - develop@funkwhale/funkwhale