Skip to content

Commit

Permalink
fetch session metadata and store to env file for deployment type apps…
Browse files Browse the repository at this point in the history
… using xpra
  • Loading branch information
Dan Isla authored and danisla committed Jan 26, 2022
1 parent f3a6a0a commit c8c1a3d
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 1 deletion.
1 change: 1 addition & 0 deletions images/watchdog/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ FROM python:3-slim

RUN apt-get update && apt-get install -y \
curl \
jq \
ca-certificates && \
rm -rf /var/lib/apt/lists/*

Expand Down
3 changes: 3 additions & 0 deletions images/watchdog/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

set -ex

# Run startup script to query session metadata
/opt/app/startup.sh &

# Timeout in seconds to wait for x server before shutting down
XSERVER_TIMEOUT=${WATCHDOG_TIMEOUT:-60}

Expand Down
34 changes: 34 additions & 0 deletions images/watchdog/startup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

# Copyright 2022 The Selkies Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

if [[ "${VDI_enableXpra:-false}" == true ]]; then
echo "Waiting for Xpra"
until [[ -e /var/run/appconfig/xpra_ready ]]; do sleep 1; done
echo "Xpra server is ready"
fi

echo "INFO: Fetching session metadata for ${APP_NAME?} pod for user ${POD_USER?} through pod broker" >&2
mkdir -p /var/run/appconfig/

if [[ ${IN_CLUSTER:-"true"} == "true" ]]; then
curl -s -f -v -H "Cookie: ${BROKER_COOKIE?}" -H "Host: ${BROKER_HOST?}" -X GET ${IN_CLUSTER_BROKER_ENDPOINT}/${APP_NAME?}/ | tee /var/run/appconfig/session_metadata.json
else
ID_TOKEN=$(curl -s -f -H "Metadata-Flavor: Google" "http://metadata/computeMetadata/v1/instance/service-accounts/default/identity?audience=${CLIENT_ID?}&format=full")
curl -s -f -H "Cookie: ${BROKER_COOKIE?}" -H "Authorization: Bearer ${ID_TOKEN}" -X DELETE ${BROKER_ENDPOINT?}/${APP_NAME?}/ | tee /var/run/appconfig/session_metadata.json
fi

# Notify sidecars that startup is complete
touch /var/run/appconfig/session_metadata_ready# XProp of Eclipse IDE Launcher window
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,10 @@
- name: APP_NAME
value: "{{ $appName }}"
- name: WATCHDOG_TIMEOUT
value: "{{default 600 .AppParams.idleShutdownTimeout}}"
value: "{{default 600 .AppParams.idleShutdownTimeout}}"

# Add the appParams to the env prefixed with VDI_
{{- range $key, $value := .AppParams }}
- name: VDI_{{ $key }}
value: {{ quote $value }}
{{- end}}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@
fi

while true; do
{{- if eq .AppSpec.Type "deployment" }}
echo "Waiting for session metadata..."
until [[ -e /var/run/appconfig/session_metadata_ready ]]; do sleep 0.5; done
echo "Found session metadata, exporting VDI_ variables to environment"
# Export session params as VDI ENV vars, if present.
jq -r '.user_params|to_entries|map("export VDI_\(.key)=\(.value|tostring)")|.[]' /var/run/appconfig/session_metadata.json | \
tee /var/run/appconfig/user_vdi_env
source /var/run/appconfig/user_vdi_env
{{- end}}

eval ${XPRA_ENTRYPOINT:-"xfdesktop --sm-client-disable -A"} &
PID=$!
if [[ "${XPRA_ENTRYPOINT}" =~ xfdesktop ]]; then
Expand Down

0 comments on commit c8c1a3d

Please sign in to comment.