11#! /bin/bash
22
3- # pre-devcontainer.sh creates a file used by the devcontainer service to keep
4- # track of the number of service failures.
3+ # pre-devcontainer.sh creates a file used by the devcontainer service for monitoring
4+ # and to keep track of the number of service failures.
55
6- touch /tmp/devcontainer-failure-count
6+ set -o errexit
7+ set -o nounset
8+ set -o pipefail
9+ set -o xtrace
10+
11+ # Keep track of the number of service failures
12+ touch /tmp/devcontainer-failure-count
13+
14+ # Fetch and cache workspace_id
15+ source /home/core/metadata-utils.sh
16+ source /home/core/service-utils.sh
17+ MONITORING_UTILS_FILE=" /home/core/monitoring-utils.sh"
18+ WORKSPACE_ID_CACHE_FILE=" /tmp/workspace_id_cache"
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} " ) "
26+ RESPONSE=$( curl -s -X GET " ${WSM_SERVICE_URL} /api/workspaces/v1/workspaceByUserFacingId/${WORKSPACE_USER_FACING_ID} " \
27+ -H " Authorization: Bearer $( /home/core/wb.sh auth print-access-token) " )
28+ WORKSPACE_ID=$( echo " ${RESPONSE} " | jq -r ' .id' ) ;
29+ echo " ${WORKSPACE_ID} " > " ${WORKSPACE_ID_CACHE_FILE} "
30+
31+ # # Record devcontainer begin for monitoring
32+ source " ${MONITORING_UTILS_FILE} "
33+ RESOURCE_ID=" $( get_metadata_value " wb-resource-id" " " ) "
34+ record_devcontainer_start " ${WSM_SERVICE_URL} " " ${WORKSPACE_ID} " " ${RESOURCE_ID} "
35+ fi
36+ touch " ${FIRST_BOOT_START_FILE} "
0 commit comments