-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
87 lines (77 loc) · 3 KB
/
action.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
name: "Deploy"
description: "Deploy using Docker and docker-compose"
inputs:
docker-image-name:
description: "Docker Image Name"
required: true
docker-compose-file:
description: "Docker Compose File"
required: true
docker-env-vars:
description: "Docker Environment Variables"
required: true
ssh-host:
description: "SSH Host"
required: true
ssh-user:
description: "SSH User"
required: true
ssh-private-key:
description: "SSH Private Key"
required: true
working-directory:
description: "Optional working directory"
required: false
default: ./
runs:
using: "composite"
steps:
- id: create-local-ssh-folder
run: mkdir -p ~/.ssh
shell: bash
working-directory: ${{ inputs.working-directory }}
- id: prepare-ssh-key
run: |
echo "${{ inputs.ssh-private-key }}" | sed '/^$/d' > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
shell: bash
working-directory: ${{ inputs.working-directory }}
- id: add-known-host
run: ssh-keyscan -H ${{ inputs.ssh-host }} > ~/.ssh/known_hosts
shell: bash
working-directory: ${{ inputs.working-directory }}
- id: create-remote-folder
run: ssh ${{ inputs.ssh-user }}@${{ inputs.ssh-host }} mkdir -p /tmp/deploy-action/${{ inputs.docker-image-name }}
shell: bash
working-directory: ${{ inputs.working-directory }}
- id: scp-docker-compose-file
run: "scp ${{ inputs.docker-compose-file }} ${{ inputs.ssh-user }}@${{ inputs.ssh-host }}:/tmp/deploy-action/${{ inputs.docker-image-name }}/docker-compose.yml"
shell: bash
working-directory: ${{ inputs.working-directory }}
- id: create-docker-env-file
run: |
ssh ${{ inputs.ssh-user }}@${{ inputs.ssh-host }} "cat <<EOF > /tmp/deploy-action/${{ inputs.docker-image-name }}/env.prod
${{ inputs.docker-env-vars }}
EOF"
shell: bash
working-directory: ${{ inputs.working-directory }}
- id: docker-pull-latest
run: ssh ${{ inputs.ssh-user }}@${{ inputs.ssh-host }} docker pull ghcr.io/${{ github.repository }}/${{ inputs.docker-image-name }}:latest
shell: bash
working-directory: ${{ inputs.working-directory }}
- id: docker-compose-up
run: ssh ${{ inputs.ssh-user }}@${{ inputs.ssh-host }} "cd /tmp/deploy-action/${{ inputs.docker-image-name }} && IMAGE_TAG=latest docker-compose -f docker-compose.yml up -d"
shell: bash
working-directory: ${{ inputs.working-directory }}
- id: remove-remote-folder
run: ssh ${{ inputs.ssh-user }}@${{ inputs.ssh-host }} rm -rf /tmp/deploy-action/${{ inputs.docker-image-name }}
shell: bash
working-directory: ${{ inputs.working-directory }}
- id: docker-system-prune
run: ssh ${{ inputs.ssh-user }}@${{ inputs.ssh-host }} docker system prune -f
shell: bash
working-directory: ${{ inputs.working-directory }}
- id: remove-ssh-folder
run: rm -rf ~/.ssh
shell: bash
working-directory: ${{ inputs.working-directory }}