website/.gitlab-ci.yml

167 lines
3.3 KiB
YAML
Raw Normal View History

2022-06-10 16:45:04 +01:00
stages:
- build
- test
- deploy
2022-06-10 16:45:04 +01:00
static:
image: node:alpine
stage: build
cache:
2022-06-10 16:56:07 +01:00
key: npm-$CI_COMMIT_REF_SLUG
2022-06-10 16:45:04 +01:00
paths:
2022-06-10 16:56:07 +01:00
- "$CI_PROJECT_DIR/.npm-cache"
2022-06-12 19:42:15 +01:00
before_script:
- apk add --no-cache bash
2022-06-10 16:45:04 +01:00
script:
2022-06-10 16:56:07 +01:00
- npm ci --cache .npm-cache --prefer-offline
2022-06-10 16:45:04 +01:00
- npm run build
artifacts:
name: '$CI_JOB_ID-node_modules'
paths:
- ./node_modules
- ./static/build
expire_in: 30 mins
pip:
image: python:3.10
2022-06-10 16:45:04 +01:00
stage: build
2022-06-10 16:56:07 +01:00
variables:
PIP_CACHE_DIR: $CI_PROJECT_DIR/.pip-cache
cache:
key: pip-$CI_COMMIT_REF_SLUG
paths:
- "$CI_PROJECT_DIR/.pip-cache"
2022-06-10 16:45:04 +01:00
script:
- python -m venv env
- source env/bin/activate
- pip install -r requirements/dev.txt
2022-06-10 16:45:04 +01:00
artifacts:
name: 'pip-$CI_JOB_ID'
paths:
- ./env/
expire_in: 30 mins
build_container:
image: docker:stable
services:
- docker:dind
variables:
IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
DOCKER_BUILDKIT: 1
dependencies: []
stage: test
2022-08-25 14:27:14 +01:00
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
script:
2022-08-25 14:27:14 +01:00
- docker build -t website --target production -t $IMAGE_TAG .
- docker push $IMAGE_TAG
.python_test_template:
image: python:3.10
2022-06-10 16:45:04 +01:00
stage: test
dependencies:
- pip
before_script:
- source env/bin/activate
2022-06-10 16:56:25 +01:00
variables:
SECRET_KEY: super-secret
test_python:
extends: .python_test_template
2022-07-28 20:41:30 +01:00
services:
- postgres:13-alpine
variables:
POSTGRES_HOST_AUTH_METHOD: trust
2022-07-28 20:41:30 +01:00
DATABASE_URL: postgres://postgres@postgres/postgres
script:
- ./manage.py collectstatic --noinput --clear
2022-08-17 19:09:07 +01:00
- coverage run ./manage.py test
- coverage report
- coverage xml
coverage: '/(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/'
artifacts:
reports:
coverage_report:
coverage_format: cobertura
path: coverage.xml
dependencies:
- pip
- static
django_checks:
extends: .python_test_template
script:
- ./manage.py check
- ./manage.py makemigrations --check --noinput
2022-06-12 15:17:28 +01:00
black:
extends: .python_test_template
script:
- black --check .
isort:
extends: .python_test_template
script:
- isort --check .
flake8:
extends: .python_test_template
script:
- flake8
mypy:
extends: .python_test_template
2022-06-12 15:17:28 +01:00
script:
- mypy .
2022-06-12 19:35:06 +01:00
2022-08-03 20:22:02 +01:00
curlylint:
extends: .python_test_template
2022-08-03 20:22:02 +01:00
script:
- curlylint .
2022-08-03 20:37:34 +01:00
djhtml:
extends: .python_test_template
2022-08-03 20:37:34 +01:00
script:
- git ls-files '*.html' | xargs djhtml --check --tabwidth 2
2022-08-03 20:55:09 +01:00
npm_lint:
image: node:alpine
stage: test
dependencies:
- static
2022-06-12 19:35:06 +01:00
script:
- npm run lint
pip_tools:
extends: .python_test_template
script:
- ./scripts/compile-requirements.sh
- git diff
- git diff-index --quiet HEAD --
crontab:
image: alpine
stage: test
dependencies: []
before_script:
- apk add --no-cache supercronic
script:
- supercronic -test etc/crontab
deploy_container:
image: docker:stable
services:
- docker:dind
variables:
SRC_IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
DEST_IMAGE_TAG: $CI_REGISTRY_IMAGE:latest
DOCKER_BUILDKIT: 1
dependencies: []
stage: deploy
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
script:
- docker pull $SRC_IMAGE_TAG
- docker tag $SRC_IMAGE_TAG $DEST_IMAGE_TAG
- docker push $DEST_IMAGE_TAG