feat: add script to copy .env file to k3s-vm-1 after pre-flight checks
This commit is contained in:
parent
bb4d0cc701
commit
b4c0f17b12
2 changed files with 40 additions and 0 deletions
|
|
@ -34,5 +34,14 @@
|
|||
],
|
||||
"retryCount": 0,
|
||||
"shouldAbort": true
|
||||
},
|
||||
{
|
||||
"name": "copy .env to k3s-vm-1",
|
||||
"function": "RunCommand",
|
||||
"params": [
|
||||
"gcloud/tf/scripts/copy_env_to_first_node.sh"
|
||||
],
|
||||
"retryCount": 0,
|
||||
"shouldAbort": true
|
||||
}
|
||||
]
|
||||
31
gcloud/tf/scripts/copy_env_to_first_node.sh
Executable file
31
gcloud/tf/scripts/copy_env_to_first_node.sh
Executable file
|
|
@ -0,0 +1,31 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
source .env
|
||||
|
||||
for i in {1..10}; do
|
||||
# Check if the instance is running
|
||||
INSTANCE_STATUS=$(gcloud compute instances describe k3s-vm-1 --zone=us-central1-a --project="$PROJECT_NAME" --format='get(status)')
|
||||
if [[ "$INSTANCE_STATUS" != "RUNNING" ]]; then
|
||||
echo "Instance k3s-vm-1 is not running. Attempt $i/10. Waiting 5 seconds..."
|
||||
sleep 5
|
||||
continue
|
||||
fi
|
||||
|
||||
# Check if the directory exists on the remote host
|
||||
if gcloud compute ssh k3s-vm-1 --zone=us-central1-a --project="$PROJECT_NAME" --command="test -d /opt/src/infctl-cli/"; then
|
||||
echo "/opt/src/infctl-cli/ exists on k3s-vm-1."
|
||||
break
|
||||
else
|
||||
echo "/opt/src/infctl-cli/ does not exist yet. Attempt $i/10. Waiting 5 seconds..."
|
||||
sleep 5
|
||||
fi
|
||||
done
|
||||
|
||||
# Final check after loop
|
||||
if ! gcloud compute ssh k3s-vm-1 --zone=us-central1-a --project="$PROJECT_NAME" --command="test -d /opt/src/infctl-cli/"; then
|
||||
echo "ERROR: /opt/src/infctl-cli/ does not exist on k3s-vm-1 after 10 attempts. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
gcloud compute scp .env k3s-vm-1:/opt/src/infctl-cli/.env --zone=us-central1-a --project=$PROJECT_NAME
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue