-
Notifications
You must be signed in to change notification settings - Fork 1
170 lines (150 loc) · 5.98 KB
/
build.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
name: Build on push to master
on:
push:
branches:
- master
workflow_dispatch:
jobs:
configure:
name: Configure
runs-on: self-hosted
steps:
- uses: actions/checkout@v3
- name: Copy configs
env:
CONFIGS_LOCATION_BASE: ${{ secrets.CONFIGS_LOCATION_BASE }}
run: |
cp $CONFIGS_LOCATION_BASE/notifier.config.json ./notifier/;
cp $CONFIGS_LOCATION_BASE/scrapper.config.json ./scrapper/;
cp $CONFIGS_LOCATION_BASE/backend.config.json ./backend/;
cp $CONFIGS_LOCATION_BASE/panel.config.json ./panel/;
cp $CONFIGS_LOCATION_BASE/grafana.ini ./monitoring/grafana/;
cp $CONFIGS_LOCATION_BASE/healthcheck.config.json ./healthcheck/;
cp $CONFIGS_LOCATION_BASE/telegram-bot.config.json ./telegram/
[[ -f $CONFIGS_LOCATION_BASE/tag-manager.html ]] &&
cp $CONFIGS_LOCATION_BASE/tag-manager.html ./frontend/src/config/tag-manager.html ||
echo "" > ./frontend/src/config/tag-manager.html;
[[ -f $CONFIGS_LOCATION_BASE/apps-links.json ]] &&
cp $CONFIGS_LOCATION_BASE/apps-links.json ./frontend/src/config/apps-links.json ||
echo "[]" > ./frontend/src/config/apps-links.json;
[[ -d $CONFIGS_LOCATION_BASE/platforms/ ]] &&
cp -r $CONFIGS_LOCATION_BASE/platforms ./frontend/public/img/
build:
name: Local Docker build
runs-on: self-hosted
needs: configure
steps:
- name: Build Docker images
env:
CONFIGS_LOCATION_BASE: ${{ secrets.CONFIGS_LOCATION_BASE }}
run: docker compose -f docker-compose.yml --env-file $CONFIGS_LOCATION_BASE/docker.env build --no-cache
testing:
name: Unit and integration tests
runs-on: self-hosted
if: "contains(github.event.head_commit.message, 'Run tests')"
needs: configure
steps:
- name: Build & test Docker images
env:
CONFIGS_LOCATION_BASE: ${{ secrets.CONFIGS_LOCATION_BASE }}
run: docker compose -f docker-compose.testing.yml --env-file $CONFIGS_LOCATION_BASE/docker.env build --no-cache
deploy:
name: Local Docker deploy
runs-on: self-hosted
if: always()
needs:
- build
- testing
steps:
- name: Deploy Docker images
env:
CONFIGS_LOCATION_BASE: ${{ secrets.CONFIGS_LOCATION_BASE }}
run: docker compose -f docker-compose.yml --env-file $CONFIGS_LOCATION_BASE/docker.env up -d --force-recreate --no-deps
docker-hub:
name: Push to Docker Hub
runs-on: self-hosted
if: "contains(github.event.head_commit.message, 'Run Cloud deploy')"
needs:
- build
- testing
env:
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
DOCKER_HUB_ACCESS_TOKEN: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
steps:
- name: Retag container
run: docker tag mss-backend:latest $DOCKER_HUB_USERNAME/mss-backend:latest
- name: Log into Docker Hub
run: |
echo "$DOCKER_HUB_ACCESS_TOKEN" | docker login --username "$DOCKER_HUB_USERNAME" --password-stdin
- name: Push to Docker Hub
run: docker push $DOCKER_HUB_USERNAME/mss-backend:latest
- name: Docker logout
run: docker logout
yandex-cloud:
name: Yandex Cloud build & deploy
runs-on: self-hosted
if: "contains(github.event.head_commit.message, 'Run Cloud deploy')"
needs:
- build
- testing
- docker-hub
env:
YANDEX_CLOUD_REGISTRY_ID: ${{ secrets.YANDEX_CLOUD_REGISTRY_ID }}
YANDEX_CLOUD_IMAGE_NAME: ${{ secrets.YANDEX_CLOUD_IMAGE_NAME }}
CONFIGS_LOCATION_BASE: ${{ secrets.CONFIGS_LOCATION_BASE }}
YANDEX_CLOUD_JSON_KEYS_FILENAME: ${{ secrets.YANDEX_CLOUD_JSON_KEYS_FILENAME }}
steps:
- name: Build Docker image
run: cd healthcheck && docker build . -t cr.yandex/$YANDEX_CLOUD_REGISTRY_ID/$YANDEX_CLOUD_IMAGE_NAME:latest
- name: Log into Yandex Cloud
run: |
cat $CONFIGS_LOCATION_BASE/$YANDEX_CLOUD_JSON_KEYS_FILENAME | docker login --username json_key --password-stdin cr.yandex
- name: Push to Yandex Cloud
run: |
docker push cr.yandex/$YANDEX_CLOUD_REGISTRY_ID/$YANDEX_CLOUD_IMAGE_NAME:latest
- name: Deploy serverless container
uses: yc-actions/yc-sls-container-deploy@v2
with:
yc-sa-json-credentials: ${{ secrets.YANDEX_CLOUD_JSON_KEYS }}
container-name: ${{ secrets.YANDEX_CLOUD_IMAGE_NAME }}
folder-id: ${{ secrets.YANDEX_CLOUD_FOLDER_ID }}
revision-service-account-id: ${{ secrets.YANDEX_CLOUD_SERVICE_ACCOUNT_ID }}
revision-image-url: cr.yandex/${{ secrets.YANDEX_CLOUD_REGISTRY_ID }}/${{ secrets.YANDEX_CLOUD_IMAGE_NAME }}:latest
revision-cores: 1
revision-memory: 256Mb
revision-env: |
CHECKING_ORIGIN=https://mirea.xyz
API_VERSION=1.3
- name: Docker logout
run: docker logout
clean:
name: Clean unused images
runs-on: self-hosted
if: always()
needs:
- deploy
- yandex-cloud
steps:
- name: Clean local images
run: |
DANGLING_IMAGES=$(docker images -qf "dangling=true");
[[ ! -z "$DANGLING_IMAGES" ]] && docker rmi $DANGLING_IMAGES || echo "No dangling images"
- name: Clean testing images
run: |
TESTING_IMAGES=$(docker images -qf "reference=mss-*:testing");
[[ ! -z "$TESTING_IMAGES" ]] && docker rmi $TESTING_IMAGES || echo "No testing images"
notify:
name: Logging
runs-on: self-hosted
if: always()
needs:
- deploy
- yandex-cloud
steps:
- name: Send logs via notifier
env:
CONFIGS_LOCATION_BASE: ${{ secrets.CONFIGS_LOCATION_BASE }}
run: |
source $CONFIGS_LOCATION_BASE/docker.env;
curl http://127.0.0.1:$NOTIFIER_PUBLISH_PORT -d "{\"error\":false,\"args\":[\"Done merge into master, initiator – $GITHUB_ACTOR\"],\"tag\":\"ci\"}" ||
echo "Done merge into master, initiator – $GITHUB_ACTOR"