-
Notifications
You must be signed in to change notification settings - Fork 8
/
.gitlab-ci.yml
125 lines (102 loc) · 2.97 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
125
stages:
- test
- build
- deploy
test-backend:
image: python:latest
stage: test
variables:
POSTGRES_DB: "sikshyalaya"
POSTGRES_USER: "postadmin"
POSTGRES_PASSWORD: "postpass"
CONFIG_PATH: "etc/dock.yml"
REDIS_HOST: redis
services:
- name: postgres:13-alpine
- name: redis:6-alpine
alias: redis
command: [ "--requirepass redispass" ]
- name: mailhog/mailhog
alias: mailhog
before_script:
- curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -
- source $HOME/.poetry/env
- cd backend && poetry config virtualenvs.create false && poetry install --no-dev
script:
- python manage.py remake
- python manage.py pytest
rules:
- if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "main"'
changes:
- backend/**/*
- if: '$CI_COMMIT_BRANCH == "main"'
changes:
- backend/**/*
build-backend:
image: docker:latest
stage: build
services:
- docker:dind
before_script:
- echo $CI_BUILD_TOKEN | docker login -u "$CI_REGISTRY_USER" --password-stdin $CI_REGISTRY
script:
- cd backend
- docker build --pull -t "$CI_REGISTRY_IMAGE/backend" .
- docker push "$CI_REGISTRY_IMAGE/backend"
rules:
- if: '$CI_COMMIT_BRANCH == "main"'
changes:
- backend/**/*
build-file-server:
image: docker:latest
stage: build
services:
- docker:dind
before_script:
- echo $CI_BUILD_TOKEN | docker login -u "$CI_REGISTRY_USER" --password-stdin $CI_REGISTRY
script:
- cd file_server
- docker build --pull -t "$CI_REGISTRY_IMAGE/file_server" .
- docker push "$CI_REGISTRY_IMAGE/file_server"
rules:
- if: '$CI_COMMIT_BRANCH == "main"'
changes:
- file_server/**/*
build-web:
image: docker:latest
stage: build
services:
- docker:dind
before_script:
- echo $CI_BUILD_TOKEN | docker login -u "$CI_REGISTRY_USER" --password-stdin $CI_REGISTRY
script:
- cd web
- docker build --no-cache --pull -t "$CI_REGISTRY_IMAGE/web:latest" .
- docker push "$CI_REGISTRY_IMAGE/web:latest"
- docker build --no-cache --build-arg TARGET_BUILD_ENV=local --pull -t "$CI_REGISTRY_IMAGE/web:local" .
- docker push "$CI_REGISTRY_IMAGE/web:local"
rules:
- if: '$CI_COMMIT_BRANCH == "main"'
changes:
- web/**/*
deploy:
stage: deploy
image: kroniak/ssh-client
variables:
DEPLOY_SSH_HOST: $DEPLOY_SSH_HOST
DEPLOY_PRIVATE_KEY: $DEPLOY_PRIVATE_KEY
script:
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
- echo "$DEPLOY_PRIVATE_KEY" > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
- echo $DEPLOY_SSH_HOST
- echo $DEPLOY_SSH_HOST
- ssh -tt daze@$DEPLOY_SSH_HOST 'cd ~/app && docker-compose down && docker-compose pull && docker-compose up -d'
rules:
- if: '$CI_COMMIT_BRANCH == "main"'
changes:
- backend/**/*
- file_server/**/*
- web/**/*