Skip to content

Commit 209ab66

Browse files
committed
fixes
1. decouple util files 2. fetch workspace_id from user_facing_id
1 parent 6c9b6c1 commit 209ab66

File tree

4 files changed

+25
-28
lines changed

4 files changed

+25
-28
lines changed

startupscript/butane/004-git-clone-devcontainer.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ api_url="${api_url%.git}"
4646
private_status=$(curl --retry 5 -s "${api_url}" | jq -r ".status")
4747
if [[ "${PRIVATE_DEVCONTAINER_ENABLED}" == "TRUE" && "${private_status}" == 404 ]]; then
4848
# Get ECM service URL
49-
if ! ECM_SERVICE_URL="$(get_service_url "ecm")"; then
49+
SERVER="$(get_metadata_value "terra-cli-server" "prod")"
50+
if ! ECM_SERVICE_URL="$(get_service_url "ecm" "${SERVER}")"; then
5051
exit 1
5152
fi
5253

startupscript/butane/pre-devcontainer.sh

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,26 @@ set -o xtrace
1111
# Keep track of the number of service failures
1212
touch /tmp/devcontainer-failure-count
1313

14-
# Fetch and cache workspace metadata
15-
source /home/core/service-utils.sh
14+
# Fetch and cache workspace_id
1615
source /home/core/metadata-utils.sh
17-
18-
WORKSPACE_USER_FACING_ID="$(get_metadata_value "terra-workspace-id" "")"
19-
RESOURCE_ID="$(get_metadata_value "wb-resource-id" "")"
20-
WSM_SERVICE_URL="$(get_service_url "wsm")"
21-
22-
# Cache workspace_id if not already cached
16+
source /home/core/service-utils.sh
17+
MONITORING_UTILS_FILE="/home/core/monitoring-utils.sh"
2318
WORKSPACE_ID_CACHE_FILE="/tmp/workspace_id_cache"
24-
if [[ ! -f "${WORKSPACE_ID_CACHE_FILE}" ]]; then
19+
FIRST_BOOT_START_FILE="/home/core/first-boot-start"
20+
if [[ -f "${MONITORING_UTILS_FILE}" && ! -f "${FIRST_BOOT_START_FILE}" ]]; then
21+
# First boot file does not exist
22+
## Cache workspace id to be used by probe-proxy-readiness.sh
23+
WORKSPACE_USER_FACING_ID="$(get_metadata_value "terra-workspace-id" "")"
24+
SERVER="$(get_metadata_value "terra-cli-server" "prod")"
25+
WSM_SERVICE_URL="$(get_service_url "wsm" "${SERVER}")"
2526
RESPONSE=$(curl -s -X GET "${WSM_SERVICE_URL}/api/workspaces/v1/workspaceByUserFacingId/${WORKSPACE_USER_FACING_ID}" \
2627
-H "Authorization: Bearer $(/home/core/wb.sh auth print-access-token)")
27-
WORKSPACE_ID=$(echo "${RESPONSE}" | jq -r '.id')
28+
WORKSPACE_ID=$(echo "${RESPONSE}" | jq -r '.id');
2829
echo "${WORKSPACE_ID}" > "${WORKSPACE_ID_CACHE_FILE}"
29-
else
30-
WORKSPACE_ID=$(cat "${WORKSPACE_ID_CACHE_FILE}")
31-
fi
3230

33-
# Record startup begin for monitoring on first boot
34-
FIRST_BOOT_START_FILE="/home/core/first-boot-start"
35-
if [[ ! -f "${FIRST_BOOT_START_FILE}" ]]; then
36-
source /home/core/monitoring-utils.sh
31+
## Record devcontainer begin for monitoring
32+
source "${MONITORING_UTILS_FILE}"
33+
RESOURCE_ID="$(get_metadata_value "wb-resource-id" "")"
3734
record_devcontainer_start "${WSM_SERVICE_URL}" "${WORKSPACE_ID}" "${RESOURCE_ID}"
3835
fi
3936
touch "${FIRST_BOOT_START_FILE}"

startupscript/butane/probe-proxy-readiness.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,16 @@ if docker ps -q --filter "name=proxy-agent" | grep -q . \
2525
MONITORING_UTILS_FILE="/home/core/monitoring-utils.sh"
2626
if [[ -f "${MONITORING_UTILS_FILE}" && ! -f "${FIRST_BOOT_END_FILE}" ]]; then
2727
# first boot file does not exist
28-
# record startup end for monitoring
28+
# record devcontainer end for monitoring
2929
source /home/core/service-utils.sh
3030
source "${MONITORING_UTILS_FILE}"
3131

3232
# Fetch required values
3333
WORKSPACE_ID_CACHE_FILE="/tmp/workspace_id_cache"
3434
WORKSPACE_ID=$(cat "${WORKSPACE_ID_CACHE_FILE}")
3535
RESOURCE_ID="$(get_metadata_value "wb-resource-id" "")"
36-
WSM_SERVICE_URL="$(get_service_url "wsm")"
36+
SERVER="$(get_metadata_value "terra-cli-server" "prod")"
37+
WSM_SERVICE_URL="$(get_service_url "wsm" "${SERVER}")"
3738

3839
record_devcontainer_end "${WSM_SERVICE_URL}" "${WORKSPACE_ID}" "${RESOURCE_ID}" "${success}"
3940
fi
Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
#!/bin/bash
22
# service-utils defines helper functions for determining service path.
3-
source /home/core/metadata-utils.sh
43

54
# Map the server to appropriate service path
65
function get_service_url() {
7-
SERVER="$(get_metadata_value "terra-cli-server" "")"
8-
if [[ -z "${SERVER}" ]]; then
9-
SERVER="prod"
6+
if [[ $# -lt 2 ]]; then
7+
echo "usage: get_service_url <service> <server>" >&2
8+
return 1
109
fi
11-
readonly SERVER
1210

13-
SERVICE="$1"
14-
readonly SERVICE
11+
local SERVICE="$1"
12+
local SERVER="$2"
1513

1614
case "${SERVER}" in
1715
"dev-stable") echo "https://workbench-dev.verily.com/api/${SERVICE}" ;;
@@ -21,4 +19,4 @@ function get_service_url() {
2119
*) return 1 ;;
2220
esac
2321
}
24-
readonly -f get_service_url
22+
readonly -f get_service_url

0 commit comments

Comments
 (0)