Skip to content

Commit

Permalink
🔀 Merge pull request datawire#15 from datawire/pgranger/dev/add-telem…
Browse files Browse the repository at this point in the history
…etry
  • Loading branch information
grangerp authored Jan 27, 2022
2 parents 1581d8d + e4835d2 commit 38d401c
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions emojivoto-web-app/js/setup_dev_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,28 @@
CONTAINER_ID=''
OS=''
ARCH=''
MOUNT_VOLUME=''
MOUNT_VOLUME_LOCAL=''
USE_TELEMETRY=
OPEN_EDITOR=
ACTIVITY_REPORT_TYPE='INTERMEDIATE_CLOUD_TOUR_SCRIPT'

use_telemetry() {
USE_TELEMETRY=true
}

send_telemetry() {
if [ $USE_TELEMETRY = true ]; then
action=$1
ambassador_cloud_url="https://auth.datawire.io"
application_activities_url="${ambassador_cloud_url}/api/applicationactivities"
curl -X POST \
-H "X-Ambassador-API-Key: $AMBASSADOR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"type": "'$ACTIVITY_REPORT_TYPE'", "extraProperties": {"action":"'"$action"'","os":"'"$OS"'","arch":"'"$ARCH"'"}}' \
-s \
$application_activities_url > /dev/null 2>&1
fi
}

has_cli() {

Expand All @@ -27,10 +48,12 @@ set_os_arch() {
"Darwin")
OS="darwin"
MOUNT_VOLUME_LOCAL=~/Library/Application\ Support
OPEN_EDITOR=open
;;
"Linux")
OS="linux"
MOUNT_VOLUME_LOCAL=$(if [[ "$XDG_CONFIG_HOME" ]]; then echo "$XDG_CONFIG_HOME"; else echo "$HOME/.config"; fi)
OPEN_EDITOR=xdg-open
;;
*)
fatal "Unsupported os $uname"
Expand Down Expand Up @@ -80,6 +103,7 @@ run_dev_container() {

# run the dev container, exposing 8081 gRPC port and volume mounting code directory
CONTAINER_ID=$(docker run -d -p8083:8083 -p8080:8080 --name ambassador-demo --cap-add=NET_ADMIN --device /dev/net/tun:/dev/net/tun --pull always --rm -it -e AMBASSADOR_API_KEY=$AMBASSADOR_API_KEY -v "${MOUNT_VOLUME_LOCAL}":/root/.host_config -v $(pwd):/opt/emojivoto/emojivoto-web-app/js datawire/emojivoto-node-and-go-demo )
send_telemetry "devContainerStarted"
}

connect_to_k8s() {
Expand All @@ -93,6 +117,7 @@ connect_to_k8s() {

echo 'Connected to cluster. Listing services in default namespace'
kubectl get svc
send_telemetry "connectedToK8S"
}

install_telepresence() {
Expand All @@ -102,8 +127,10 @@ install_telepresence() {
echo "Installing Telepresence"
sudo curl -fL https://app.getambassador.io/download/tel2/${OS}/${ARCH}/latest/telepresence -o /usr/local/bin/telepresence
sudo chmod a+x /usr/local/bin/telepresence
send_telemetry "telepresenceInstalled"
else
echo "Telepresence already installed"
send_telemetry "telepresenceAlreadyInstalled"
fi
}

Expand All @@ -114,8 +141,10 @@ connect_local_dev_env_to_remote() {
telepresence intercept web-app-57bc7c4959 -n emojivoto --service web-app --port 8083:80 --ingress-port 80 --ingress-host ambassador.ambassador --ingress-l5 ambassador.ambassador
telOut=$?
if [ $telOut != 0 ]; then
send_telemetry "interceptFailed"
exit $telOut
fi
send_telemetry "interceptCreated"
}

open_editor() {
Expand All @@ -124,7 +153,7 @@ open_editor() {
sleep 2

# replace this line with your editor of choice, e.g. VS code, Intelli J
$EDITOR .
$OPEN_EDITOR components/Vote.jsx
}

display_instructions_to_user () {
Expand All @@ -135,6 +164,7 @@ display_instructions_to_user () {
echo 'export KUBECONFIG=./emojivoto_k8s_context.yaml'
}

use_telemetry
has_cli
set_os_arch
check_init_config
Expand Down

0 comments on commit 38d401c

Please sign in to comment.