This repository has been archived by the owner on Apr 21, 2020. It is now read-only.
/
.gitlab-ci.yml
124 lines (112 loc) · 2.92 KB
/
.gitlab-ci.yml
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
120
121
122
123
124
stages:
- build
- test
- deploy
variables:
PIPENV_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pipenv"
PIPENV_VENV_IN_PROJECT: "true"
# ignore the pipenv environment variables, rely on gitlab ci
PIPENV_DONT_LOAD_ENV: "true"
POSTGRES_DB: "postgres"
POSTGRES_USER: "postgres"
POSTGRES_PASSWORD: ""
POSTGRES_HOST: "postgres"
POSTGRES_HOST_AUTH_METHOD: "trust"
DJANGO_SECRET_KEY: "DJANGO_SECRET_KEY"
DJANGO_SETTINGS_MODULE: "mellophone.settings_local"
# https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#container-registry-examples
DOCKER_HOST: tcp://docker:2375
DOCKER_DRIVER: overlay2
DOCKER_REGISTRY: registry.gitlab.com
DOCKER_IMAGE_TAG: $DOCKER_REGISTRY/nchlswhttkr/mellophone:$CI_COMMIT_REF_SLUG
cache:
paths:
- .cache
- .venv
- mellophone/frontend/node_modules
"FE Linting":
image: node:10-alpine
stage: test
allow_failure: true
script:
- cd mellophone/frontend
- yarn
- yarn lint
"FE Testing":
image: node:10-alpine
stage: test
script:
- cd mellophone/frontend
- yarn
- yarn test --verbose
"FE Install/Build":
image: node:10-alpine
stage: build
artifacts:
paths:
- mellophone/frontend/build
script:
- cd mellophone/frontend
- yarn
- REACT_APP_COMMIT_SHA=$CI_COMMIT_SHORT_SHA yarn build
"BE Linting":
image: $DOCKER_IMAGE_TAG
stage: test
allow_failure: true
script:
- pipenv clean
- pipenv sync --dev --keep-outdated
- pipenv run lint --check
"BE Testing":
image: $DOCKER_IMAGE_TAG
stage: test
services:
- postgres:10
script:
- pipenv clean
- pipenv sync --keep-outdated
- pipenv run test-unit
"E2E Testing":
image: $DOCKER_IMAGE_TAG
stage: test
services:
- postgres:10
artifacts:
when: on_failure
paths:
- e2e
script:
- pipenv clean
- pipenv sync --dev --keep-outdated
- pipenv run migrate
- pipenv run python mellophone/manage.py collectstatic --clear --no-input --no-post-process
- sh scripts/test-e2e.sh
"Deploy":
image: $DOCKER_IMAGE_TAG
stage: deploy
environment:
name: production
# url: https://mellophone.pink
only:
- master
script:
- eval $(ssh-agent -s)
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan $PRODUCTION_IP > ~/.ssh/known_hosts
- echo "$PRODUCTION_PRIVATE_SSH_KEY" | tr -d '\r' | ssh-add - > /dev/null
- pipenv sync --keep-outdated
- pipenv run python mellophone/manage.py collectstatic --clear --no-input --no-post-process
- rsync -a -e ssh --delete-excluded --exclude-from=.rsyncignore config mellophone Pipfile Pipfile.lock mellophone@$PRODUCTION_IP:~/latest-deployment
"Dev Image Build":
image: docker:stable
services:
- docker:dind
stage: build
only:
changes:
- Dockerfile
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $DOCKER_REGISTRY
- docker build -t $DOCKER_IMAGE_TAG - < Dockerfile
- docker push $DOCKER_IMAGE_TAG