From f5bb59b261c01dae56ef4f60e6c0a4c361254d94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Ka=C5=82u=C5=BCny?= Date: Tue, 6 Dec 2022 14:23:51 +0100 Subject: [PATCH] CosmicTroubleshooting: support for Dev Containers --- .../Student/Challenge-00.md | 33 +++++++- .../Resources/.devcontainer/devcontainer.json | 36 ++++++++ .../Student/Resources/.gitignore | 82 +++++++++++++++++++ .../Challenge00/setup-machine-codespaces.sh | 56 +++++++++++++ 4 files changed, 206 insertions(+), 1 deletion(-) create mode 100644 056-CosmicTroubleshooting/Student/Resources/.devcontainer/devcontainer.json create mode 100644 056-CosmicTroubleshooting/Student/Resources/.gitignore create mode 100644 056-CosmicTroubleshooting/Student/Resources/Challenge00/setup-machine-codespaces.sh diff --git a/056-CosmicTroubleshooting/Student/Challenge-00.md b/056-CosmicTroubleshooting/Student/Challenge-00.md index cceda9a64c..69f59e6b2d 100644 --- a/056-CosmicTroubleshooting/Student/Challenge-00.md +++ b/056-CosmicTroubleshooting/Student/Challenge-00.md @@ -34,6 +34,37 @@ You might not need all of them for the hack you are participating in. However, i - [VS Code plugin for Bicep](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-bicep) - [Azure Storage Explorer](../../000-HowToHack/WTH-Common-Prerequisites.md#azure-storage-explorer) +If you want you can use Visual Studio Code Dev Containers or GitHub Codespaces then check out the [Dev Containers](#dev-containers) section. + +### Dev Containers + +#### Visual Studio Code Dev Containers + +To start the environment in a local container: + +- [Setup Dev Containers](https://code.visualstudio.com/docs/devcontainers/tutorial) +- You can open VS Code in the extracted `Resources.zip` and use the Use the **Dev Containers: Reopen in Container** command from the Command Palette (`F1`, `⇧⌘P`) + +#### GitHub Codespaces + +To start the environment in the GitHub Codespaces: + +- Install [GitHub CLI](https://cli.github.com/) +- Open terminal in + Bash: + ``` + # Login to GitHub CLI + gh auth login + # Initialize git repo and do initial commit + git init -b main + git add . && git commit -m "initial commit" + # Create private repo in your GitHub account and push files + gh repo create WTH-CosmicTroubleshooting --source=. --private --push + ``` +- Go to [GitHub Codespaces](https://github.com/codespaces/new) and create new selecting your repository (your `username/WTH-CosmicTroubleshooting`) + +[How to work with GitHub Codespaces](https://docs.github.com/en/codespaces/developing-in-codespaces/developing-in-a-codespace) + ## Description Now that you have the common prerequisites installed on your workstation, there are prerequisites specific to this hack. @@ -63,7 +94,7 @@ Please deploy the infrastructure by running one of the following scripts in the ``` - Bash: ``` - # Make sure your machine has the prerequisites + # Make sure your machine has the prerequisites (for Github Codespaces and Visual Studio Code Dev Containers use ./setup-machine-codespaces.sh) # Also does an "az login" ./setup-machine.sh diff --git a/056-CosmicTroubleshooting/Student/Resources/.devcontainer/devcontainer.json b/056-CosmicTroubleshooting/Student/Resources/.devcontainer/devcontainer.json new file mode 100644 index 0000000000..52c7fae75a --- /dev/null +++ b/056-CosmicTroubleshooting/Student/Resources/.devcontainer/devcontainer.json @@ -0,0 +1,36 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/dotnet +{ + "name": "C# (.NET)", + "image": "mcr.microsoft.com/devcontainers/dotnet:0-6.0", + "features": { + "ghcr.io/devcontainers/features/azure-cli:1": {}, + "ghcr.io/devcontainers/features/github-cli:1": {}, + "ghcr.io/devcontainers/features/powershell:1": {}, + "ghcr.io/eitsupi/devcontainer-features/jq-likes:0": {} + }, + "customizations": { + "vscode": { + "settings": { + "omnisharp.defaultLaunchSolution": "Challenge00/WTHAzureCosmosDB.sln" + }, + "extensions": [ + "ms-vscode.vscode-node-azure-pack", + "ms-azuretools.vscode-bicep", + "azps-tools.azps-tools", + "ms-vscode.PowerShell" + ] + } + }, + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [5000, 5001], + // Use 'postCreateCommand' to run commands after the container is created./notifications/ + // "postCreateCommand": "dotnet restore", + "postCreateCommand": "dotnet restore Challenge00/WTHAzureCosmosDB.sln && pwsh -Command Install-Module -Name Az -Scope CurrentUser -Repository PSGallery -Force" + // Configure tool-specific properties. + // "customizations": {}, + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} \ No newline at end of file diff --git a/056-CosmicTroubleshooting/Student/Resources/.gitignore b/056-CosmicTroubleshooting/Student/Resources/.gitignore new file mode 100644 index 0000000000..adc440ac73 --- /dev/null +++ b/056-CosmicTroubleshooting/Student/Resources/.gitignore @@ -0,0 +1,82 @@ +### DotnetCore ### +# .NET Core build folders +bin/ +obj/ + +# Common node modules locations +/node_modules +/wwwroot/node_modules + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### macOS Patch ### +# iCloud generated files +*.icloud + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk \ No newline at end of file diff --git a/056-CosmicTroubleshooting/Student/Resources/Challenge00/setup-machine-codespaces.sh b/056-CosmicTroubleshooting/Student/Resources/Challenge00/setup-machine-codespaces.sh new file mode 100644 index 0000000000..86d7ec976d --- /dev/null +++ b/056-CosmicTroubleshooting/Student/Resources/Challenge00/setup-machine-codespaces.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +echoerr() { printf "\033[0;31m%s\n\033[0m" "$*" >&2; } +echosuccess() { printf "\033[0;32m%s\n\033[0m" "$*" >&2; } + +# check installed tooling +echo "Testing tools:"; +az version +if [ $? == 0 ]; then + echosuccess "[.] az cli tool...OK"; +else + echoerr "Error with 'az cli' tool!"; + exit 1; +fi + + +az bicep version +if [ $? == 0 ]; then + echosuccess "[.] bicep support...OK"; +else + echo "Installing bicep" + az bicep install + exit 1; +fi + + +dotnet --version +if [ $? == 0 ]; then + echosuccess "[.] dotnet support...OK"; +else + echoerr "Error with dotnet!"; + exit 1; +fi + +jq --version +if [ $? == 0 ]; then + echosuccess "[.] jq tool...OK"; +else + echoerr "Error with 'jq' tool!"; + exit 1; +fi + +echo "Asking user to log in..."; +# ask user for login +az login +if [ $? == 0 ]; then + echosuccess " + Your machine should be ready! Now proceed with ./deploy.sh script + + "; +else + echoerr "Login into Azure failed!"; + exit 1; +fi +# set executable bit on ./deploy.sh +chmod +x ./deploy.sh \ No newline at end of file