Skip to content
Snippets Groups Projects
Verified Commit 756b26c4 authored by Jan Maximilian Michal's avatar Jan Maximilian Michal
Browse files

Minor Refactor of the gitlab-ci file

This hopefully accelerates the pipelines as it uses
caching for pip modules and resticts building the
docker image only for the master branch (Which is
the only branch that is every deployed anyway)
parent fe469148
No related branches found
No related tags found
1 merge request!24Added convenience method to create test data
Pipeline #
stages: stages:
- build - build
- test - test
- pages - pages
- staging - build_image
- staging
variables: variables:
IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
# ============================= Building section ============================= #
build_backend: # ========================== Build Testing section =========================== #
image: docker:latest build_test_env:
stage: build image: python:3.6
script: stage: build
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY script:
- docker build -t $IMAGE_TAG . - python -m venv .venv
- docker push $IMAGE_TAG - source .venv/bin/activate
- make install
artifacts:
paths:
- .venv/
expire_in: 1 hour
# ============================== Testing section ============================= # # ============================== Testing section ============================= #
# ----------------------------- Backend subsection --------------------------- # # ----------------------------- Backend subsection --------------------------- #
.test_template_backend: &test_definition_backend .test_template_virtualenv: &test_definition_virtualenv
stage: test image: python:3.6
image: $IMAGE_TAG before_script:
before_script: - source .venv/bin/activate
- pip install -r requirements.dev.txt dependencies:
- build_test_env
test_pytest: test_pytest:
<<: *test_definition_backend <<: *test_definition_virtualenv
services: stage: test
- postgres:9.5 services:
script: - postgres:9.5
- DJANGO_SETTINGS_MODULE=grady.settings pytest --cov script:
artifacts: - DJANGO_SETTINGS_MODULE=grady.settings pytest --cov
paths: artifacts:
- .coverage paths:
- .coverage
test_flake8: test_flake8:
<<: *test_definition_backend <<: *test_definition_virtualenv
script: stage: test
- flake8 --exclude=migrations --ignore=N802 core script:
- flake8 --exclude=migrations --ignore=N802 core
# ----------------------------- Frontend subsection -------------------------- # # ----------------------------- Frontend subsection -------------------------- #
.test_template_frontend: &test_definition_frontend .test_template_frontend: &test_definition_frontend
image: node:carbon image: node:carbon
stage: test before_script:
before_script: - cd frontend/
- cd frontend/
test_frontend: test_frontend:
<<: *test_definition_frontend <<: *test_definition_frontend
script: stage: test
- yarn install script:
- yarn test --single-run - yarn install
- yarn test --single-run
# =========================== Gitlab pages section =========================== # # =========================== Gitlab pages section =========================== #
test_coverage: test_coverage:
image: $IMAGE_TAG <<: *test_definition_virtualenv
stage: stage:
pages pages
script: script:
- pip install coverage - coverage html -d public
- coverage html -d public dependencies:
dependencies: - test_pytest
- test_pytest artifacts:
artifacts: paths:
paths: - public
- public only:
only: - master
- 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 section ============================= #
.staging_template: &staging_definition .staging_template: &staging_definition
stage: staging stage: staging
image: docker:latest image: docker:latest
only: only:
- master - master
before_script: before_script:
- apk add --update py-pip && pip install docker-compose - apk add --update py-pip && pip install docker-compose
staging: staging:
<<: *staging_definition <<: *staging_definition
environment: environment:
name: review/$CI_COMMIT_REF_NAME name: review/$CI_COMMIT_REF_NAME
url: https://staging.grady.janmax.org url: https://staging.grady.janmax.org
on_stop: staging_stop on_stop: staging_stop
script: script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- docker-compose up -d --force-recreate - docker-compose up -d --force-recreate
staging_stop: staging_stop:
<<: *staging_definition <<: *staging_definition
script: script:
- docker-compose rm --force --stop - docker-compose rm --force --stop
when: manual when: manual
environment: environment:
name: review/$CI_COMMIT_REF_NAME name: review/$CI_COMMIT_REF_NAME
action: stop action: stop
...@@ -23,7 +23,7 @@ isort-check: ...@@ -23,7 +23,7 @@ isort-check:
migrate: migrate:
python manage.py migrate python manage.py migrate
install: install:
pip install -r requirements.txt pip install -r requirements.txt
pip install -r requirements.dev.txt pip install -r requirements.dev.txt
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment