-
Notifications
You must be signed in to change notification settings - Fork 0
140 lines (123 loc) · 4.27 KB
/
docker-release.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
name: Deploy docker compose
on:
# secrets для ручного запуска храняться в репозитории CI-CD
workflow_dispatch:
inputs:
compose_folder:
description: "Путь к директории с целевым compose.yml"
type: string
required: true
env_file_name:
description: "Путь к файлу *.env нужного образа"
type: string
required: true
compose_service_name:
description: "Имя сервиса, который собираемся обновить"
type: string
required: true
image_tag_env:
description: "Переменная окружения для тега версии образа *_TAG={значение}"
type: string
required: true
image_port_env:
description: "Переменная окружения для порта образа *_PORT={значение}"
type: string
required: true
environment_name:
description: "Название стенда"
type: choice
required: true
default: 'workflow_test'
options:
- development
- production
- workflow_test
project_name:
description: "Название проекта"
type: string
required: true
workflow_call:
inputs:
compose_folder:
type: string
required: true
env_file_name:
type: string
required: true
compose_service_name:
type: string
required: true
image_tag_env:
type: string
required: true
image_port_env:
type: string
required: true
environment_name:
type: string
required: true
project_name:
type: string
required: true
secrets:
SSH_PRIVATE_KEY:
required: true
SSH_HOST:
required: true
SSH_USER:
required: true
# base64 encoded
ENV_TEXT:
required: true
jobs:
docker-release:
runs-on: ubuntu-latest
environment: ${{ inputs.environment_name }}
steps:
- uses: actions/checkout@v3
with:
repository: DaemonSharps/CI-CD
- name: Install SSH key
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Adding Known Hosts
run: ssh-keyscan -H ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts
- name: Create docker context
run: docker context create vps-remote --docker "host=ssh://${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}"
- name: Use new context
run: docker context use vps-remote
- name: Docker cleanup
run: |
echo Delete unnecessary containers
docker container prune -f
echo Delete unnecessary images
docker image prune -a -f
echo Delete unnecessary networks
docker network prune -f
echo Delete unnecessary volumes
docker volume prune -f
- name: Create ${{ inputs.env_file_name }}
run: |
cd ${{ inputs.compose_folder }}
echo $ENV_TEXT | base64 -d > ${{ inputs.env_file_name }}
env:
ENV_TEXT: ${{ secrets.ENV_TEXT }}
- name: Show containers
run: |
cd ${{ inputs.compose_folder }}
docker compose -p ${{ inputs.project_name }}-${{ inputs.environment_name }} ps
- name: Context soft stop and restart
run: |
cd ${{ inputs.compose_folder }}
export ${{ inputs.image_tag_env }}
export ${{ inputs.image_port_env }}
docker compose -p ${{ inputs.project_name }}-${{ inputs.environment_name }} pull ${{ inputs.compose_service_name }}
docker compose -p ${{ inputs.project_name }}-${{ inputs.environment_name }} up -d --no-deps --force-recreate ${{ inputs.compose_service_name }}
- name: Stop if testing
if: inputs.environment_name == 'workflow_test'
run: docker compose -p ${{ inputs.project_name }}-${{ inputs.environment_name }} stop
- name: Show containers
run: |
cd ${{ inputs.compose_folder }}
docker compose -p ${{ inputs.project_name }}-${{ inputs.environment_name }} ps