-
Notifications
You must be signed in to change notification settings - Fork 0
220 lines (204 loc) · 9.18 KB
/
deploy-cloudways.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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
name: Cloudways
on:
workflow_call:
inputs:
host_ip:
description: 'IP Address of the host server'
required: true
type: string
site_url:
description: 'The site url we are deploying to (full url)'
required: true
type: string
environment:
description: 'The environment we are deploying to (production, staging)'
required: false
default: 'staging'
type: string
branch:
description: 'The branch we are deploying to'
required: false
default: 'staging'
type: string
deployment:
description: 'The deployment ID from previous jobs'
required: true
type: string
deployment_path:
description: 'Provide if the deployment path is non standard'
required: false
default: '~/private_html/releases'
type: string
workflow_run_id:
description: 'Workflow Run ID to get artifacts from'
required: true
type: string
remote_plugin_install:
description: 'Use the wp cli to remote install plugins instead of using composer'
type: boolean
default: false
deployment_auth_type:
description: 'Define the type of authentication being used for the environment'
type: string
required: false
default: 'key'
secrets:
deployment_ssh_user:
description: 'Cloudways SSH User needed for deployment'
required: true
deployment_ssh_key:
description: 'Cloudways SSH Key needed for deployment'
required: false
deployment_ssh_pass:
description: 'Cloudways Autonomous only support SSH passwords'
required: false
gh_bot_token:
description: 'Bot Access to Private repo'
required: true
jobs:
deploy:
name: To Cloudways
runs-on: ubuntu-latest
environment:
name: ${{ inputs.environment }}
url: ${{ inputs.site_url }}
steps:
- name: Deployment In Progress
id: in_progress_deployment
uses: octokit/[email protected]
with:
route: POST /repos/{repo}/deployments/{deployment}/statuses
repo: ${{ github.repository }}
deployment: ${{ inputs.deployment }}
environment: ${{ inputs.environment }}
environment_url: ${{ inputs.site_url }}
log_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
state: in_progress
mediaType: '{"previews": ["flash", "ant-man"]}'
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
- name: Download All Artifacts
uses: actions/[email protected]
id: download
with:
name: 'release'
path: ./
- name: Generate release zip
id: folder
run: |
echo "folder=$(date +'%s')" >> $GITHUB_OUTPUT
- name: Configure SSH Connection with Cloudways
if: ${{ inputs.deployment_auth_type == 'key' }}
run: |
SSH_PATH="$HOME/.ssh"
KNOWN_HOSTS_PATH="$SSH_PATH/known_hosts"
SSH_KEY_PRIVATE_PATH="$SSH_PATH/github_action"
mkdir "$SSH_PATH"
ssh-keyscan -t rsa "$SSH_HOST" >> "$KNOWN_HOSTS_PATH"
#Copy Secret Keys to container
echo "$SSH_KEY" > "$SSH_KEY_PRIVATE_PATH"
chmod 700 "$SSH_PATH"
chmod 644 "$KNOWN_HOSTS_PATH"
chmod 600 "$SSH_KEY_PRIVATE_PATH"
cat >>~/.ssh/config <<END
Host cloudways
HostName $SSH_HOST
User $SSH_USER
IdentityFile $SSH_KEY_PRIVATE_PATH
StrictHostKeyChecking no
END
env:
SSH_USER: ${{ secrets.deployment_ssh_user }}
SSH_KEY: ${{ secrets.deployment_ssh_key }}
SSH_HOST: ${{ inputs.host_ip }}
- name: Configure SSH Connection with Cloudways
if: ${{ inputs.deployment_auth_type == 'pass' }}
run: |
SSH_PATH="$HOME/.ssh"
KNOWN_HOSTS_PATH="$SSH_PATH/known_hosts"
mkdir -p "$SSH_PATH"
ssh-keyscan -t rsa "$SSH_HOST" >> "$KNOWN_HOSTS_PATH"
chmod 700 "$SSH_PATH"
chmod 644 "$KNOWN_HOSTS_PATH"
cat >>~/.ssh/config <<END
Host cloudways
HostName $SSH_HOST
User $SSH_USER
StrictHostKeyChecking no
END
env:
SSH_USER: ${{ secrets.deployment_ssh_user }}
SSH_HOST: ${{ inputs.host_ip }}
- name: Upload Assets
if: ${{ inputs.deployment_auth_type == 'key' }}
id: upload_assets
run: |
SSH_PATH="$HOME/.ssh"
KNOWN_HOSTS_PATH="$SSH_PATH/known_hosts"
SSH_KEY_PRIVATE_PATH="$SSH_PATH/github_action"
mv ./release.zip ./${{ steps.folder.outputs.folder }}.zip
ssh cloudways "mkdir -p ${{ inputs.deployment_path }}"
rsync --rsh="ssh -v -p 22 -i $SSH_KEY_PRIVATE_PATH -o StrictHostKeyChecking=no" -zrxc --delete "${{ steps.folder.outputs.folder }}.zip" "${{ secrets.deployment_ssh_user }}@${{ inputs.host_ip }}:${{ inputs.deployment_path }}"
- name: Upload Assets with Password
if: ${{ inputs.deployment_auth_type == 'pass' }}
run: |
SSH_PATH="$HOME/.ssh"
KNOWN_HOSTS_PATH="$SSH_PATH/known_hosts"
mv ./release.zip ./${{ steps.folder.outputs.folder }}.zip
ssh-keyscan -H ${{ inputs.host_ip }} >> "$KNOWN_HOSTS_PATH"
chmod 700 "$SSH_PATH"
chmod 644 "$KNOWN_HOSTS_PATH"
sshpass -p "${{ secrets.deployment_ssh_pass }}" ssh -o StrictHostKeyChecking=no ${{ secrets.deployment_ssh_user }}@${{ inputs.host_ip }} "mkdir -p ${{ inputs.deployment_path }}"
sshpass -p "${{ secrets.deployment_ssh_pass }}" rsync --rsh="ssh -o StrictHostKeyChecking=no" -zrxc --delete --no-perms --no-times "${{ steps.folder.outputs.folder }}.zip" "${{ secrets.deployment_ssh_user }}@${{ inputs.host_ip }}:${{ inputs.deployment_path }}"
env:
SSH_USER: ${{ secrets.deployment_ssh_user }}
SSH_HOST: ${{ inputs.host_ip }}
SSH_PASSWORD: ${{ secrets.deployment_ssh_pass }}
- name: Remote - Run Scripts
if: ${{ inputs.deployment_auth_type == 'key' }}
id: execute_bash
run: |
ssh cloudways "rm -rf ${{ inputs.deployment_path }}/release"
ssh cloudways "unzip -o -q ${{ inputs.deployment_path }}/${{ steps.folder.outputs.folder }}.zip -d ${{ inputs.deployment_path }}"
ssh cloudways "mkdir -p ${{ inputs.deployment_path }}/release/.deployment"
ssh cloudways "cd ${{ inputs.deployment_path }}/release/.deployment && wget -O entrypoint.sh https://raw.githubusercontent.com/linchpin/actions/v2/.deployment/cloudways-entrypoint.sh && chmod +x ./entrypoint.sh && bash ./entrypoint.sh"
- name: Remote - Run Scripts with Password
if: ${{ inputs.deployment_auth_type == 'pass' }}
id: execute_bash_pass
run: |
sshpass -p "${{ secrets.deployment_ssh_pass }}" ssh ${{ secrets.deployment_ssh_user }}@${{ inputs.host_ip }} "rm -rf ${{ inputs.deployment_path }}/release"
sshpass -p "${{ secrets.deployment_ssh_pass }}" ssh ${{ secrets.deployment_ssh_user }}@${{ inputs.host_ip }} "unzip -o -q ${{ inputs.deployment_path }}/${{ steps.folder.outputs.folder }}.zip -d ${{ inputs.deployment_path }}"
sshpass -p "${{ secrets.deployment_ssh_pass }}" ssh ${{ secrets.deployment_ssh_user }}@${{ inputs.host_ip }} "mkdir -p ${{ inputs.deployment_path }}/release/.deployment"
sshpass -p "${{ secrets.deployment_ssh_pass }}" ssh ${{ secrets.deployment_ssh_user }}@${{ inputs.host_ip }} "cd ${{ inputs.deployment_path }}/release/.deployment && wget -O entrypoint.sh https://raw.githubusercontent.com/linchpin/actions/v2/.deployment/cloudways-entrypoint.sh && chmod +x ./entrypoint.sh && bash ./entrypoint.sh"
env:
SSH_USER: ${{ secrets.deployment_ssh_user }}
SSH_HOST: ${{ inputs.host_ip }}
SSH_PASSWORD: ${{ secrets.deployment_ssh_pass }}
- name: Set Deployment Status as Successful
if: ${{ success() }}
uses: octokit/[email protected]
with:
route: POST /repos/{repo}/deployments/{deployment}/statuses
repo: ${{ github.repository }}
deployment: ${{ inputs.deployment }}
environment: ${{ inputs.environment }}
environment_url: ${{ inputs.site_url }}
log_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
state: success
mediaType: '{"previews": ["flash", "ant-man"]}'
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
- name: Set Deployment Status as Failboat
if: ${{ failure() }}
uses: octokit/[email protected]
with:
route: POST /repos/{repo}/deployments/{deployment}/statuses
repo: ${{ github.repository }}
deployment: ${{ inputs.deployment }}
environment: ${{ inputs.environment }}
environment_url: ${{ inputs.site_url }}
log_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
state: failure
mediaType: '{"previews": ["flash", "ant-man"]}'
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"