Skip to content

Commit 1d46431

Browse files
authored
Volume (#16)
* start with volume * ext4 * automount false * udevadm
1 parent 5545b71 commit 1d46431

File tree

5 files changed

+67
-17
lines changed

5 files changed

+67
-17
lines changed

README.md

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ jobs:
162162
| `server_type` | | Name of the Server type this Server should be created with. | `cx22` (Intel x86, 2 vCPU, 4GB RAM, 40GB SSD) |
163163
| `server_wait` | | Wait up to `server_wait` retries (10 sec each) for the Hetzner Cloud Server to start. | `30` (5 min) |
164164
| `ssh_key` | | SSH key ID (integer) which should be injected into the Server at creation time. | `null` |
165+
| `volume` | | Specify a Volume ID (integer) to attach and mount to the Server during creation. The volume will be automatically mounted at `/mnt/HC_Volume_[VOLUME-ID]`. The volume must be in the same location as the Server. More details in [Volumes section](#Volumes). | `null` |
165166

166167
## Outputs
167168

@@ -174,6 +175,8 @@ jobs:
174175

175176
The following `hcloud` CLI commands can help you find the required input values.
176177

178+
### Locations
179+
177180
**List Locations:**
178181

179182
```bash
@@ -190,6 +193,8 @@ nbg1 Nuremberg DC Park 1 eu-central DE Nuremberg
190193
sin Singapore ap-southeast SG Singapore
191194
```
192195

196+
### Server Types
197+
193198
**List Server Types:**
194199

195200
```bash
@@ -219,6 +224,8 @@ cx42 8 shared x86 16.0 GB 160 GB
219224
cx52 16 shared x86 32.0 GB 320 GB
220225
```
221226

227+
### Images
228+
222229
**List x86_64 Images:**
223230

224231
```bash
@@ -273,24 +280,44 @@ Tip: Create custom images with HashiCorp [Packer](https://github.com/hetznerclou
273280
hcloud image list --output "columns=ID,DESCRIPTION,ARCHITECTURE,DISK_SIZE" --type "snapshot" --sort "name"
274281
```
275282

276-
**List Primary IPs:**
283+
### Network
284+
285+
**List Networks:**
277286

278287
```bash
279-
hcloud primary-ip list --output "columns=ID,TYPE,NAME,IP,ASSIGNEE"
288+
hcloud network list --output "columns=ID,NAME,IP_RANGE,SERVERS"
280289
```
281290

282-
**List Networks:**
291+
**List Primary IPs:**
283292

284293
```bash
285-
hcloud network list --output "columns=ID,NAME,IP_RANGE,SERVERS"
294+
hcloud primary-ip list --output "columns=ID,TYPE,NAME,IP,ASSIGNEE"
286295
```
287296

297+
### SSH
298+
288299
**List SSH Keys:**
289300

290301
```bash
291302
hcloud ssh-key list --output "columns=ID,NAME"
292303
```
293304

305+
### Volumes
306+
307+
**List Volumes:**
308+
309+
```bash
310+
hcloud volume list --output "columns=ID,NAME,LOCATION"
311+
```
312+
313+
**Create Volume:**
314+
315+
To create a 10GB volume named `volume-test` in the Nuremberg DC Park 1 (`nbg1`) location, use the following command:
316+
317+
```bash
318+
hcloud volume create --name "volume-test" --size "10" --format "ext4" --location "nbg1"
319+
```
320+
294321
## Security
295322

296323
> We recommend that you only use self-hosted runners with private repositories.

action.sh

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,14 @@ if [[ "$MY_SSH_KEY" != "null" && ! "$MY_SSH_KEY" =~ ^[0-9]+$ ]]; then
226226
exit_with_failure "The SSH key ID must be 'null' or an integer!"
227227
fi
228228

229+
# Set the volume ID which should be attached to the instance at the creation time (default: null)
230+
# If INPUT_VOLUME is set, use its value; otherwise, use "null".
231+
MY_VOLUME=${INPUT_VOLUME:-"null"}
232+
# Check if MY_VOLUME is an integer
233+
if [[ "$MY_VOLUME" != "null" && ! "$MY_VOLUME" =~ ^[0-9]+$ ]]; then
234+
exit_with_failure "The volume ID must be 'null' or an integer!"
235+
fi
236+
229237
#
230238
# DELETE
231239
#
@@ -369,17 +377,23 @@ if [[ "$MY_PRIMARY_IPV6" != "null" ]]; then
369377
jq ".public_net.ipv6 = $MY_PRIMARY_IPV6" < create-server-ipv6.json > create-server.json && \
370378
echo "Primary IPv6 ID added to create-server.json."
371379
fi
380+
# Add network configuration to the create-server.json file if MY_NETWORK is not "null".
381+
if [[ "$MY_NETWORK" != "null" ]]; then
382+
cp create-server.json create-server-network.json && \
383+
jq ".networks += [$MY_NETWORK]" < create-server-network.json > create-server.json && \
384+
echo "Network added to create-server.json."
385+
fi
372386
# Add SSH key configuration to the create-server.json file if MY_SSH_KEY is not "null".
373387
if [[ "$MY_SSH_KEY" != "null" ]]; then
374388
cp create-server.json create-server-ssh.json && \
375389
jq ".ssh_keys += [$MY_SSH_KEY]" < create-server-ssh.json > create-server.json && \
376390
echo "SSH key added to create-server.json."
377391
fi
378-
# Add network configuration to the create-server.json file if MY_NETWORK is not "null".
379-
if [[ "$MY_NETWORK" != "null" ]]; then
380-
cp create-server.json create-server-network.json && \
381-
jq ".networks += [$MY_NETWORK]" < create-server-network.json > create-server.json && \
382-
echo "Network added to create-server.json."
392+
# Add volume configuration to the create-server.json file if MY_VOLUME is not "null".
393+
if [[ "$MY_VOLUME" != "null" ]]; then
394+
cp create-server.json create-server-volume.json && \
395+
jq ".volumes += [$MY_VOLUME]" < create-server-volume.json > create-server.json && \
396+
echo "Volume added to create-server.json."
383397
fi
384398

385399
# Send a POST request to the Hetzner Cloud API to create a server.

action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ inputs:
112112
SSH key ID (integer) or name which should be injected into the Server at creation time.
113113
required: false
114114
default: 'null'
115+
volume:
116+
description: >-
117+
Volume ID (integer) which should be attached to the Server at the creation time.
118+
required: false
119+
default: 'null'
115120

116121
outputs:
117122
label:
@@ -154,3 +159,4 @@ runs:
154159
INPUT_SERVER_TYPE: ${{ inputs.server_type }}
155160
INPUT_SERVER_WAIT: ${{ inputs.server_wait }}
156161
INPUT_SSH_KEY: ${{ inputs.ssh_key }}
162+
INPUT_VOLUME: ${{ inputs.volume }}

cloud-init.template.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ packages:
88
package_update: true
99
package_upgrade: false
1010
runcmd:
11+
- udevadm trigger -c add -s block -p ID_VENDOR=HC -p ID_MODEL=Volume
1112
- export RUNNER_ALLOW_RUNASROOT=1
1213
- bash $MY_RUNNER_DIR/pre_runner_script.sh
1314
- bash $MY_RUNNER_DIR/install.sh -v "$MY_RUNNER_VERSION" -d "$MY_RUNNER_DIR"

create-server.template.json

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
{
2+
"name": $name,
23
"location": $location,
4+
"server_type": $server_type,
5+
"start_after_create": true,
6+
"image": $image,
7+
"ssh_keys": [],
8+
"volumes": [],
9+
"networks": [],
10+
"user_data": $cloud_init_yml,
311
"labels": {
412
"type": "github-runner",
513
"os-image": $image,
614
"gh-ver": $runner_version,
715
"gh-owner-id": $github_owner_id,
816
"gh-repo-id": $github_repo_id
917
},
10-
"image": $image,
11-
"server_type": $server_type,
12-
"name": $name,
13-
"networks": [],
18+
"automount": false,
1419
"public_net": {
1520
"enable_ipv4": $enable_ipv4,
1621
"enable_ipv6": $enable_ipv6,
17-
},
18-
"start_after_create": true,
19-
"ssh_keys": [],
20-
"user_data": $cloud_init_yml,
22+
}
2123
}

0 commit comments

Comments
 (0)