From 072605dea6374439c340e2d6eda0c923ef59174b Mon Sep 17 00:00:00 2001 From: Eliot Berriot <contact@eliotberriot.com> Date: Sun, 25 Jun 2017 16:45:33 +0200 Subject: [PATCH] CI builds / pipeline now run tests and build static assets --- .gitlab-ci.yml | 40 ++++++++++++++++++- api/config/settings/test.py | 1 + api/docker/Dockerfile.base | 10 ----- api/docker/Dockerfile.local | 12 ------ api/docker/Dockerfile.test | 10 ++++- api/funkwhale_api/radios/radios.py | 2 +- api/funkwhale_api/radios/tests/test_radios.py | 3 +- api/requirements/test.txt | 2 +- api/test.yml | 1 - dev.yml | 18 ++++----- 10 files changed, 60 insertions(+), 39 deletions(-) delete mode 100644 api/docker/Dockerfile.base delete mode 100644 api/docker/Dockerfile.local diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a6341011..8742084d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,4 +1,42 @@ -image: docker:latest +stages: + - test + - build + +test_api: + stage: test + before_script: + - docker-compose -f api/test.yml build + script: + - docker-compose -f api/test.yml run test + after_script: + - docker-compose -f api/test.yml run test rm -rf funkwhale_api/media/ + + tags: + - dind + +build_front: + stage: build + image: node:6-alpine + before_script: + - cd front + + script: + - npm install + - npm run build + cache: + key: "$CI_COMMIT_REF_NAME" + paths: + - front/node_modules + artifacts: + name: "front_${CI_COMMIT_REF_NAME}" + paths: + - front/dist/ + only: + - master + - develop + tags: + - docker + # When using dind, it's wise to use the overlayfs driver for # improved performance. diff --git a/api/config/settings/test.py b/api/config/settings/test.py index 1323ff35..b8dd89b0 100644 --- a/api/config/settings/test.py +++ b/api/config/settings/test.py @@ -32,3 +32,4 @@ CELERY_ALWAYS_EAGER = True ########## END CELERY # Your local stuff: Below this line define 3rd party library settings +API_AUTHENTICATION_REQUIRED = False diff --git a/api/docker/Dockerfile.base b/api/docker/Dockerfile.base deleted file mode 100644 index 2617c958..00000000 --- a/api/docker/Dockerfile.base +++ /dev/null @@ -1,10 +0,0 @@ -FROM python:3.5 - -ENV PYTHONUNBUFFERED 1 - -# Requirements have to be pulled and installed here, otherwise caching won't work -COPY ./requirements.apt /requirements.apt -COPY ./install_os_dependencies.sh /install_os_dependencies.sh -RUN bash install_os_dependencies.sh install -COPY ./requirements /requirements -RUN pip install -r /requirements/base.txt diff --git a/api/docker/Dockerfile.local b/api/docker/Dockerfile.local deleted file mode 100644 index b7041045..00000000 --- a/api/docker/Dockerfile.local +++ /dev/null @@ -1,12 +0,0 @@ -FROM python:3.5 - -ENV PYTHONUNBUFFERED 1 - -# Requirements have to be pulled and installed here, otherwise caching won't work -COPY ./requirements.apt /requirements.apt -COPY ./install_os_dependencies.sh /install_os_dependencies.sh -RUN bash install_os_dependencies.sh install -COPY ./requirements /requirements -RUN pip install -r /requirements/local.txt - -WORKDIR /app diff --git a/api/docker/Dockerfile.test b/api/docker/Dockerfile.test index f2e2ef89..eda9f9c8 100644 --- a/api/docker/Dockerfile.test +++ b/api/docker/Dockerfile.test @@ -1,13 +1,19 @@ -FROM funkwhale/apibase +FROM python:3.5 ENV PYTHONUNBUFFERED 1 +ENV PYTHONDONTWRITEBYTECODE 1 # Requirements have to be pulled and installed here, otherwise caching won't work COPY ./requirements.apt /requirements.apt COPY ./install_os_dependencies.sh /install_os_dependencies.sh RUN bash install_os_dependencies.sh install -COPY ./requirements /requirements + +RUN mkdir /requirements +COPY ./requirements/base.txt /requirements +RUN pip install -r /requirements/base.txt +COPY ./requirements/local.txt /requirements RUN pip install -r /requirements/local.txt +COPY ./requirements/test.txt /requirements RUN pip install -r /requirements/test.txt WORKDIR /app diff --git a/api/funkwhale_api/radios/radios.py b/api/funkwhale_api/radios/radios.py index 0f2632fe..43819b9c 100644 --- a/api/funkwhale_api/radios/radios.py +++ b/api/funkwhale_api/radios/radios.py @@ -50,7 +50,7 @@ class SessionRadio(SimpleRadio): def filter_from_session(self, queryset): already_played = self.session.session_tracks.all().values_list('track', flat=True) - queryset = queryset.exclude(pk__in=already_played) + queryset = queryset.exclude(pk__in=list(already_played)) return queryset def pick(self, **kwargs): diff --git a/api/funkwhale_api/radios/tests/test_radios.py b/api/funkwhale_api/radios/tests/test_radios.py index eb839a42..7d069be9 100644 --- a/api/funkwhale_api/radios/tests/test_radios.py +++ b/api/funkwhale_api/radios/tests/test_radios.py @@ -74,12 +74,11 @@ class TestRadios(TestCase): def test_can_use_radio_session_to_filter_choices(self): tracks = mommy.make('music.Track', _quantity=30) - radio = radios.RandomRadio() session = radio.start_session(self.user) for i in range(30): - radio.pick() + p = radio.pick() # ensure 30 differents tracks have been suggested tracks_id = [session_track.track.pk for session_track in session.session_tracks.all()] diff --git a/api/requirements/test.txt b/api/requirements/test.txt index e3540b72..bcb6ef06 100644 --- a/api/requirements/test.txt +++ b/api/requirements/test.txt @@ -7,6 +7,6 @@ coverage==4.0.3 django_coverage_plugin==1.1 flake8==2.5.0 django-test-plus==1.0.11 -factory_boy==2.6.0 +factory_boy>=2.8.1 model_mommy tox diff --git a/api/test.yml b/api/test.yml index c28a8138..dc50a9b5 100644 --- a/api/test.yml +++ b/api/test.yml @@ -6,4 +6,3 @@ test: - .:/app environment: - DJANGO_SETTINGS_MODULE=config.settings.test - - API_AUTHENTICATION_REQUIRED=False diff --git a/dev.yml b/dev.yml index 2144d4b1..526ce1ba 100644 --- a/dev.yml +++ b/dev.yml @@ -52,12 +52,12 @@ services: - redis - celeryworker - nginx: - env_file: .env.dev - build: ./api/compose/nginx - links: - - api - volumes: - - ./api/funkwhale_api/media:/staticfiles/media - ports: - - "0.0.0.0:6001:80" + # nginx: + # env_file: .env.dev + # build: ./api/compose/nginx + # links: + # - api + # volumes: + # - ./api/funkwhale_api/media:/staticfiles/media + # ports: + # - "0.0.0.0:6001:80" -- GitLab