Skip to content

Commit

Permalink
adjusting devcontainer to include a basic labs cli
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Pflueger committed Oct 17, 2023
1 parent 9c98ed6 commit 661e503
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 25 deletions.
4 changes: 4 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ ENV PATH="$PATH:/home/$USERNAME/.cargo/bin"
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | bash -s -- \
-y --target wasm32-wasi

# Install Spin Plugins & Templates
RUN spin plugins update && \
spin plugins install check-for-update -y && \
spin plugins install cloud -y && \
Expand All @@ -40,3 +41,6 @@ RUN spin plugins update && \
spin templates install --upgrade --git https://github.com/fermyon/spin && \
spin templates install --upgrade --git https://github.com/fermyon/spin-js-sdk && \
spin templates install --upgrade --git https://github.com/fermyon/spin-python-sdk

# Source the labs-cli.sh for the default shell
RUN echo ". /workspaces/spin-fundamentals/labs/labs-cli.sh" >> $HOME/.zshenv
26 changes: 17 additions & 9 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,27 @@
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
// "image": "mcr.microsoft.com/devcontainers/base:jammy",
"build": {
"dockerfile": "Dockerfile"
"dockerfile": "Dockerfile",
"context": "."
},
"features": {
},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "uname -a",
// Most features are built into the Dockerfile for startup time reduction. For more information, see
"features": {},

// Configure tool-specific properties.
// "customizations": {},
"customizations": {
"vscode": {
"settings": {
"terminal.integrated.defaultProfile.linux": "zsh",
"terminal.integrated.profiles.linux": {
"zsh": {
"path": "/usr/bin/zsh",
"icon": "terminal-linux"
}
}
}
}
},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
"remoteUser": "vscode"
Expand Down
16 changes: 16 additions & 0 deletions labs/01-new-app/lab.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env zsh

lab-01-setup()
{
echo "Setting up lab 1..."
}

lab-01-check()
{
echo "Checking lab 1..."
}

lab-01-solve()
{
echo "Solving lab 1..."
}
16 changes: 0 additions & 16 deletions labs/01-new-app/workstation.sh

This file was deleted.

114 changes: 114 additions & 0 deletions labs/labs-cli.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#!/usr/bin/zsh

#TODO: would it make more sense to do this in something like JS or Python?

pushd . > '/dev/null';
__LABS_DIR="${BASH_SOURCE[0]:-$0}";

while [ -h "$__LABS_DIR" ];
do
cd "$( dirname -- "$__LABS_DIR"; )";
__LABS_DIR="$( readlink -f -- "$__LABS_DIR"; )";
done

cd "$( dirname -- "$__LABS_DIR"; )" > '/dev/null';
__LABS_DIR="$( pwd; )";
popd > '/dev/null';

labs() {
# use the argument select a sub-command
case $1 in
list)
__labs_list
;;
show)
__labs_show
;;
check)
__labs_check
;;
-h|--help)
__labs_usage
;;
*)
echo "Unknown command $1"
__labs_usage
;;
esac
}

__labs_usage() {
echo "Usage: labs [options] <command>"
echo ""
echo "Options:"
echo " -h, --help Show help"
echo ""
echo "Commands:"
echo " show Shows the current in-progress lab"
echo " list List available labs"
echo " check Checks the current in-progress lab"
}

__labs_show() {
echo "-------------------------------------------------------------------------------------------------------"
echo "| Lab # | Description | Status | Path |"
echo "| ------- | ------------- | ---------- | ------------------------------------------------------------ |"
__lab_display "$(__labs_current)"
echo "-------------------------------------------------------------------------------------------------------"
}

__labs_list() {
echo "-------------------------------------------------------------------------------------------------------"
echo "| Lab # | Description | Status | Path |"
echo "| ------- | ------------- | ---------- | ------------------------------------------------------------ |"
for lab in $(ls -d $__LABS_DIR/*/); do
__lab_display "$lab"
done
echo "-------------------------------------------------------------------------------------------------------"
}

__labs_check() {
local lab="$(__labs_current)"
__lab_get "$lab"
lab-${lab_number}-check
}

__labs_current() {
for lab in $(ls -d $__LABS_DIR/*/); do
if [ ! -f $lab/.completed ]; then
echo "$lab"
break
fi
done
}

__lab_display() {
__lab_get "$1"
printf "| %-7s | %-13s | %-10s | %-60s |\n" $lab_number $lab_description $lab_status $lab_path
}

__lab_get() {
lab="$1"
lab_name=$(basename $lab)
lab_number=$(echo $lab_name | cut -d'-' -f1)
lab_description=$(echo $lab_name | cut -d'-' -f2-)

# NOTE: use grealpath on Darwin
# TODO: probably a better way to do this right?
if [ "$(uname)" = "Darwin" ]; then
lab_path=$(grealpath --relative-to=${PWD} $lab)
else
lab_path=$(realpath --relative-to=${PWD} $lab)
fi

if [ -f $lab/.completed ]; then
lab_status='completed '
else
lab_status='incomplete'
fi
}

# source all of the individual lab scripts
for lab in $(ls -d $__LABS_DIR/*/); do
. "$lab/lab.sh"
done

0 comments on commit 661e503

Please sign in to comment.