Skip to content

Commit

Permalink
Implemented make shell command to easily start interactive shell in l…
Browse files Browse the repository at this point in the history
…earner environment
  • Loading branch information
niallthomson committed Jun 28, 2022
1 parent 98e23c4 commit 74b40cb
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ test:
e2e-test:
bash hack/run-e2e.sh

.PHONY: shell
shell:
bash hack/shell.sh

.PHONY: update-helm-versions
update-helm-versions:
bash hack/update-helm-versions.sh
4 changes: 2 additions & 2 deletions environment/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

set -e

if [ ! -z "$CLUSTER_NAME" ]; then
aws eks update-kubeconfig --name $CLUSTER_NAME
if [ ! -z "$EKS_CLUSTER_NAME" ]; then
aws eks update-kubeconfig --name $EKS_CLUSTER_NAME
fi

bash -l
30 changes: 30 additions & 0 deletions hack/shell.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

set -Eeuo pipefail

if [ -z "$ASSUME_ROLE" ]; then
echo "Must set ASSUME_ROLE environment variable"
exit 1
fi

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

echo "Generating temporary AWS credentials..."

ACCESS_VARS=$(aws sts assume-role --role-arn $ASSUME_ROLE --role-session-name eks-workshop-shell | jq -r '.Credentials | "export AWS_ACCESS_KEY_ID=\(.AccessKeyId) AWS_SECRET_ACCESS_KEY=\(.SecretAccessKey) AWS_SESSION_TOKEN=\(.SessionToken)"')

echo "Building container images..."

(cd $SCRIPT_DIR/../environment && docker build -q -t eks-workshop-environment .)

# TODO: Retrieve this from state file
export EKS_CLUSTER_NAME="eksw-env-cluster-eks"

# TODO: This should probably not use eval
eval "$ACCESS_VARS"

echo "Starting shell in container..."

docker run -v $SCRIPT_DIR/../site/content:/content -it \
-e "EKS_CLUSTER_NAME" -e "AWS_ACCESS_KEY_ID" -e "AWS_SECRET_ACCESS_KEY" -e "AWS_SESSION_TOKEN" -e "AWS_DEFAULT_REGION" \
eks-workshop-environment

0 comments on commit 74b40cb

Please sign in to comment.