diff --git a/installer/utils.sh b/installer/utils.sh index 312a0a21b..4206123ae 100755 --- a/installer/utils.sh +++ b/installer/utils.sh @@ -300,6 +300,8 @@ load_cluster_state_env() { # fi # export ADMIN_EMAIL=$(openssl x509 -in ${SAVE_DIR}/fullchain-${AWS_ACCOUNT}-${CLUSTER_NAME}.pem -noout -email) # fi + + restore_env_from_s3 } clone_repo() { diff --git a/pod-configs/utils/lib/common.sh b/pod-configs/utils/lib/common.sh index 0bec4d1bc..f1e489829 100755 --- a/pod-configs/utils/lib/common.sh +++ b/pod-configs/utils/lib/common.sh @@ -136,6 +136,28 @@ upload_savedir() { fi } +restore_env_from_s3() { + if [ ! -f ${HOME}/.env ] && [ -n "${BUCKET_NAME:-}" ] && [ -n "${AWS_REGION:-}" ] && [ -n "${SAVE_DIR_S3:-}" ]; then + if check_s3_savedir_file .env 2>/dev/null; then + echo "Info: Restoring .env file from S3..." + download_savedir_file .env + if [ -f ${SAVE_DIR}/.env ]; then + cp ${SAVE_DIR}/.env ${HOME}/.env + chmod 600 ${HOME}/.env + echo "Info: .env file restored from S3." + export $(cat ${HOME}/.env | xargs) + fi + fi + fi +} + +backup_env_to_s3() { + if [[ -f ~/.env ]]; then + cp ~/.env ${SAVE_DIR}/.env + upload_savedir_file .env + fi +} + remove_s3_data() { files=$(all_data_files_v2) for file in $files; do diff --git a/pod-configs/utils/provision.sh b/pod-configs/utils/provision.sh index 4b91f3f5c..4dedcf8ec 100755 --- a/pod-configs/utils/provision.sh +++ b/pod-configs/utils/provision.sh @@ -1142,7 +1142,6 @@ EOF popd - jq -n ". += {\"gitea_argo_user\":${gitea_argo_user}}" | \ jq ". += {\"gitea_argo_token\":${gitea_argo_token}}" | \ jq ". += {\"gitea_co_user\":${gitea_co_user}}" | \ @@ -1358,6 +1357,8 @@ action_orch_loadbalancer() { echo "ARGOCD_TG_ARN=${argocd_tg_arn}" >> ~/.env fi popd + + backup_env_to_s3 fi rm -rf $dir @@ -1665,6 +1666,7 @@ install() { if ! check_s3_savedir_empty && ! [[ -f ${values_changed} ]]; then download_savedir echo "Info: Pulled S3 ${SAVE_DIR}." + restore_env_from_s3 fi if [[ ! -f ${SAVE_DIR}/${VARIABLE_TFVAR} ]]; then @@ -1736,6 +1738,7 @@ uninstall() { if ! check_s3_savedir_empty && ! [[ -f ${values_changed} ]]; then download_savedir echo "Info: Pulled S3 ${SAVE_DIR}." + restore_env_from_s3 else echo "Warning: Failed to download data files from S3. Make sure the value specified for the --customer-state-prefix parameter is correct. Type \"yes\" to continue, others to quit: "; read s @@ -1809,6 +1812,7 @@ pull-savedir() { if check_local_savedir_empty && ! check_s3_savedir_empty; then download_savedir echo "Info: files have been pulled in the ${SAVE_DIR} directory." + restore_env_from_s3 else echo "Error: Some files have existed. No file is pulled. If you really want to pull, remove the files related to ${ENV_NAME} from the ${SAVE_DIR} directory and try again." exit 1 @@ -1939,6 +1943,7 @@ config() { if ! check_s3_savedir_empty && ! [[ -f ${values_changed} ]]; then download_savedir echo "Info: Pulled S3 ${SAVE_DIR}." + restore_env_from_s3 fi set_values "config" @@ -2010,6 +2015,7 @@ upgrade() { echo "Info: Checking deployed version..." download_savedir + restore_env_from_s3 load_values check_running_sshuttle refresh_sshuttle @@ -2069,6 +2075,7 @@ update-cluster-setting() { if ! check_s3_savedir_empty; then download_savedir echo "Info: Pulled S3 ${SAVE_DIR}." + restore_env_from_s3 fi local profile_file="$SAVE_DIR/$PROFILE_TFVAR"