-
-
Notifications
You must be signed in to change notification settings - Fork 16
110 lines (98 loc) · 4.04 KB
/
deploy-to-environment.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
name: Deploy the current version of Crypter to a specific environment
on:
workflow_dispatch:
inputs:
environment:
description: 'Define the environment name'
required: true
type: choice
options:
- production
- staging
env:
docker_compose_profile: ${{ (github.event.inputs.environment == 'staging' && 'local') || 'web' }}
jobs:
deploy-web-container:
runs-on: ubuntu-latest
environment:
name: ${{ github.event.inputs.environment }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Stop service
uses: appleboy/[email protected]
with:
host: ${{ secrets.APPSERVER_SSH_HOST }}
port: ${{ secrets.APPSERVER_SSH_PORT }}
username: ${{ secrets.APPSERVER_SSH_USER }}
key: ${{ secrets.APPSERVER_SSH_PRIVATE_KEY }}
script: |
if [ "$(systemctl --user is-active crypter.service)" = "active" ]; then
echo "Stopping service"
systemctl --user stop crypter.service;
fi
script_stop: true
- name: Push latest systemctl service file
uses: appleboy/[email protected]
with:
host: ${{ secrets.APPSERVER_SSH_HOST }}
port: ${{ secrets.APPSERVER_SSH_PORT }}
username: ${{ secrets.APPSERVER_SSH_USER }}
key: ${{ secrets.APPSERVER_SSH_PRIVATE_KEY }}
source: Environments/${{ github.event.inputs.environment }}/crypter.service
target: .config/systemd/user/
strip_components: 2
- name: Reload systemctl daemon
uses: appleboy/[email protected]
with:
host: ${{ secrets.APPSERVER_SSH_HOST }}
port: ${{ secrets.APPSERVER_SSH_PORT }}
username: ${{ secrets.APPSERVER_SSH_USER }}
key: ${{ secrets.APPSERVER_SSH_PRIVATE_KEY }}
script: systemctl --user daemon-reload
- name: Push latest Docker Compose file
uses: appleboy/[email protected]
with:
host: ${{ secrets.APPSERVER_SSH_HOST }}
port: ${{ secrets.APPSERVER_SSH_PORT }}
username: ${{ secrets.APPSERVER_SSH_USER }}
key: ${{ secrets.APPSERVER_SSH_PRIVATE_KEY }}
source: docker-compose.yml
target: crypter-web-container/
- name: Push latest Docker Compose override file if deploying to Staging server
if: github.event.inputs.environment == 'staging'
uses: appleboy/[email protected]
with:
host: ${{ secrets.APPSERVER_SSH_HOST }}
port: ${{ secrets.APPSERVER_SSH_PORT }}
username: ${{ secrets.APPSERVER_SSH_USER }}
key: ${{ secrets.APPSERVER_SSH_PRIVATE_KEY }}
source: docker-compose.override.yml
target: crypter-web-container/
- name: Pull latest images
uses: appleboy/[email protected]
with:
host: ${{ secrets.APPSERVER_SSH_HOST }}
port: ${{ secrets.APPSERVER_SSH_PORT }}
username: ${{ secrets.APPSERVER_SSH_USER }}
key: ${{ secrets.APPSERVER_SSH_PRIVATE_KEY }}
script: docker compose --project-directory crypter-web-container --profile ${{ env.docker_compose_profile }} pull
script_stop: true
- name: Migrate database
uses: appleboy/[email protected]
with:
host: ${{ secrets.APPSERVER_SSH_HOST }}
port: ${{ secrets.APPSERVER_SSH_PORT }}
username: ${{ secrets.APPSERVER_SSH_USER }}
key: ${{ secrets.APPSERVER_SSH_PRIVATE_KEY }}
script: docker compose --project-directory crypter-web-container --profile ${{ env.docker_compose_profile }} run api /app/efbundle
script_stop: true
- name: Start service
uses: appleboy/[email protected]
with:
host: ${{ secrets.APPSERVER_SSH_HOST }}
port: ${{ secrets.APPSERVER_SSH_PORT }}
username: ${{ secrets.APPSERVER_SSH_USER }}
key: ${{ secrets.APPSERVER_SSH_PRIVATE_KEY }}
script: systemctl --user start crypter.service
script_stop: true