-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
134 lines (126 loc) · 3.68 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
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
name: Deploy with pipe
description: 'Deploy applications using pipe'
inputs:
host:
description: 'Remote host to deploy to'
required: true
user:
description: 'SSH user for remote host'
required: false
default: 'root'
image:
description: 'Docker image name'
required: true
dockerfile:
description: 'Path to the dockerfile'
required: false
default: 'Dockerfile'
tag:
description: 'Docker image tag'
required: false
default: 'latest'
platform:
description: 'Docker platform'
required: false
default: 'linux/amd64'
ssh_key:
description: 'SSH private key content'
required: true
sensitive: true
container_name:
description: 'Name for the container'
required: true
container_port:
description: 'Container port'
required: true
host_port:
description: 'Host port'
required: true
env_file:
description: 'Environment file'
required: false
build_args:
description: 'Build arguments (comma-separated KEY=VALUE pairs)'
required: false
rollback:
description: 'Rollback to the previous version'
required: false
network:
description: 'Docker network to connect to'
required: false
cpus:
description: 'Number of CPUs (e.g., "0.5" or "2")'
required: false
memory:
description: 'Memory limit (e.g., "512m" or "2g")'
required: false
volumes:
description: 'Volume mounts (comma-separated host:container pairs)'
required: false
runs:
using: "composite"
steps:
- name: Set up SSH key
shell: bash
run: |
mkdir -p ~/.ssh
echo "${{ inputs.ssh_key }}" > ~/.ssh/deploy_key
chmod 600 ~/.ssh/deploy_key
ssh-keyscan -H ${{ inputs.host }} >> ~/.ssh/known_hosts
- name: Download pipe
shell: bash
run: |
curl -L -o pipe "https://github.com/bjarneo/pipe/releases/latest/download/pipe-linux-amd64"
chmod +x pipe
- name: Prepare build args
id: build_args
shell: bash
run: |
BUILD_ARGS=""
if [ -n "${{ inputs.build_args }}" ]; then
IFS=',' read -ra ARGS <<< "${{ inputs.build_args }}"
for arg in "${ARGS[@]}"; do
BUILD_ARGS="$BUILD_ARGS --build-arg $arg"
done
fi
echo "args=$BUILD_ARGS" >> $GITHUB_OUTPUT
- name: Prepare volume flags
id: volume_flags
shell: bash
run: |
VOLUME_FLAGS=""
if [ -n "${{ inputs.volumes }}" ]; then
IFS=',' read -ra VOLS <<< "${{ inputs.volumes }}"
for vol in "${VOLS[@]}"; do
VOLUME_FLAGS="$VOLUME_FLAGS --volume $vol"
done
fi
echo "flags=$VOLUME_FLAGS" >> $GITHUB_OUTPUT
- name: Deploy with pipe
shell: bash
env:
HOST: ${{ inputs.host }}
HOST_USER: ${{ inputs.user }}
HOST_PLATFORM: ${{ inputs.platform }}
HOST_PORT: ${{ inputs.host_port }}
DOCKER_IMAGE_NAME: ${{ inputs.image }}
DOCKER_IMAGE_TAG: ${{ inputs.tag }}
DOCKER_CONTAINER_NAME: ${{ inputs.container_name }}
DOCKER_CONTAINER_PORT: ${{ inputs.container_port }}
DOCKER_CONTAINER_ENV_FILE: ${{ inputs.env_file }}
DOCKER_NETWORK: ${{ inputs.network }}
DOCKER_CPUS: ${{ inputs.cpus }}
DOCKER_MEMORY: ${{ inputs.memory }}
SSH_KEY_PATH: ~/.ssh/deploy_key
run: |
if [ "${{ inputs.rollback }}" = "true" ]; then
./pipe --rollback
else
./pipe ${{ steps.build_args.outputs.args }} ${{ steps.volume_flags.outputs.flags }}
fi
- name: Upload deployment logs
if: always()
uses: actions/upload-artifact@v4
with:
name: deployment-logs
path: deploy.log