-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
55 lines (50 loc) · 1.42 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
stages:
- test
- build
- deploy
.build-image: &build_image
image: docker:latest
services:
- docker:18.09-dind
before_script:
- docker system prune -f
- echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY
- docker build -t $CI_REGISTRY_IMAGE --push .
after_script:
- docker logout $CI_REGISTRY
build-job:
<<: *build_image
stage: build
rules:
- if: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "main"
script:
- docker run -d -v "${PWD}:/usr/src/app" -p 4555:4555 $CI_REGISTRY_IMAGE
- lsof -i:4555 || { echo tsy mpah ; docker ps -a ; exit 1 ; }
lint-test-job:
stage: test
rules:
- if: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "main"
before_script:
- apt-get update -y
- apt-get install python3-pip -y
script:
- python3 -m pip install flake8
- flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
deploy-job:
stage: deploy
environment: production
script:
- apt-get update -y -qq
- apt-get install -y -qq sshpass
- export SSHPASS=$PASSWORD_SERVER
- |
sshpass -e ssh -t -oStrictHostKeyChecking=no "$USER_SERVER@$HOST_SERVER" <<EOF
cd /opt/voting-bot
git pull
docker rm -f voting-bot
docker rmi -f voting-bot-image
docker build -t voting-bot-image .
docker run --name voting-bot -d -p 4555:4555 voting-bot-image
EOF
only:
- main