diff --git a/gcloud/tf/scripts/build-gcloud-k3s-pipeline.json b/gcloud/tf/scripts/build-gcloud-k3s-pipeline.json index 179282f..d1fd61b 100644 --- a/gcloud/tf/scripts/build-gcloud-k3s-pipeline.json +++ b/gcloud/tf/scripts/build-gcloud-k3s-pipeline.json @@ -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 } ] \ No newline at end of file diff --git a/gcloud/tf/scripts/copy_env_to_first_node.sh b/gcloud/tf/scripts/copy_env_to_first_node.sh new file mode 100755 index 0000000..5bce28a --- /dev/null +++ b/gcloud/tf/scripts/copy_env_to_first_node.sh @@ -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 +