Skip to content

Commit fc99cbf

Browse files
committed
Merge branch 'main' into adamancini/bjw-template
2 parents 342bf0d + 0d98776 commit fc99cbf

File tree

2 files changed

+122
-4
lines changed

2 files changed

+122
-4
lines changed

applications/wg-easy/Taskfile.yaml

Lines changed: 110 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ vars:
1515
REPLICATED_LICENSE_ID: '{{.REPLICATED_LICENSE_ID}}'
1616

1717
# Cluster configuration
18-
CLUSTER_NAME: '{{.CLUSTER_NAME | default (printf "%s-cluster" (or (env "USER") "wg-easy-dev"))}}'
18+
CLUSTER_NAME: '{{.CLUSTER_NAME | default (printf "%s-cluster" (or (env "USER") "wg-easy-dev"))}}'
1919
K8S_VERSION: '{{.K8S_VERSION | default "1.32.2"}}'
2020
DISK_SIZE: '{{.DISK_SIZE | default "100"}}'
2121
INSTANCE_TYPE: '{{.INSTANCE_TYPE | default "r1.small"}}'
@@ -39,6 +39,16 @@ vars:
3939
DEV_CONTAINER_NAME: '{{.DEV_CONTAINER_NAME | default "wg-easy-tools"}}'
4040
CONTAINER_RUNTIME: '{{.CONTAINER_RUNTIME | default "podman"}}'
4141

42+
# CMX VM configuration
43+
CMX_VM_NAME: '{{.CMX_VM_NAME | default (printf "%s-cmx-vm" (or (env "USER") "dev"))}}'
44+
CMX_VM_DISTRIBUTION: '{{.CMX_VM_DISTRIBUTION | default "ubuntu"}}'
45+
CMX_VM_VERSION: '{{.CMX_VM_VERSION | default "24.04"}}'
46+
CMX_VM_INSTANCE_TYPE: '{{.CMX_VM_INSTANCE_TYPE | default "r1.medium"}}'
47+
CMX_VM_DISK_SIZE: '{{.CMX_VM_DISK_SIZE | default "100"}}'
48+
CMX_VM_TTL: '{{.CMX_VM_TTL | default "1h"}}'
49+
CMX_VM_USER: '{{.CMX_VS_USER}}'
50+
CMX_VM_PUBLIC_KEY: '{{.CMX_VM_PUBLIC_KEY}}'
51+
4252
tasks:
4353
default:
4454
desc: Show available tasks
@@ -183,10 +193,10 @@ tasks:
183193
silent: false
184194
vars:
185195
DRY_RUN: '{{.DRY_RUN | default "false"}}'
186-
cmds:
196+
cmds:
187197
- |
188198
PREFLIGHT_FLAGS=""
189-
if [ "{{.DRY_RUN}}" = "true" ]; then
199+
if [ "{{.DRY_RUN}}" = "true" ]; then
190200
PREFLIGHT_FLAGS="--dry-run"
191201
fi
192202
@@ -453,7 +463,7 @@ tasks:
453463
OPERATION: "setup-embedded"
454464
APP_SLUG: '{{.APP_SLUG}}'
455465
RELEASE_CHANNEL: '{{.RELEASE_CHANNEL}}'
456-
AUTH_TOKEN: '{{.AUTH_TOKEN}}'
466+
AUTH_TOKEN: '{{.REPLICATED_LICENSE_ID}}'
457467
GCP_PROJECT: '{{.GCP_PROJECT}}'
458468
GCP_ZONE: '{{.GCP_ZONE}}'
459469
VM_NAME: '{{.VM_NAME}}'
@@ -535,3 +545,99 @@ tasks:
535545
- task: helm-install
536546
- task: test
537547
- task: cluster-delete
548+
549+
cmx-vm-create:
550+
desc: Create a CMX VM instance using Replicated CLI
551+
run: once
552+
silent: true
553+
status:
554+
- |
555+
# Check if VM is running
556+
replicated vm ls | grep "{{.CMX_VM_NAME}}" | grep running
557+
cmds:
558+
- |
559+
echo "Creating CMX VM {{.CMX_VM_NAME}}..."
560+
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}}
561+
562+
echo "Waiting for VM to be running (timeout: 120s)..."
563+
for i in $(seq 1 60); do
564+
replicated vm ls | grep "{{.CMX_VM_NAME}}"
565+
if replicated vm ls | grep "{{.CMX_VM_NAME}}" | grep running; then
566+
echo "VM {{.CMX_VM_NAME}} is ready!"
567+
break
568+
fi
569+
if [ $i -eq 60 ]; then
570+
echo "Timeout reached after 120s. VM may still be initializing."
571+
exit 1
572+
fi
573+
sleep 2
574+
done
575+
576+
cmx-vm-delete:
577+
desc: Delete a CMX VM instance
578+
silent: true
579+
cmds:
580+
- |
581+
echo "Deleting CMX VM {{.CMX_VM_NAME}}..."
582+
replicated vm rm {{.CMX_VM_NAME}}
583+
584+
cmx-vm-install:
585+
desc: Download and install the app as Embedded Cluster on CMX VM
586+
silent: true
587+
requires:
588+
vars: [REPLICATED_LICENSE_ID]
589+
vars:
590+
CHANNEL: '{{.CHANNEL | default "Unstable"}}'
591+
SKIP_INSTALL: '{{.SKIP_INSTALL | default "false"}}'
592+
ADMIN_CONSOLE_PASSWORD:
593+
sh: uuidgen | cut -c1-13
594+
deps:
595+
- cmx-vm-create
596+
status:
597+
- replicated vm port ls {{.CMX_VM_NAME}}
598+
- curl -sL $(replicated vm port ls {{.CMX_VM_NAME}} --output=json | jq -r ".[0].hostname")/healthz
599+
cmds:
600+
- |
601+
echo "Check if user is set..."
602+
if [ -z "{{.CMX_VM_USER}}" ]; then
603+
echo "CMX_VM_USER is not set. Set it to your Github handle. E.g. task cmx-vm-install CMX_VM_USER=nvanthao"
604+
exit 1
605+
fi
606+
607+
echo "Check if license ID is set..."
608+
if [ -z "{{.REPLICATED_LICENSE_ID}}" ]; then
609+
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"
610+
exit 1
611+
fi
612+
613+
echo "SSH into the VM and download the app binary..."
614+
SSH_BASE_CMD="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
615+
if [ -n "{{.CMX_VM_PUBLIC_KEY}}" ]; then
616+
SSH_BASE_CMD="$SSH_BASE_CMD -i {{.CMX_VM_PUBLIC_KEY}}"
617+
fi
618+
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)\"")
619+
620+
echo "SSH base command: $SSH_BASE_CMD"
621+
$VM_SSH_CMD << 'EOF'
622+
set -e
623+
echo 'Downloading {{.APP_NAME}} installer...'
624+
curl -f 'https://replicated.app/embedded/{{.APP_NAME}}/{{.CHANNEL}}' -H 'Authorization: {{.REPLICATED_LICENSE_ID}}' -o {{.APP_NAME}}-{{.CHANNEL}}.tgz
625+
626+
echo 'Extracting installer...'
627+
tar -xvzf {{.APP_NAME}}-{{.CHANNEL}}.tgz
628+
629+
if [ "{{.SKIP_INSTALL}}" = "false" ]; then
630+
echo "Installing {{.APP_NAME}}..."
631+
sudo ./{{.APP_NAME}} install --license license.yaml --admin-console-password {{.ADMIN_CONSOLE_PASSWORD}} --yes
632+
else
633+
echo "Skipping installation as requested. Binary is available at ./{{.APP_NAME}}"
634+
fi
635+
EOF
636+
637+
if [ "{{.SKIP_INSTALL}}" = "false" ]; then
638+
echo "Exposing port 30000 on the VM..."
639+
replicated vm port expose --port 30000 {{.CMX_VM_NAME}}
640+
641+
echo "Visit above URL to access the Admin Console, password: {{.ADMIN_CONSOLE_PASSWORD}}"
642+
fi
643+

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)