-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
112 lines (101 loc) · 2.64 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
.docker_login: &docker-login
- docker login -u gitlab-ci-token -p ${CI_JOB_TOKEN} ${CI_REGISTRY}
.docker_push: &docker-push
- docker push ${CI_REGISTRY_IMAGE}:${CI_COMMIT_REF_SLUG}
.deploy_docker_compose: &deploy_docker_compose
stage: deploy
image: docker:27.0.3
variables:
DOCKER_HOST: "ssh://${SERVER_USER}@${SERVER_HOST}"
before_script:
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- eval $(ssh-agent -s)
- echo "${SSH_PRIVATE_KEY}" | tr -d '\r' | ssh-add -
- echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- date '+%Y-%m-%d %H:%M:%S'
- TZ='Europe/Moscow' date '+%Y-%m-%d %H:%M:%S'
script:
- export MAGNAT_VERSION="${CI_COMMIT_REF_SLUG} $(TZ='Europe/Moscow' date '+%Y-%m-%d %H:%M:%S')"
- docker compose pull client-backend
- if [ -z `docker compose ps -q db` ] || [ -z `docker ps -q --no-trunc | grep $(docker compose ps -q db)` ];
then docker compose up --no-deps -d; else docker compose up --no-deps -d client-backend; fi
tags:
- docker
cache:
key: $CI_PROJECT_NAME
paths:
- vendor
- public
- rails
stages:
- build
- test
- release
- deploy
build:
stage: build
image: docker:27.0.3
services:
- name: docker:27.0.3-dind
variables:
DOCKER_HOST: tcp://docker:2375
DOCKER_TLS_CERTDIR: ""
DOCKER_DRIVER: overlay2
- name: postgres:14.7-alpine
alias: ${POSTGRES_HOST}
variables:
POSTGRES_HOST: postgresql
POSTGRES_DB: my_app_gitlab
POSTGRES_USER: my_app
POSTGRES_PASSWORD: 'git!ab'
script:
- *docker-login
- docker build --add-host=${POSTGRES_HOST}:$(getent hosts ${POSTGRES_HOST} | awk '{ print $1 }') -t ${CI_REGISTRY_IMAGE}:${CI_COMMIT_REF_SLUG}
--build-arg POSTGRES_HOST=${POSTGRES_HOST} --build-arg POSTGRES_DB=${POSTGRES_DB}
--build-arg POSTGRES_USER=${POSTGRES_USER} --build-arg POSTGRES_PASSWORD=${POSTGRES_PASSWORD} .
- *docker-push
tags:
- docker
only:
changes:
- Dockerfile
- Gemfile
- Gemfile.lock
- app/**/*
- bin/**/*
- config/**/*
- db/**/*
- lib/**/*
- log/**/*
- public/**/*
- storage/**/*
- test/**/*
- vendor/**/*
deploy to dev:
<<: *deploy_docker_compose
# when:
# manual
environment:
name: development
only:
- development
needs:
- job: build
optional: true
tags:
- docker
deploy to prod:
<<: *deploy_docker_compose
when:
manual
environment:
name: production
only:
- main
needs:
- job: build
optional: true
tags:
- docker