.gitlab-ci.yml 1.9 KB
Newer Older
okhin's avatar
okhin committed
1
2
3
4
5
variables:
    PIP_CACHE_DIR: "$CI_PROJECT_DIR/pip-cache"

cache:
    paths:
6
7
        - "pip-cache"
        - "env"
okhin's avatar
okhin committed
8
9
10
11
12
13
14
15
16
17
    key: "$CI_PROJECT_ID"

stages:
    - test
    - build
    - deploy

unit tests:
    stage: test
    script:
okhin's avatar
okhin committed
18
        - virtualenv -p python3 env
okhin's avatar
okhin committed
19
20
21
22
23
24
        - source ./env/bin/activate
        - pip install -r requirements.txt
        - pip install -r requirements-dev.txt
        - pip install -r requirements-tests.txt
        - echo "DEBUG = True" > ./project/settings/env.py
        - echo "SECRET_KEY = '$(pwgen 20 1)'" >> ./project/settings/env.py
25
        - ./manage.py migrate
okhin's avatar
okhin committed
26
27
        - pytest apps/ --cov=apps/
    tags: [preprod]
28
29

static build:
okhin's avatar
okhin committed
30
    stage: build
31
    script:
32
        - virtualenv -p python3 env
33
34
        - source ./env/bin/activate
        - pip install -r requirements.txt
35
36
37
        - yarn install
        - webpack
        - echo "DEBUG = False" > ./project/settings/env.py
38
39
40
        - echo "SECRET_KEY = '$(pwgen 20 1)'" >> ./project/settings/env.py
        - ./manage.py collectstatic
    tags: [preprod]
41
42
43
44
    artifacts:
        paths:
            - static/
        expire_in: 1 day
okhin's avatar
okhin committed
45
46
47

deploy preprod:
    variables:
okhin's avatar
okhin committed
48
49
        BASE_PATH: /srv/rp/rp-rp2
        VIRTUALENV: /srv/rp/env
okhin's avatar
okhin committed
50
51
    stage: deploy
    script:
okhin's avatar
okhin committed
52
        - rsync --exclude 'env' --exclude 'pip-cache' --exclude '.git' -r --chown rp:www-data --chmod g+srw ./ ${BASE_PATH}
okhin's avatar
okhin committed
53
54
        - source ${VIRTUALENV}/bin/activate
        - pip install --upgrade pip
55
        - pip install --upgrade -r requirements.txt
okhin's avatar
okhin committed
56
        - pip install --upgrade -r requirements-dev.txt
okhin's avatar
okhin committed
57
        - echo "DEBUG = True" > ${BASE_PATH}/project/settings/env.py
58
        - echo "SECRET_KEY = '$(pwgen 20 1)'" >> ${BASE_PATH}/project/settings/env.py
okhin's avatar
okhin committed
59
        - echo "SITE_ID = 2" >> ${BASE_PATH}/project/settings/env.py
60
        - ${BASE_PATH}/manage.py migrate
okhin's avatar
okhin committed
61
        - chmod g+srw ${BASE_PATH}/db.sqlite3
okhin's avatar
okhin committed
62
        - touch ${BASE_PATH}/ready
63
64
    only:
        - rp2
okhin's avatar
okhin committed
65
    tags: [preprod]