-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
99 lines (91 loc) · 2.9 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
image:
name: docker/compose:1.29.2
services:
- docker:dind
stages:
- test
- build
- deploy
variables:
DOMAIN: localhost
SONOUNO_SERVER_IMAGE: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_BRANCH}-latest
MONGODB_IMAGE: ${CI_REGISTRY_IMAGE}/mongodb:${CI_COMMIT_BRANCH}-latest
MONGOEXPRESS_IMAGE: ${CI_REGISTRY_IMAGE}/mongoexpress:${CI_COMMIT_BRANCH}-latest
NGINX_IMAGE: ${CI_REGISTRY_IMAGE}/nginx:${CI_COMMIT_BRANCH}-latest
before_script:
- docker version
- docker-compose version
tests:
stage: test
interruptible: true
script:
- compose/run-tests-backend.sh
coverage: '/^TOTAL.+?(\d+\%)$/'
build-and-publish:
stage: build
interruptible: true
before_script:
- apk add --no-cache py3-pip py3-wheel py3-cryptography git
- ln -s python3 /usr/bin/python
- python --version
- pip install --upgrade --ignore-installed distlib
- pip install --no-cache-dir "poetry==1.2.0b1" poetry-dynamic-versioning
- cd backend
- poetry version
script:
- ../compose/build.sh
- poetry config repositories.gitlab "$CI_API_V4_URL/projects/$CI_PROJECT_ID/packages/pypi"
- poetry config http-basic.gitlab gitlab-ci-token "$CI_JOB_TOKEN"
- poetry publish --repository gitlab
- echo ${CI_JOB_TOKEN} | docker login -u "${CI_REGISTRY_USER}" --password-stdin "${CI_REGISTRY}"
- docker push ${SONOUNO_SERVER_IMAGE}
- docker push ${MONGODB_IMAGE}
- docker push ${MONGOEXPRESS_IMAGE}
- docker push ${NGINX_IMAGE}
pages:
stage: deploy
interruptible: true
image: python:3.10
before_script:
- pip install poetry
- cd backend
- poetry install
script:
- poetry run mkdocs build --strict --verbose
- mv site ../public
artifacts:
paths:
- public
rules:
- if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
deploy-staging:
stage: deploy
interruptible: true
environment:
name: staging
url: http://37.187.38.200
before_script:
- echo $DOCKER_HOST
- export OLD_DOCKER_HOST=$DOCKER_HOST
- which ssh-agent || ( apk add --update --no-cache openssh-client )
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- echo "$SSH_SERVER_HOSTKEYS" > ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
- docker context create --docker host=ssh://[email protected] --description="Staging docker engine" engine-staging
- unset DOCKER_HOST
- docker context use engine-staging
script:
- echo ${CI_JOB_TOKEN} | docker login -u "${CI_REGISTRY_USER}" --password-stdin "${CI_REGISTRY}"
- docker info
- cd compose
- docker-compose -f docker-compose.yml --env-file .env config > docker-stack.yml
- docker-compose -f docker-stack.yml pull
- docker-compose -f docker-stack.yml down --remove-orphan
- docker network prune --force
- docker-compose -f docker-stack.yml up -d
after_script:
- DOCKER_HOST=$OLD_DOCKER_HOST
- docker context use default