Skip to content

Commit f81030e

Browse files
committed
wip
1 parent 7533222 commit f81030e

File tree

2 files changed

+104
-0
lines changed

2 files changed

+104
-0
lines changed

applications/wg-easy/Taskfile.yaml

Lines changed: 93 additions & 0 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 | default (env "HOME" | printf "%s/.ssh/id_ed25519")}}'
54+
4555
tasks:
4656
default:
4757
desc: Show available tasks
@@ -519,3 +529,86 @@ tasks:
519529
- task: helm-install
520530
- task: test
521531
- task: cluster-delete
532+
533+
cmx-vm-create:
534+
desc: Create a CMX VM instance using Replicated CLI
535+
run: once
536+
silent: false
537+
status:
538+
- |
539+
# Check if VM is running
540+
replicated vm ls | grep "{{.CMX_VM_NAME}}" | grep running
541+
cmds:
542+
- |
543+
echo "Creating CMX VM {{.CMX_VM_NAME}}..."
544+
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}}
545+
546+
echo "Waiting for VM to be running (timeout: 120s)..."
547+
for i in $(seq 1 60); do
548+
replicated vm ls | grep "{{.CMX_VM_NAME}}"
549+
if replicated vm ls | grep "{{.CMX_VM_NAME}}" | grep running; then
550+
echo "VM {{.CMX_VM_NAME}} is ready!"
551+
break
552+
fi
553+
if [ $i -eq 60 ]; then
554+
echo "Timeout reached after 120s. VM may still be initializing."
555+
exit 1
556+
fi
557+
sleep 2
558+
done
559+
560+
cmx-vm-delete:
561+
desc: Delete a CMX VM instance
562+
silent: false
563+
cmds:
564+
- |
565+
echo "Deleting CMX VM {{.CMX_VM_NAME}}..."
566+
replicated vm rm {{.CMX_VM_NAME}}
567+
568+
cmx-vm-embedded-cluster-setup:
569+
desc: Download and install the app as Embedded Cluster on CMX VM
570+
silent: false
571+
vars:
572+
CHANNEL: '{{.CHANNEL | default "Unstable"}}'
573+
AUTH_TOKEN: '{{.AUTH_TOKEN | default "2usDXzovcJNcpn54yS5tFQVNvCq"}}'
574+
ADMIN_CONSOLE_PASSWORD:
575+
sh: uuidgen | cut -c1-13
576+
deps:
577+
- cmx-vm-create
578+
cmds:
579+
- |
580+
echo "Check if user is set..."
581+
if [ -z "{{.CMX_VM_USER}}" ]; then
582+
echo "CMX_VM_USER is not set. Set it to your Github handle. E.g. task cmx-vm-embedded-cluster-setup CMX_VM_USER=nvanthao"
583+
exit 1
584+
fi
585+
586+
echo "Check if public key exists..."
587+
if [ ! -f "{{.CMX_VM_PUBLIC_KEY}}" ]; then
588+
echo "{{.CMX_VM_PUBLIC_KEY}} does not exist."
589+
exit 1
590+
fi
591+
592+
echo "SSH into the VM and download the app binary..."
593+
SSH_BASE_CMD="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i {{.CMX_VM_PUBLIC_KEY}}"
594+
VM_SSH_CMD=$(replicated vm ls --output=json | jq -r ".[] | select(.name == \"{{.CMX_VM_NAME}}\") | \"$SSH_BASE_CMD -p \(.direct_ssh_port) nvanthao@\(.direct_ssh_endpoint)\"")
595+
596+
echo "SSH command: $VM_SSH_CMD"
597+
$VM_SSH_CMD << 'EOF'
598+
set -e
599+
echo 'Downloading {{.APP_NAME}} installer...'
600+
curl -f 'https://replicated.app/embedded/{{.APP_NAME}}/{{.CHANNEL}}' -H 'Authorization: {{.AUTH_TOKEN}}' -o {{.APP_NAME}}-{{.CHANNEL}}.tgz
601+
602+
echo 'Extracting installer...'
603+
tar -xvzf {{.APP_NAME}}-{{.CHANNEL}}.tgz
604+
605+
echo "Installing {{.APP_NAME}}..."
606+
sudo ./{{.APP_NAME}} install --license license.yaml --admin-console-password {{.ADMIN_CONSOLE_PASSWORD}} --yes
607+
608+
EOF
609+
610+
echo "Exposing port 30000 on the VM..."
611+
replicated vm port expose --port 30000 {{.CMX_VM_NAME}}
612+
613+
echo "Visit above URL to access the Admin Console, password: {{.ADMIN_CONSOLE_PASSWORD}}"
614+

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

Lines changed: 11 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-embedded-cluster-setup` | Sets up a Replicated embedded cluster on the CMX VM | Stage 7: Embedded Testing |
4851

4952
### Common Environment Combinations
5053

@@ -115,6 +118,14 @@ 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-embedded-cluster-setup` | 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-embedded-cluster-setup` | VM user for SSH access | Required |
128+
| `CMX_VM_PUBLIC_KEY` | `cmx-vm-embedded-cluster-setup` | Path to SSH public key | "~/.ssh/id_ed25519" |
118129

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

0 commit comments

Comments
 (0)