forked from SaintAngeLs/distributed_minispace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
206 lines (186 loc) · 5.83 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
stages:
- build
- deploy
variables:
DOCKER_REGISTRY: registry.gitlab.com
DOCKER_IMAGE: $DOCKER_REGISTRY/distributed-asp-net-core-blazor-social-app/distributed_minispace
services:
- docker:dind
before_script:
- echo "$CI_REGISTRY_PASSWORD" | docker login $CI_REGISTRY -u $CI_REGISTRY_USER --password-stdin
.build_template: &build_template
stage: build
image: docker:latest
script:
- docker build -t $DOCKER_IMAGE/$SERVICE_NAME:latest $SERVICE_PATH
- docker push $DOCKER_IMAGE/$SERVICE_NAME:latest
build_api_gateway:
<<: *build_template
variables:
SERVICE_NAME: api-gateway
SERVICE_PATH: MiniSpace.APIGateway
rules:
- if: '$CI_COMMIT_MESSAGE =~ /deploy-all/'
- if: '$CI_COMMIT_MESSAGE !~ /deploy/'
changes:
- MiniSpace.APIGateway/**
build_web:
<<: *build_template
variables:
SERVICE_NAME: web
SERVICE_PATH: MiniSpace.Web
rules:
- if: '$CI_COMMIT_MESSAGE =~ /deploy-all/'
- if: '$CI_COMMIT_MESSAGE !~ /deploy/'
changes:
- MiniSpace.Web/**
build_services_identity:
<<: *build_template
variables:
SERVICE_NAME: services-identity
SERVICE_PATH: MiniSpace.Services.Identity
rules:
- if: '$CI_COMMIT_MESSAGE =~ /deploy-all/'
- if: '$CI_COMMIT_MESSAGE !~ /deploy/'
changes:
- MiniSpace.Services.Identity/**
build_services_events:
<<: *build_template
variables:
SERVICE_NAME: services-events
SERVICE_PATH: MiniSpace.Services.Events
rules:
- if: '$CI_COMMIT_MESSAGE =~ /deploy-all/'
- if: '$CI_COMMIT_MESSAGE !~ /deploy/'
changes:
- MiniSpace.Services.Events/**
build_services_students:
<<: *build_template
variables:
SERVICE_NAME: services-students
SERVICE_PATH: MiniSpace.Services.Students
rules:
- if: '$CI_COMMIT_MESSAGE =~ /deploy-all/'
- if: '$CI_COMMIT_MESSAGE !~ /deploy/'
changes:
- MiniSpace.Services.Students/**
build_services_friends:
<<: *build_template
variables:
SERVICE_NAME: services-friends
SERVICE_PATH: MiniSpace.Services.Friends
rules:
- if: '$CI_COMMIT_MESSAGE =~ /deploy-all/'
- if: '$CI_COMMIT_MESSAGE !~ /deploy/'
changes:
- MiniSpace.Services.Friends/**
build_services_reactions:
<<: *build_template
variables:
SERVICE_NAME: services-reactions
SERVICE_PATH: MiniSpace.Services.Reactions
rules:
- if: '$CI_COMMIT_MESSAGE =~ /deploy-all/'
- if: '$CI_COMMIT_MESSAGE !~ /deploy/'
changes:
- MiniSpace.Services.Reactions/**
build_services_posts:
<<: *build_template
variables:
SERVICE_NAME: services-posts
SERVICE_PATH: MiniSpace.Services.Posts
rules:
- if: '$CI_COMMIT_MESSAGE =~ /deploy-all/'
- if: '$CI_COMMIT_MESSAGE !~ /deploy/'
changes:
- MiniSpace.Services.Posts/**
build_services_comments:
<<: *build_template
variables:
SERVICE_NAME: services-comments
SERVICE_PATH: MiniSpace.Services.Comments
rules:
- if: '$CI_COMMIT_MESSAGE =~ /deploy-all/'
- if: '$CI_COMMIT_MESSAGE !~ /deploy/'
changes:
- MiniSpace.Services.Comments/**
build_services_mediafiles:
<<: *build_template
variables:
SERVICE_NAME: services-mediafiles
SERVICE_PATH: MiniSpace.Services.MediaFiles
rules:
- if: '$CI_COMMIT_MESSAGE =~ /deploy-all/'
- if: '$CI_COMMIT_MESSAGE !~ /deploy/'
changes:
- MiniSpace.Services.MediaFiles/**
# build_services_organizations:
# <<: *build_template
# variables:
# SERVICE_NAME: services-organizations
# SERVICE_PATH: MiniSpace.Services.Organizations
# rules:
# - if: '$CI_COMMIT_MESSAGE =~ /deploy-all/'
# - if: '$CI_COMMIT_MESSAGE !~ /deploy/'
# changes:
# - MiniSpace.Services.Organizations/**
build_services_notifications:
<<: *build_template
variables:
SERVICE_NAME: services-notifications
SERVICE_PATH: MiniSpace.Services.Notifications
rules:
- if: '$CI_COMMIT_MESSAGE =~ /deploy-all/'
- if: '$CI_COMMIT_MESSAGE !~ /deploy/'
changes:
- MiniSpace.Services.Notifications/**
build_services_reports:
<<: *build_template
variables:
SERVICE_NAME: services-reports
SERVICE_PATH: MiniSpace.Services.Reports
rules:
- if: '$CI_COMMIT_MESSAGE =~ /deploy-all/'
- if: '$CI_COMMIT_MESSAGE !~ /deploy/'
changes:
- MiniSpace.Services.Reports/**
build_services_email:
<<: *build_template
variables:
SERVICE_NAME: services-email
SERVICE_PATH: MiniSpace.Services.Email
rules:
- if: '$CI_COMMIT_MESSAGE =~ /deploy-all/'
- if: '$CI_COMMIT_MESSAGE !~ /deploy/'
changes:
- MiniSpace.Services.Email/**
deploy:
stage: deploy
image: docker:latest
script:
- apk add --no-cache openssh
- mkdir -p ~/.ssh
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
- ssh-keyscan -H $PRODUCTION_SERVER_IP >> ~/.ssh/known_hosts
- scp ./MiniSpace/compose/services-prod.yml $PRODUCTION_SERVER_USER@$PRODUCTION_SERVER_IP:/root/social_net_app
- ssh $PRODUCTION_SERVER_USER@$PRODUCTION_SERVER_IP 'bash -s' < deploy.sh $GITLAB_TOKEN
rules:
- if: '$CI_COMMIT_BRANCH == "main" && $CI_COMMIT_MESSAGE =~ /deploy-all/'
- if: '$CI_COMMIT_BRANCH == "main" && $CI_COMMIT_MESSAGE =~ /deploy/'
- if: '$CI_COMMIT_BRANCH == "main" && $CI_COMMIT_MESSAGE !~ /deploy-all/ && $CI_COMMIT_MESSAGE !~ /deploy/'
changes:
- MiniSpace.APIGateway/**
- MiniSpace.Web/**
- MiniSpace.Services.Identity/**
- MiniSpace.Services.Events/**
- MiniSpace.Services.Students/**
- MiniSpace.Services.Friends/**
- MiniSpace.Services.Reactions/**
- MiniSpace.Services.Posts/**
- MiniSpace.Services.Comments/**
- MiniSpace.Services.MediaFiles/**
- MiniSpace.Services.Notifications/**
- MiniSpace.Services.Reports/**
- MiniSpace.Services.Email/**
# - MiniSpace.Services.Organizations/**