Skip to content

Commit

Permalink
Merge branch 'master' into dp-scaffold
Browse files Browse the repository at this point in the history
  • Loading branch information
dpark01 authored Feb 5, 2024
2 parents b0b2ac5 + 45c4c27 commit 3cddc0d
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions pipes/WDL/tasks/tasks_terra.wdl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ task check_terra_env {
touch google_project_id.txt

# create Terra-related output files
touch user_email.txt
touch workspace_name.txt
touch workspace_namespace.txt
touch workspace_bucket_path.txt
Expand All @@ -61,6 +62,20 @@ task check_terra_env {
# write system environment variables to output file
env | tee -a env_info.log

# check if running on GCP
if curl -s metadata.google.internal -i | grep -E 'Metadata-Flavor:\s+Google'; then
echo "Cloud platform appears to be GCP";
echo "true" > RUNNING_ON_GCP

GCLOUD_OAUTH_BEARER_TOKEN="$(gcloud auth print-access-token)"

# write gcloud env info to output files
gcloud info | tee -a gcloud_config_info.log
else
echo "NOT running on GCP";
echo "false" > RUNNING_ON_GCP
fi

GOOGLE_PROJECT_ID="$(gcloud config list --format='value(core.project)')"
echo "$GOOGLE_PROJECT_ID" > google_project_id.txt

Expand All @@ -70,23 +85,19 @@ task check_terra_env {
# (shell-portable regex conditional)
echo "Job appears to be running on Terra (GCP project ID: ${GOOGLE_PROJECT_ID})"
echo "true" > RUNNING_ON_TERRA

# get user e-mail for Terra account via firecloud API
curl -s -X 'GET' \
'https://api.firecloud.org/me?userDetailsOnly=true' \
-H 'accept: application/json' \
-H "Authorization: Bearer $GCLOUD_OAUTH_BEARER_TOKEN" > user_info.json

USER_EMAIL="$(jq -cr '.userEmail' user_info.json | tee user_email.txt)"
else
echo "NOT running on Terra"
echo "false" > RUNNING_ON_TERRA
fi

# check if running on GCP
if curl -s metadata.google.internal -i | grep -E 'Metadata-Flavor:\s+Google'; then
echo "Cloud platform appears to be GCP";
echo "true" > RUNNING_ON_GCP

# write gcloud env info to output files
gcloud info | tee -a gcloud_config_info.log
else
echo "NOT running on GCP";
echo "false" > RUNNING_ON_GCP
fi

if grep --quiet "true" RUNNING_ON_GCP && grep --quiet "true" RUNNING_ON_TERRA; then
echo "Running on Terra+GCP"

Expand All @@ -112,8 +123,6 @@ task check_terra_env {
#GOOGLE_PROJECT_ID="$(sed -n -E 's!.*(terra-[0-9a-f]+).*# project to use if requester pays$!\1!p' /cromwell_root/gcs_localization.sh | sort -u)"
# =======================================

GCLOUD_OAUTH_BEARER_TOKEN="$(gcloud auth print-access-token)"

# === request workspace name AND namespace from API, based on bucket path / ID ===
curl -s -X 'GET' \
"https://api.firecloud.org/api/workspaces/id/${WORKSPACE_ID}?fields=workspace.name%2Cworkspace.namespace%2Cworkspace.googleProject" \
Expand Down Expand Up @@ -201,6 +210,8 @@ task check_terra_env {

String google_project_id = read_string("google_project_id.txt")

String user_email = read_string("user_email.txt")

String workspace_id = read_string("workspace_id.txt")
String workspace_name = read_string("workspace_name.txt")
String workspace_namespace = read_string("workspace_namespace.txt")
Expand Down

0 comments on commit 3cddc0d

Please sign in to comment.