Skip to content

Instantly share code, notes, and snippets.

@greyhoundforty
Last active July 28, 2020 13:40
Show Gist options
  • Save greyhoundforty/e43a31b8e21e5dbf2d3baa9fb8b531e9 to your computer and use it in GitHub Desktop.
Save greyhoundforty/e43a31b8e21e5dbf2d3baa9fb8b531e9 to your computer and use it in GitHub Desktop.
Windows Dev Lab 1

Windows Dev Lunch

Pre-work

If you have about 15-20 minutes ahead of the lunch today go ahead and install WSL and Docker for Desktop

Install Windows Subsystem for Linux

The Windows Subsystem for Linux lets developers run a GNU/Linux environment -- including most command-line tools, utilities, and applications -- directly on Windows, unmodified, without the overhead of a traditional virtual machine or dualboot setup.

Note: You will be prompted to restart the machine after WSL feature is first installed. Choose not to restart until we have also installed Docker desktop.

Powershell

Open a Powershell session as Administrator and run the following command:

## Powershell
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

GUI

If you want to enable the feature via the GUI you will need to launch Server Manager.

  • In the main dialog box you should see a link for Add features and roles. Click on that to start the install wizard 🔧.

Add Features and Roles

  • Select Role Based for the install type
  • Select your local server
  • Select Next on the Roles page
  • In the Features options, scroll down and select Windows Subsystem for Linux

Add WSL Role

Docker desktop (Skip for now)

Note: You will be prompted to restart the machine after installing Docker desktop. So if you were tinkering with things save all your work before you log out.

## Powershell
Invoke-WebRequest -Uri https://download.docker.com/win/stable/Docker%20Desktop%20Installer.exe -OutFile DockerDesktop.exe -UseBasicParsing
.\DockerDesktop.exe

If for some reason the Powershell download appears stuck, just pop https://download.docker.com/win/stable/Docker%20Desktop%20Installer.exe in to your browser and install it that way.

Reboot machine

☕ ⏰

Install an OS image for WSL

You can find supported images here on the WSL site. The rest of the guide assumes you're using Ubuntu 18 for the Virtual machine but most of the commands should translate to other (incorrect) operating system choices.

## Powershell
Invoke-WebRequest -Uri https://aka.ms/wsl-ubuntu-1804 -OutFile Ubuntu.appx -UseBasicParsing
Rename-Item .\Ubuntu.appx .\Ubuntu.zip
Expand-Archive .\Ubuntu.zip .\Ubuntu

Open up Windows explorer to C:\Users\Administrator\Ubuntu and double click on the ubuntu1804.exe to start the install process. You will be prompted to create a linux system user and set a password. With those set you are now dropped in to your WSL shell.

WSL Terminal

Once the install completes go back to Powershell and run the following commands to set the ubuntu executable to be in our path:

## Powershell
$userenv = [System.Environment]::GetEnvironmentVariable("Path", "User")
[System.Environment]::SetEnvironmentVariable("PATH", $userenv + ";C:\Users\Administrator\Ubuntu", "User")

Install common utilities (WSL terminal)

Since we will likely be re-using these machines for future lunch and learns I would recommend installing the following tools. (at the very least install jq to help with parsing JSON CLI output)

sudo apt-get update
sudo apt-get upgrade -y 
sudo apt-get install jq git build-essential unzip python3 python3-pip -y 

Install IBM Cloud CLI (WSL terminal)

Back in your WSL terminal

## WSL
curl -sL http://ibm.biz/idt-installer -o cli-installer.sh
chmod +x cli-installer.sh
./cli-installer.sh
sudo usermod -aG docker <your username>

Install IBM Cloud CLI in Powershell

If you want to run CLI commands within Powershell you will want to run the following commands:

## Powershell
[Net.ServicePointManager]::SecurityProtocol = "Tls12"; iex(New-Object Net.WebClient).DownloadString('https://ibm.biz/idt-win-installer')

IBM Cloud config and Plugins

We're now ready to start learning some IBM Cloud CLI commands

Sign in with --sso

We're going to sign in with SSO for our initial login

$ ibmcloud login --sso

Generate a CLI API Key

We will generate a CLI specific API key to use on the machine

$ ibmcloud iam api-key-create <name of key> -d "A description" --file ~/ibmcloud_api.json

Set as Env variable

So that we can simply login to the IBM Cloud CLI without having to go through the SSO dance everytime we will set the IBMCLOUD_API_KEY store the environmental variable for future use.

$ echo "export IBMCLOUD_API_KEY=\"$(cat ~/ibmcloud_api.json | jq -r .apikey)\"" | tee -a ~/.bashrc
$ source ~/.bashrc

Log out, back in and target a region

To make sure that our API key environmental variable is set properly we will log out and then back in:

$ ibmcloud logout
$ ibmcloud login -r us-south 

Do some simple commands

  • Show account details
$ ibmcloud account show 
  • List available plugins for the CLI
$ ibmcloud plugin repo-plugins
  • List Classic Servers in Dallas 13
$ ibmcloud sl hardware list -d dal13
  • Target a new region and list service-instances
$ ibmcloud target -r us-east
$ ibmcloud resource service-instances
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment