forked from CuteHorse/DeployApplicationToHostAction
-
Notifications
You must be signed in to change notification settings - Fork 0
71 lines (65 loc) · 1.89 KB
/
Copy pathDeployApplicationToHost.yml
File metadata and controls
71 lines (65 loc) · 1.89 KB
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
name: Deploy application to host
on:
workflow_call:
inputs:
host:
required: true
type: string
port:
required: true
type: string
user:
required: true
type: string
app-dir:
required: true
type: string
tmp-dir:
required: true
type: string
pre-copy:
required: true
type: string
post-copy:
required: true
type: string
secrets:
private-key:
required: true
jobs:
create-snapshot:
runs-on: ubuntu-latest
steps:
- name: Configure SSH
run: |
mkdir -p ~/.ssh/
echo "${{secrets.private-key}}" > ~/.ssh/targetServer.key
chmod 600 ~/.ssh/targetServer.key
cat >>~/.ssh/config <<END
Host targetServer
HostName ${{inputs.host}}
Port ${{inputs.port}}
User ${{inputs.user}}
IdentityFile ~/.ssh/targetServer.key
StrictHostKeyChecking no
END
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: build
- name: Pack files
run: >
tar --ignore-failed-read --exclude=./publish.tgz -czvf publish.tgz .
- name: Copy files to target
run: |
ssh targetServer 'mkdir -p ${{inputs.tmp-dir}}/unpacked/ && mkdir -p ${{inputs.app-dir}}'
scp -r publish.tgz targetServer:${{inputs.tmp-dir}}
- name: Unpack files and restart service
run: >
ssh targetServer '\
cd ${{inputs.tmp-dir}} && \
${{inputs.pre-copy}} && \
tar -xvf publish.tgz -C "${{inputs.tmp-dir}}/unpacked/" && \
rsync -a "${{inputs.tmp-dir}}/unpacked/" ${{inputs.app-dir}} && \
rm -r publish.tgz "${{inputs.tmp-dir}}/unpacked/" && \
${{inputs.post-copy}}'