From 2f118907795233ec869f18a02c512bd3059860f1 Mon Sep 17 00:00:00 2001 From: jon brookes Date: Tue, 14 Oct 2025 18:15:32 +0100 Subject: [PATCH] feat: add .env file check and load it in startup script --- gcloud/tf/scripts/k3s-vm-startup.sh | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/gcloud/tf/scripts/k3s-vm-startup.sh b/gcloud/tf/scripts/k3s-vm-startup.sh index 658ecac..48c5d29 100644 --- a/gcloud/tf/scripts/k3s-vm-startup.sh +++ b/gcloud/tf/scripts/k3s-vm-startup.sh @@ -103,3 +103,32 @@ if [[ ! -d "$INFCTL_INSTALL_DIR" ]]; then chown -R user:user "$INFCTL_INSTALL_DIR" fi +for i in {1..100}; do + if [[ -f /opt/src/infctl-cli/.env ]]; then + echo ".env file found." + break + else + echo ".env file not found. Attempt $i/100. Waiting 5 seconds..." + sleep 5 + fi +done + +# Final check after loop +if [[ ! -f /opt/src/infctl-cli/.env ]]; then + echo "ERROR: .env file not found after 10 attempts. Exiting." + exit 1 +fi + +# load .env file +source /opt/src/infctl-cli/.env +cd $INFCTL_INSTALL_DIR/infctl-cli || "echo 'Failed to change directory to $INFCTL_INSTALL_DIR/infctl-cli' ; exit 1" + +# check to see if INSTALL_FORGEJO is set to "true" +if [[ "$INSTALL_FORGEJO" == "true" ]]; then + # install forgejo using infctl + # .... + export KUBECONFIG=/etc/rancher/k3s/k3s.yaml + LOG_FORMAT=none infctl -f "${INFCTL_INSTALL_DIR}/infctl-cli/gcloud/tf/scripts/install-forgejo-pipeline.json" + touch /etc/forgejo_was_installed + +fi