Skip to content
Snippets Groups Projects
.gitlab-ci.yml 7.19 KiB
Newer Older
variables:
  IMAGE_NAME: funkwhale/funkwhale
  IMAGE: $IMAGE_NAME:$CI_COMMIT_REF_NAME
  ALL_IN_ONE_IMAGE_NAME: funkwhale/all-in-one
  ALL_IN_ONE_IMAGE: $ALL_IN_ONE_IMAGE_NAME:$CI_COMMIT_REF_NAME
  PIP_CACHE_DIR: "$CI_PROJECT_DIR/pip-cache"
  PYTHONDONTWRITEBYTECODE: "true"
  REVIEW_DOMAIN: preview.funkwhale.audio
  REVIEW_INSTANCE_URL: https://demo.funkwhale.audio
Eliot Berriot's avatar
Eliot Berriot committed
stages:
Eliot Berriot's avatar
Eliot Berriot committed
  - test
Eliot Berriot's avatar
Eliot Berriot committed
  - build
Eliot Berriot's avatar
Eliot Berriot committed

Eliot Berriot's avatar
Eliot Berriot committed
review_front:
  stage: review
  image: node:9
  when: manual
  allow_failure: true
  before_script:
Eliot Berriot's avatar
Eliot Berriot committed
    - 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
    - cd front
  script:
    - yarn install
    # this is to ensure we don't have any errors in the output,
Eliot Berriot's avatar
Eliot Berriot committed
    # cf https://dev.funkwhale.audio/funkwhale/funkwhale/issues/169
    - VUE_APP_INSTANCE_URL=$REVIEW_INSTANCE_URL yarn run build | tee /dev/stderr | (! grep -i 'ERROR in')
    - 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
    key: "funkwhale__front_dependencies"
    paths:
      - front/node_modules
      - front/yarn.lock
  environment:
    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
    on_stop: stop_front_review
  tags:
    - funkwhale-review

Eliot Berriot's avatar
Eliot Berriot committed
stop_front_review:
  stage: review
  script:
    - rm -rf /static/front/$CI_PROJECT_PATH_SLUG-$CI_BUILD_REF_SLUG/
  variables:
    GIT_STRATEGY: none
  when: manual
  only:
    - branches
  environment:
    name: review/front/$CI_PROJECT_PATH_SLUG-$CI_BUILD_REF_SLUG
Eliot Berriot's avatar
Eliot Berriot committed
    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
    - apt-get update
    - apt-get install -y graphviz
    - pip install sphinx

Eliot Berriot's avatar
Eliot Berriot committed
  cache:
    key: "$CI_PROJECT_ID__sphinx"
    paths:
      - "$PIP_CACHE_DIR"
  script:
    - ./build_docs.sh
    - 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
  environment:
    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
    on_stop: stop_docs_review
  only:
Eliot Berriot's avatar
Eliot Berriot committed
  tags:
    - funkwhale-review

stop_docs_review:
  stage: review
  script:
    - rm -rf /static/docs/$CI_PROJECT_PATH_SLUG-$CI_BUILD_REF_SLUG/
Eliot Berriot's avatar
Eliot Berriot committed
  variables:
    GIT_STRATEGY: none
  when: manual
Eliot Berriot's avatar
Eliot Berriot committed
  environment:
    name: review/docs/$CI_PROJECT_PATH_SLUG-$CI_BUILD_REF_SLUG
    action: stop
  tags:
    - funkwhale-review

black:
  image: python:3.6
  stage: lint
  variables:
    GIT_STRATEGY: fetch
  before_script:
    - pip install black
  script:
    - black --exclude "/(\.git|\.hg|\.mypy_cache|\.tox|\.venv|_build|buck-out|build|dist|migrations)/" --check --diff api/
Eliot Berriot's avatar
Eliot Berriot committed
flake8:
  image: python:3.6
  stage: lint
  variables:
    GIT_STRATEGY: fetch
  before_script:
    - pip install flake8
  script:
Eliot Berriot's avatar
Eliot Berriot committed
    key: "$CI_PROJECT_ID__flake8_pip_cache"
    paths:
      - "$PIP_CACHE_DIR"
Eliot Berriot's avatar
Eliot Berriot committed
test_api:
  services:
Eliot Berriot's avatar
Eliot Berriot committed
    - redis:3
Eliot Berriot's avatar
Eliot Berriot committed
  stage: test
  image: funkwhale/funkwhale:develop
    key: "$CI_PROJECT_ID__pip_cache"
    paths:
      - "$PIP_CACHE_DIR"
    DATABASE_URL: "postgresql://postgres@postgres/postgres"
    FUNKWHALE_URL: "https://funkwhale.ci"
Eliot Berriot's avatar
Eliot Berriot committed
    DJANGO_SETTINGS_MODULE: config.settings.local
Eliot Berriot's avatar
Eliot Berriot committed
  before_script:
Eliot Berriot's avatar
Eliot Berriot committed
    - 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
  script:
    - pytest --cov=funkwhale_api tests/
  tags:
    - docker

test_front:
  stage: test
  image: node:9
  before_script:
    - cd front
    - yarn install --check-files
    key: "funkwhale__front_dependencies"
      - front/node_modules
      - front/yarn.lock
  artifacts:
    name: "front_${CI_COMMIT_REF_NAME}"
    paths:
      - front/dist/
Eliot Berriot's avatar
Eliot Berriot committed
  tags:
Eliot Berriot's avatar
Eliot Berriot committed

build_front:
  stage: build
Eliot Berriot's avatar
Eliot Berriot committed
  before_script:
Eliot Berriot's avatar
Eliot Berriot committed
    - 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
    - cd front
  script:
    - yarn install
    - yarn run i18n-compile
    # this is to ensure we don't have any errors in the output,
Eliot Berriot's avatar
Eliot Berriot committed
    # cf https://dev.funkwhale.audio/funkwhale/funkwhale/issues/169
    - yarn build | tee /dev/stderr | (! grep -i 'ERROR in')
Eliot Berriot's avatar
Eliot Berriot committed
  artifacts:
    name: "front_${CI_COMMIT_REF_NAME}"
    paths:
      - front/dist/
  only:
    - tags@funkwhale/funkwhale
    - master@funkwhale/funkwhale
    - develop@funkwhale/funkwhale
Eliot Berriot's avatar
Eliot Berriot committed
  tags:
    - docker
Eliot Berriot's avatar
Eliot Berriot committed
  stage: test
  image: python:3.6
  variables:
    BUILD_PATH: "../public"
  before_script:
    - cd docs
    - apt-get update
    - apt-get install -y graphviz
    - pip install sphinx
    - ./build_docs.sh
Eliot Berriot's avatar
Eliot Berriot committed
  cache:
    key: "$CI_PROJECT_ID__sphinx"
    paths:
      - "$PIP_CACHE_DIR"
  artifacts:
    paths:
      - public
  only:
Eliot Berriot's avatar
Eliot Berriot committed
  tags:
    - docker
  stage: deploy
Eliot Berriot's avatar
Eliot Berriot committed
  image: bash
    - docker login -u $DOCKER_LOGIN -p $DOCKER_PASSWORD
    - cp -r front/dist api/frontend
Eliot Berriot's avatar
Eliot Berriot committed
    - (if [ "$CI_COMMIT_REF_NAME" == "develop" ]; then ./scripts/set-api-build-metadata.sh $(echo $CI_COMMIT_SHA | cut -c 1-8); fi);
    - docker build -t $IMAGE .
    - docker push $IMAGE
    - develop@funkwhale/funkwhale
    - tags@funkwhale/funkwhale
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

build_api:
  # Simply publish a zip containing api/ directory
  stage: deploy
Eliot Berriot's avatar
Eliot Berriot committed
  image: bash
  artifacts:
    name: "api_${CI_COMMIT_REF_NAME}"
    paths:
      - api
Eliot Berriot's avatar
Eliot Berriot committed
    - (if [ "$CI_COMMIT_REF_NAME" == "develop" ]; then ./scripts/set-api-build-metadata.sh $(echo $CI_COMMIT_SHA | cut -c 1-8); fi);
    - chmod -R 750 api
    - echo Done!
    - tags@funkwhale/funkwhale
    - master@funkwhale/funkwhale
    - develop@funkwhale/funkwhale