diff --git a/README.md b/README.md index 529eaed..aeafe94 100644 --- a/README.md +++ b/README.md @@ -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 @@ -174,6 +175,8 @@ jobs: The following `hcloud` CLI commands can help you find the required input values. +### Locations + **List Locations:** ```bash @@ -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 @@ -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 @@ -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. diff --git a/action.sh b/action.sh index 7832297..735dc96 100644 --- a/action.sh +++ b/action.sh @@ -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 # @@ -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. diff --git a/action.yml b/action.yml index 5575849..36a364e 100644 --- a/action.yml +++ b/action.yml @@ -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: @@ -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 }} diff --git a/cloud-init.template.yml b/cloud-init.template.yml index 13ec383..01d0971 100644 --- a/cloud-init.template.yml +++ b/cloud-init.template.yml @@ -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" diff --git a/create-server.template.json b/create-server.template.json index 40646fb..452b822 100644 --- a/create-server.template.json +++ b/create-server.template.json @@ -1,5 +1,13 @@ { + "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, @@ -7,15 +15,9 @@ "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, + } }