Skip to content

Commit

Permalink
Drive Rapid PowerShell Adoption Using Jupyter Notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Soule committed May 4, 2023
1 parent 2c610c5 commit dc69223
Show file tree
Hide file tree
Showing 13 changed files with 1,622 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Michael-Soule-Jupyter-Notebooks/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM jupyter/base-notebook:lab-3.6.3
USER root
RUN wget https://packages.microsoft.com/config/ubuntu/22.10/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
RUN dpkg -i packages-microsoft-prod.deb
RUN rm packages-microsoft-prod.deb
RUN apt-get update -y
RUN apt-get install -y dotnet-sdk-7.0
COPY ./workingWithO365.ipynb ${HOME}
USER root
RUN chown -R 1000 ${HOME}
USER jovyan
RUN dotnet tool install -g Microsoft.dotnet-interactive
ENV PATH="${PATH}:${HOME}/.dotnet/tools"
RUN dotnet interactive jupyter install
56 changes: 56 additions & 0 deletions Michael-Soule-Jupyter-Notebooks/Notes-demo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
winget install --id Microsoft.VisualStudioCode
winget install --id Microsoft.DotNet.SDK.7 --log C:\temp\dotnet.log
winget install --id Microsoft.PowerShell

# New Terminal Session for PWSH
$psversionTable
& code

# Install PolyGlot Extension in VSCode
# New Jupyter Notebook for PowerShell
$psversionTable

iwr https://raw.githubusercontent.com/Snozzberries/jupyterDemo/main/workingWithO365.ipynb -OutFile .\workingWithO365.ipynb
code .\workingWithO365.ipynb

# Show basic navigations
# Show Mermaid

# Start basics
# Get email and show email in Outlook
# Send Teams message and show Teams

# Start complex
# Send Teams message and show Teams

# Start JupyterHub
# Show automatic server launch
# Show ECS task
$psversionTable
iwr https://raw.githubusercontent.com/Snozzberries/jupyterDemo/main/workingWithO365.ipynb -OutFile .\workingWithO365.ipynb
# Refresh dir viewer
# Open file
# Run Mermaid
# change Kernel
# Run through Connecting to the graph
# Connect-MgGraph -ContextScope Process
# Add a code cell and show Get-MgContext

## In JupyterLab
iwr https://raw.githubusercontent.com/Snozzberries/jupyterDemo/main/powerBi.ipynb -OutFile .\powerBi.ipynb

# Hub > Home > Token
# Create new token
# New notebook in VSCode
# Change Kernel to existing server
# https://jupyter.soule.aws.sentinel.com/user/allen%20deyoung?token=
## In VSCode
gci
## In Browser
gci
"" > ./test.txt
## In VSCode
gci

## In VSCode
.\PowerShellAI.ipynb
79 changes: 79 additions & 0 deletions Michael-Soule-Jupyter-Notebooks/PowerShellAI.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Prepare the Kernel with specific functions and setup the API key"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"dotnet_interactive": {
"language": "pwsh"
},
"polyglot_notebook": {
"kernelName": "pwsh"
}
},
"outputs": [],
"source": [
"Import-Module C:\\Users\\Mike\\OneDrive\\Documents\\PowerShell\\Modules\\PowerShellAI\\0.6.1\\Public\\NotebookCopilot.ps1\n",
"Set-OpenAIKey -Key (Get-Secret -Name PowerShellAI)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Request the PowerShell function and place within a new code cell"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"dotnet_interactive": {
"language": "pwsh"
},
"polyglot_notebook": {
"kernelName": "pwsh"
}
},
"outputs": [],
"source": [
"$return = ai \"Write FizzBuzz in the fewest number of characters possible using PowerShell\"\n",
"$return = $return -replace '```powershell', '' -replace '```', ''\n",
"$return | New-NBCell -cellType pwsh"
]
}
],
"metadata": {
"kernelspec": {
"display_name": ".NET (C#)",
"language": "C#",
"name": ".net-csharp"
},
"language_info": {
"name": "polyglot-notebook"
},
"orig_nbformat": 4,
"polyglot_notebook": {
"kernelInfo": {
"defaultKernelName": "csharp",
"items": [
{
"aliases": [],
"name": "csharp"
}
]
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Binary file not shown.
50 changes: 50 additions & 0 deletions Michael-Soule-Jupyter-Notebooks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# jupyterDemo
Content associated with PowerShell + DevOps Global Summit 2022 session Drive Rapid PowerShell Adoption Using Jupyter Notebooks

[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/Snozzberries/jupyterDemo/HEAD)

[Main Repo](https://github.com/Snozzberries/jupyterDemo)

--------------

![](https://github.com/Snozzberries/jupyterDemo/blob/main/demo.gif)

## Docker Images

### jupyterhub

Provides JupyterHub image with integration to Azure AD through OAuthenticator and the Fargate Spawner

> Update the Fargate, Secrets Manager, Service URL, and Azure AD App Registration configurations
### dotnet

Provides JupyterNotebook image with integration for dotnet interactive

> Update the dotnet SDK version if applicable
### Dockerfile

At the root of the repo is a Dockerfile copy of the dotnet image. This is to build a custom image for use with Binder specifically.

> When you launch with Binder ensure you select the PowerShell Kernel when the JupyterLab instance is started
## example.cfn.yml

The cfn template profiles an example of the resources and integrations necessary for Route 53 to manage DNS, Elastic Loadbalancer to handle the inbound client traffic with a certificate from Certificate Manager, with the target group using the Elastic Container Service Fargate Service for the JupyterHub image from Elastic Container Registry (ECR), loading the Azure AD App secret from Secrets Manager, and able to spawn JupyterNotebook tasks from the dotnet image in ECR

> This will NOT work as is, treat this as a reference only
## Notes

### Notes-demo.txt

Provides an outline of the different steps shown during the demo

### notes.sh

Provides basic steps in creating the environment

## workingWithO365.ipynb

Provides the notebook used during the demo
Binary file added Michael-Soule-Jupyter-Notebooks/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions Michael-Soule-Jupyter-Notebooks/dotnet/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM jupyter/base-notebook:latest
USER root
RUN wget https://packages.microsoft.com/config/ubuntu/22.10/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
RUN dpkg -i packages-microsoft-prod.deb
RUN rm packages-microsoft-prod.deb
RUN apt-get update -y
RUN apt-get install -y dotnet-sdk-7.0
USER jovyan
RUN dotnet tool install -g Microsoft.dotnet-interactive
ENV PATH="${PATH}:${HOME}/.dotnet/tools"
RUN dotnet interactive jupyter install
Loading

0 comments on commit dc69223

Please sign in to comment.