diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 663ce9c18faedca6329c096f19a3849a4015be87..b948f105e8df66e66e8d1a09defd5dada4243b51 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,97 +1,116 @@ stages: - - build - - test - - pages - - staging + - build + - test + - pages + - build_image + - staging variables: - IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME + IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME -# ============================= Building section ============================= # -build_backend: - image: docker:latest - stage: build - script: - - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY - - docker build -t $IMAGE_TAG . - - docker push $IMAGE_TAG + +# ========================== Build Testing section =========================== # +build_test_env: + image: python:3.6 + stage: build + script: + - python -m venv .venv + - source .venv/bin/activate + - make install + artifacts: + paths: + - .venv/ + expire_in: 1 hour # ============================== Testing section ============================= # # ----------------------------- Backend subsection --------------------------- # -.test_template_backend: &test_definition_backend - stage: test - image: $IMAGE_TAG - before_script: - - pip install -r requirements.dev.txt +.test_template_virtualenv: &test_definition_virtualenv + image: python:3.6 + before_script: + - source .venv/bin/activate + dependencies: + - build_test_env test_pytest: - <<: *test_definition_backend - services: - - postgres:9.5 - script: - - DJANGO_SETTINGS_MODULE=grady.settings pytest --cov - artifacts: - paths: - - .coverage + <<: *test_definition_virtualenv + stage: test + services: + - postgres:9.5 + script: + - DJANGO_SETTINGS_MODULE=grady.settings pytest --cov + artifacts: + paths: + - .coverage test_flake8: - <<: *test_definition_backend - script: - - flake8 --exclude=migrations --ignore=N802 core + <<: *test_definition_virtualenv + stage: test + script: + - flake8 --exclude=migrations --ignore=N802 core # ----------------------------- Frontend subsection -------------------------- # .test_template_frontend: &test_definition_frontend - image: node:carbon - stage: test - before_script: - - cd frontend/ + image: node:carbon + before_script: + - cd frontend/ test_frontend: - <<: *test_definition_frontend - script: - - yarn install - - yarn test --single-run + <<: *test_definition_frontend + stage: test + script: + - yarn install + - yarn test --single-run # =========================== Gitlab pages section =========================== # test_coverage: - image: $IMAGE_TAG - stage: - pages - script: - - pip install coverage - - coverage html -d public - dependencies: - - test_pytest - artifacts: - paths: - - public - only: - - master + <<: *test_definition_virtualenv + stage: + pages + script: + - coverage html -d public + dependencies: + - test_pytest + artifacts: + paths: + - public + only: + - master + +# =========================== Build Image section ============================ # +build_backend: + image: docker:latest + stage: build_image + script: + - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY + - docker build -t $IMAGE_TAG . + - docker push $IMAGE_TAG + only: + - master # ============================== Staging section ============================= # .staging_template: &staging_definition - stage: staging - image: docker:latest - only: - - master - before_script: - - apk add --update py-pip && pip install docker-compose + stage: staging + image: docker:latest + only: + - master + before_script: + - apk add --update py-pip && pip install docker-compose staging: - <<: *staging_definition - environment: - name: review/$CI_COMMIT_REF_NAME - url: https://staging.grady.janmax.org - on_stop: staging_stop - script: - - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY - - docker-compose up -d --force-recreate + <<: *staging_definition + environment: + name: review/$CI_COMMIT_REF_NAME + url: https://staging.grady.janmax.org + on_stop: staging_stop + script: + - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY + - docker-compose up -d --force-recreate staging_stop: - <<: *staging_definition - script: - - docker-compose rm --force --stop - when: manual - environment: - name: review/$CI_COMMIT_REF_NAME - action: stop + <<: *staging_definition + script: + - docker-compose rm --force --stop + when: manual + environment: + name: review/$CI_COMMIT_REF_NAME + action: stop diff --git a/Makefile b/Makefile index b9dc21017bb8b37e07b0a1ee88195f1f6580b0ce..035e3be63dba808a65b7cd10049ce7e820383ce6 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ isort-check: migrate: python manage.py migrate -install: +install: pip install -r requirements.txt pip install -r requirements.dev.txt