aboutsummaryrefslogtreecommitdiffstats
path: root/.gitlab-ci.yml
blob: c6fad330c4485fc18c234929eb59be1a1d3240fc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
stages:
    - lint
    - test
    - publish
    - deploy
image: python:3.7-alpine

.test-template: &test-template
    stage: test
    services:
        - postgres:10-alpine
    script:
        - python manage.py test
    tags:
        - docker
    variables:
        DATABASE_URL: postgres://django:supersecret@postgres/pysite
        POSTGRES_DB: pysite
        POSTGRES_PASSWORD: supersecret
        POSTGRES_USER: django

lint:
    stage: lint
    before_script:
        - apk add python3-dev git libpq postgresql-dev gcc cmake autoconf automake musl-dev
        - python3 -m pip install --no-cache-dir .[lint]
    script:
        - flake8
    tags:
        - docker

test-3.7-alpine:
    <<: *test-template
    image: python:3.7-alpine
    before_script:
        - apk add python3-dev git libpq postgresql-dev gcc cmake autoconf automake musl-dev
        - python3 -m pip install --no-cache-dir .[test]
        - python manage.py migrate
    script:
        - coverage run --source=api,home,pysite,wiki --branch manage.py test
    after_script:
        - coverage report
    artifacts:
        paths:
            - .coverage

test-3.6-alpine:
    <<: *test-template
    image: python:3.6-alpine
    before_script:
        - apk add git libpq postgresql-dev gcc cmake autoconf automake musl-dev
        - python3 -m pip install --no-cache-dir .[test]
        - python manage.py migrate

test-3.7-stretch:
    <<: *test-template
    image: python:3.7-stretch
    services:
        - postgres:11
    before_script:
        - apt-get update -y
        - apt-get install -y git libpq-dev gcc cmake autoconf automake libc-dev
        - python3 -m pip install --no-cache-dir .[test]
        - python manage.py migrate

test-3.6-stretch:
    <<: *test-template
    image: python:3.6-stretch
    services:
        - postgres:11
    before_script:
        - apt-get update -y
        - apt-get install -y git libpq-dev gcc cmake autoconf automake libc-dev
        - python3 -m pip install --no-cache-dir .[test]
        - python manage.py migrate

pages:
    stage: publish
    dependencies:
        - test-3.7-alpine
    before_script:
        - pip install coverage
    script:
        - coverage html --directory=public
    artifacts:
        paths:
            - public
        expire_in: 30 days

push-django:
    image: docker:stable-git
    stage: publish
    script:
        - echo "$DOCKER_PASSWORD" | docker login --username "$DOCKER_USERNAME" --password-stdin
        - docker build -t pythondiscord/django:latest .
        - docker push pythondiscord/django:latest
    only:
        - master
        - django
    tags:
        - docker

deploy:
    stage: deploy
    image: alpine:latest
    before_script:
        - apk add --no-cache openssh-client
        - mkdir .ssh
        - chmod 700 .ssh
        - echo "[jchri.st]:583 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBDfASki6pPLNwInyoRmUc4qH9JZd9SJeSofNOLiOxlJ3JUuLrLil7L4JPgC+RY5Rneb3Z7+S3cc7BmBDG5s2+lU" > .ssh/known_hosts
        - chmod 400 .ssh/known_hosts
        - echo "$DJANGO_DEPLOY_SSH_PRIVATE_KEY" > privkey
    script:
        - ssh -i privkey -p 583 [email protected]
    environment:
        name: Django staging
        url: https://pysite.jchri.st
    tags:
        - docker