Skip to content

Commit 0d98776

Browse files
authored
feat: add wg-easy installation on CMX VM (#65)
* wip * add status * update from code review * update from code review * update embedded-cluster-setup task to use license ID * silent CMX tasks
1 parent 7533222 commit 0d98776

File tree

2 files changed

+119
-2
lines changed

2 files changed

+119
-2
lines changed

applications/wg-easy/Taskfile.yaml

Lines changed: 107 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ vars:
4242
DEV_CONTAINER_NAME: '{{.DEV_CONTAINER_NAME | default "wg-easy-tools"}}'
4343
CONTAINER_RUNTIME: '{{.CONTAINER_RUNTIME | default "podman"}}'
4444

45+
# CMX VM configuration
46+
CMX_VM_NAME: '{{.CMX_VM_NAME | default (printf "%s-cmx-vm" (or (env "USER") "dev"))}}'
47+
CMX_VM_DISTRIBUTION: '{{.CMX_VM_DISTRIBUTION | default "ubuntu"}}'
48+
CMX_VM_VERSION: '{{.CMX_VM_VERSION | default "24.04"}}'
49+
CMX_VM_INSTANCE_TYPE: '{{.CMX_VM_INSTANCE_TYPE | default "r1.medium"}}'
50+
CMX_VM_DISK_SIZE: '{{.CMX_VM_DISK_SIZE | default "100"}}'
51+
CMX_VM_TTL: '{{.CMX_VM_TTL | default "1h"}}'
52+
CMX_VM_USER: '{{.CMX_VS_USER}}'
53+
CMX_VM_PUBLIC_KEY: '{{.CMX_VM_PUBLIC_KEY}}'
54+
4555
tasks:
4656
default:
4757
desc: Show available tasks
@@ -424,7 +434,6 @@ tasks:
424434
silent: false
425435
vars:
426436
CHANNEL: '{{.CHANNEL | default "Unstable"}}'
427-
AUTH_TOKEN: '{{.AUTH_TOKEN | default "2usDXzovcJNcpn54yS5tFQVNvCq"}}'
428437
deps:
429438
- gcp-vm-create
430439
status:
@@ -437,7 +446,7 @@ tasks:
437446
OPERATION: "setup-embedded"
438447
APP_SLUG: '{{.APP_SLUG}}'
439448
CHANNEL: '{{.CHANNEL}}'
440-
AUTH_TOKEN: '{{.AUTH_TOKEN}}'
449+
AUTH_TOKEN: '{{.REPLICATED_LICENSE_ID}}'
441450
GCP_PROJECT: '{{.GCP_PROJECT}}'
442451
GCP_ZONE: '{{.GCP_ZONE}}'
443452
VM_NAME: '{{.VM_NAME}}'
@@ -519,3 +528,99 @@ tasks:
519528
- task: helm-install
520529
- task: test
521530
- task: cluster-delete
531+
532+
cmx-vm-create:
533+
desc: Create a CMX VM instance using Replicated CLI
534+
run: once
535+
silent: true
536+
status:
537+
- |
538+
# Check if VM is running
539+
replicated vm ls | grep "{{.CMX_VM_NAME}}" | grep running
540+
cmds:
541+
- |
542+
echo "Creating CMX VM {{.CMX_VM_NAME}}..."
543+
replicated vm create --distribution {{.CMX_VM_DISTRIBUTION}} --version {{.CMX_VM_VERSION}} --instance-type {{.CMX_VM_INSTANCE_TYPE}} --disk {{.CMX_VM_DISK_SIZE}} --name {{.CMX_VM_NAME}} --ttl {{.CMX_VM_TTL}}
544+
545+
echo "Waiting for VM to be running (timeout: 120s)..."
546+
for i in $(seq 1 60); do
547+
replicated vm ls | grep "{{.CMX_VM_NAME}}"
548+
if replicated vm ls | grep "{{.CMX_VM_NAME}}" | grep running; then
549+
echo "VM {{.CMX_VM_NAME}} is ready!"
550+
break
551+
fi
552+
if [ $i -eq 60 ]; then
553+
echo "Timeout reached after 120s. VM may still be initializing."
554+
exit 1
555+
fi
556+
sleep 2
557+
done
558+
559+
cmx-vm-delete:
560+
desc: Delete a CMX VM instance
561+
silent: true
562+
cmds:
563+
- |
564+
echo "Deleting CMX VM {{.CMX_VM_NAME}}..."
565+
replicated vm rm {{.CMX_VM_NAME}}
566+
567+
cmx-vm-install:
568+
desc: Download and install the app as Embedded Cluster on CMX VM
569+
silent: true
570+
requires:
571+
vars: [REPLICATED_LICENSE_ID]
572+
vars:
573+
CHANNEL: '{{.CHANNEL | default "Unstable"}}'
574+
SKIP_INSTALL: '{{.SKIP_INSTALL | default "false"}}'
575+
ADMIN_CONSOLE_PASSWORD:
576+
sh: uuidgen | cut -c1-13
577+
deps:
578+
- cmx-vm-create
579+
status:
580+
- replicated vm port ls {{.CMX_VM_NAME}}
581+
- curl -sL $(replicated vm port ls {{.CMX_VM_NAME}} --output=json | jq -r ".[0].hostname")/healthz
582+
cmds:
583+
- |
584+
echo "Check if user is set..."
585+
if [ -z "{{.CMX_VM_USER}}" ]; then
586+
echo "CMX_VM_USER is not set. Set it to your Github handle. E.g. task cmx-vm-install CMX_VM_USER=nvanthao"
587+
exit 1
588+
fi
589+
590+
echo "Check if license ID is set..."
591+
if [ -z "{{.REPLICATED_LICENSE_ID}}" ]; then
592+
echo "REPLICATED_LICENSE_ID is not set. Set it to your DEV Customer License ID. E.g. task cmx-vm-install REPLICATED_LICENSE_ID=1234567890"
593+
exit 1
594+
fi
595+
596+
echo "SSH into the VM and download the app binary..."
597+
SSH_BASE_CMD="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
598+
if [ -n "{{.CMX_VM_PUBLIC_KEY}}" ]; then
599+
SSH_BASE_CMD="$SSH_BASE_CMD -i {{.CMX_VM_PUBLIC_KEY}}"
600+
fi
601+
VM_SSH_CMD=$(replicated vm ls --output=json | jq -r ".[] | select(.name == \"{{.CMX_VM_NAME}}\") | \"$SSH_BASE_CMD -p \(.direct_ssh_port) {{.CMX_VM_USER}}@\(.direct_ssh_endpoint)\"")
602+
603+
echo "SSH base command: $SSH_BASE_CMD"
604+
$VM_SSH_CMD << 'EOF'
605+
set -e
606+
echo 'Downloading {{.APP_NAME}} installer...'
607+
curl -f 'https://replicated.app/embedded/{{.APP_NAME}}/{{.CHANNEL}}' -H 'Authorization: {{.REPLICATED_LICENSE_ID}}' -o {{.APP_NAME}}-{{.CHANNEL}}.tgz
608+
609+
echo 'Extracting installer...'
610+
tar -xvzf {{.APP_NAME}}-{{.CHANNEL}}.tgz
611+
612+
if [ "{{.SKIP_INSTALL}}" = "false" ]; then
613+
echo "Installing {{.APP_NAME}}..."
614+
sudo ./{{.APP_NAME}} install --license license.yaml --admin-console-password {{.ADMIN_CONSOLE_PASSWORD}} --yes
615+
else
616+
echo "Skipping installation as requested. Binary is available at ./{{.APP_NAME}}"
617+
fi
618+
EOF
619+
620+
if [ "{{.SKIP_INSTALL}}" = "false" ]; then
621+
echo "Exposing port 30000 on the VM..."
622+
replicated vm port expose --port 30000 {{.CMX_VM_NAME}}
623+
624+
echo "Visit above URL to access the Admin Console, password: {{.ADMIN_CONSOLE_PASSWORD}}"
625+
fi
626+

applications/wg-easy/docs/task-reference.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ These tasks help manage the development and testing environments.
4545
| `gcp-vm-create` | Creates a GCP VM instance for embedded cluster testing | Stage 7: Embedded Testing |
4646
| `gcp-vm-delete` | Deletes the GCP VM instance after testing | Stage 7: Cleanup |
4747
| `embedded-cluster-setup` | Sets up a Replicated embedded cluster on the GCP VM | Stage 7: Embedded Testing |
48+
| `cmx-vm-create` | Creates a CMX VM instance using Replicated CLI | Stage 7: Embedded Testing |
49+
| `cmx-vm-delete` | Deletes a CMX VM instance | Stage 7: Cleanup |
50+
| `cmx-vm-install` | Downloads and optionally installs the app as Embedded Cluster on CMX VM | Stage 7: Embedded Testing |
4851

4952
### Common Environment Combinations
5053

@@ -115,6 +118,15 @@ Many tasks accept parameters to customize their behavior. Here are the most comm
115118
| `RELEASE_NOTES` | `release-create` | Notes for the release | "" |
116119
| `GCP_PROJECT` | `gcp-vm-create` | GCP project ID | Required |
117120
| `GCP_ZONE` | `gcp-vm-create` | GCP zone | "us-central1-a" |
121+
| `CMX_VM_NAME` | `cmx-vm-create`, `cmx-vm-delete`, `cmx-vm-install` | Name for the CMX VM | "{{USER}}-cmx-vm" |
122+
| `CMX_VM_DISTRIBUTION` | `cmx-vm-create` | VM distribution | "ubuntu" |
123+
| `CMX_VM_VERSION` | `cmx-vm-create` | VM version | "24.04" |
124+
| `CMX_VM_INSTANCE_TYPE` | `cmx-vm-create` | VM instance type | "r1.medium" |
125+
| `CMX_VM_DISK_SIZE` | `cmx-vm-create` | VM disk size in GB | "100" |
126+
| `CMX_VM_TTL` | `cmx-vm-create` | VM time-to-live | "1h" |
127+
| `CMX_VM_USER` | `cmx-vm-install` | VM user for SSH access | Required |
128+
| `CMX_VM_PUBLIC_KEY` | `cmx-vm-install` | Path to SSH public key | "" |
129+
| `SKIP_INSTALL` | `cmx-vm-install` | Skip the installation step, only download binary | "false" |
118130

119131
Parameters in the Taskfile.yaml try to always have defaults so that it works out of the box but allows customization for common values.
120132

0 commit comments

Comments
 (0)