diff --git a/bin/deploy-via-gcloud.sh b/bin/deploy-via-gcloud.sh index fc1e90f..9fefdeb 100755 --- a/bin/deploy-via-gcloud.sh +++ b/bin/deploy-via-gcloud.sh @@ -8,8 +8,9 @@ set -u # Treat unset variables as an error when substituting deploy_via_gcloud() { printf "\n" + # Load the current project variables script_dir=$(dirname "$0") - source "${script_dir}/select-environment.sh" "$1" + source "${script_dir}/get-project-vars.sh" # Deploy the Google Cloud Function echo "Deploying to Google Cloud Functions..." diff --git a/bin/get-function-logs-url.sh b/bin/get-function-logs-url.sh index 7901f2d..c82f9d7 100755 --- a/bin/get-function-logs-url.sh +++ b/bin/get-function-logs-url.sh @@ -6,8 +6,9 @@ set -u # Treat unset variables as an error when substituting # Prints the log explorer URL for the Cloud Function and displays it in the terminal. # Requires an environment arg (e.g., staging, production). get_function_logs_url() { + # Load the current project variables script_dir=$(dirname "$0") - source "${script_dir}/select-environment.sh" "$1" + source "${script_dir}/get-project-vars.sh" # Get time 1 hour ago in UTC start_time=$(date -u -v-1H +"%Y-%m-%dT%H:%M:%S.000Z") diff --git a/bin/get-function-logs.sh b/bin/get-function-logs.sh index 8edfc7c..3762f65 100755 --- a/bin/get-function-logs.sh +++ b/bin/get-function-logs.sh @@ -6,11 +6,13 @@ set -u # Treat unset variables as an error when substituting # Fetches the latest logs for the Cloud Function and displays them in the terminal. # Requires an environment arg (e.g., staging, production). get_function_logs() { + # Load the current project variables script_dir=$(dirname "$0") - source "${script_dir}/select-environment.sh" "$1" + source "${script_dir}/get-project-vars.sh" # Fetch raw logs raw_logs=$(gcloud logging read "resource.labels.function_name=${function_name}" \ + --project "${project_id}" \ --format json \ --limit 50) diff --git a/bin/select-environment.sh b/bin/select-environment.sh deleted file mode 100755 index f48fb19..0000000 --- a/bin/select-environment.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash -set -e # Fail on any error -set -o pipefail # Ensure piped commands propagate exit codes properly -set -u # Treat unset variables as an error when substituting - -select_environment() { - # Check if environment parameter is provided - if [[ $# -ne 1 ]]; then - echo "Usage: $0 " - echo "Example: $0 staging" - exit 1 - fi - env=$1 - - # Load the current project variables - script_dir=$(dirname "$0") - source "${script_dir}/get-project-vars.sh" - - # Select the desired workspace - terraform -chdir=infra workspace select "${env}" - cached_workspace=${workspace} - - # Determine if cache should be invalidated to not deploy to the wrong environment - if [[ ${env} != "${cached_workspace}" ]]; then - source "${script_dir}/get-project-vars.sh" --invalidate-cache - fi -} - -select_environment "$@"