Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ jobs:
| `server_type` | | Name of the Server type this Server should be created with. | `cx22` (Intel x86, 2 vCPU, 4GB RAM, 40GB SSD) |
| `server_wait` | | Wait up to `server_wait` retries (10 sec each) for the Hetzner Cloud Server to start. | `30` (5 min) |
| `ssh_key` | | SSH key ID (integer) which should be injected into the Server at creation time. | `null` |
| `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` |

## Outputs

Expand All @@ -174,6 +175,8 @@ jobs:

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

### Locations

**List Locations:**

```bash
Expand All @@ -190,6 +193,8 @@ nbg1 Nuremberg DC Park 1 eu-central DE Nuremberg
sin Singapore ap-southeast SG Singapore
```

### Server Types

**List Server Types:**

```bash
Expand Down Expand Up @@ -219,6 +224,8 @@ cx42 8 shared x86 16.0 GB 160 GB
cx52 16 shared x86 32.0 GB 320 GB
```

### Images

**List x86_64 Images:**

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

**List Primary IPs:**
### Network

**List Networks:**

```bash
hcloud primary-ip list --output "columns=ID,TYPE,NAME,IP,ASSIGNEE"
hcloud network list --output "columns=ID,NAME,IP_RANGE,SERVERS"
```

**List Networks:**
**List Primary IPs:**

```bash
hcloud network list --output "columns=ID,NAME,IP_RANGE,SERVERS"
hcloud primary-ip list --output "columns=ID,TYPE,NAME,IP,ASSIGNEE"
```

### SSH

**List SSH Keys:**

```bash
hcloud ssh-key list --output "columns=ID,NAME"
```

### Volumes

**List Volumes:**

```bash
hcloud volume list --output "columns=ID,NAME,LOCATION"
```

**Create Volume:**

To create a 10GB volume named `volume-test` in the Nuremberg DC Park 1 (`nbg1`) location, use the following command:

```bash
hcloud volume create --name "volume-test" --size "10" --format "ext4" --location "nbg1"
```

## Security

> We recommend that you only use self-hosted runners with private repositories.
Expand Down
24 changes: 19 additions & 5 deletions action.sh
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,14 @@ if [[ "$MY_SSH_KEY" != "null" && ! "$MY_SSH_KEY" =~ ^[0-9]+$ ]]; then
exit_with_failure "The SSH key ID must be 'null' or an integer!"
fi

# Set the volume ID which should be attached to the instance at the creation time (default: null)
# If INPUT_VOLUME is set, use its value; otherwise, use "null".
MY_VOLUME=${INPUT_VOLUME:-"null"}
# Check if MY_VOLUME is an integer
if [[ "$MY_VOLUME" != "null" && ! "$MY_VOLUME" =~ ^[0-9]+$ ]]; then
exit_with_failure "The volume ID must be 'null' or an integer!"
fi

#
# DELETE
#
Expand Down Expand Up @@ -369,17 +377,23 @@ if [[ "$MY_PRIMARY_IPV6" != "null" ]]; then
jq ".public_net.ipv6 = $MY_PRIMARY_IPV6" < create-server-ipv6.json > create-server.json && \
echo "Primary IPv6 ID added to create-server.json."
fi
# Add network configuration to the create-server.json file if MY_NETWORK is not "null".
if [[ "$MY_NETWORK" != "null" ]]; then
cp create-server.json create-server-network.json && \
jq ".networks += [$MY_NETWORK]" < create-server-network.json > create-server.json && \
echo "Network added to create-server.json."
fi
# Add SSH key configuration to the create-server.json file if MY_SSH_KEY is not "null".
if [[ "$MY_SSH_KEY" != "null" ]]; then
cp create-server.json create-server-ssh.json && \
jq ".ssh_keys += [$MY_SSH_KEY]" < create-server-ssh.json > create-server.json && \
echo "SSH key added to create-server.json."
fi
# Add network configuration to the create-server.json file if MY_NETWORK is not "null".
if [[ "$MY_NETWORK" != "null" ]]; then
cp create-server.json create-server-network.json && \
jq ".networks += [$MY_NETWORK]" < create-server-network.json > create-server.json && \
echo "Network added to create-server.json."
# Add volume configuration to the create-server.json file if MY_VOLUME is not "null".
if [[ "$MY_VOLUME" != "null" ]]; then
cp create-server.json create-server-volume.json && \
jq ".volumes += [$MY_VOLUME]" < create-server-volume.json > create-server.json && \
echo "Volume added to create-server.json."
fi

# Send a POST request to the Hetzner Cloud API to create a server.
Expand Down
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ inputs:
SSH key ID (integer) or name which should be injected into the Server at creation time.
required: false
default: 'null'
volume:
description: >-
Volume ID (integer) which should be attached to the Server at the creation time.
required: false
default: 'null'

outputs:
label:
Expand Down Expand Up @@ -154,3 +159,4 @@ runs:
INPUT_SERVER_TYPE: ${{ inputs.server_type }}
INPUT_SERVER_WAIT: ${{ inputs.server_wait }}
INPUT_SSH_KEY: ${{ inputs.ssh_key }}
INPUT_VOLUME: ${{ inputs.volume }}
1 change: 1 addition & 0 deletions cloud-init.template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ packages:
package_update: true
package_upgrade: false
runcmd:
- udevadm trigger -c add -s block -p ID_VENDOR=HC -p ID_MODEL=Volume
- export RUNNER_ALLOW_RUNASROOT=1
- bash $MY_RUNNER_DIR/pre_runner_script.sh
- bash $MY_RUNNER_DIR/install.sh -v "$MY_RUNNER_VERSION" -d "$MY_RUNNER_DIR"
Expand Down
18 changes: 10 additions & 8 deletions create-server.template.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
{
"name": $name,
"location": $location,
"server_type": $server_type,
"start_after_create": true,
"image": $image,
"ssh_keys": [],
"volumes": [],
"networks": [],
"user_data": $cloud_init_yml,
"labels": {
"type": "github-runner",
"os-image": $image,
"gh-ver": $runner_version,
"gh-owner-id": $github_owner_id,
"gh-repo-id": $github_repo_id
},
"image": $image,
"server_type": $server_type,
"name": $name,
"networks": [],
"automount": false,
"public_net": {
"enable_ipv4": $enable_ipv4,
"enable_ipv6": $enable_ipv6,
},
"start_after_create": true,
"ssh_keys": [],
"user_data": $cloud_init_yml,
}
}