fix resource deployment notebooks (#21096)

This commit is contained in:
Alan Ren
2022-11-03 13:12:07 -07:00
committed by GitHub
parent d268b9948b
commit 5f16251ca7
9 changed files with 312 additions and 224 deletions

View File

@@ -1,10 +1,33 @@
{
"metadata": {
"kernelspec": {
"name": "python3",
"display_name": "Python 3 (ipykernel)",
"language": "python"
},
"language_info": {
"name": "python",
"version": "3.8.10",
"mimetype": "text/x-python",
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"pygments_lexer": "ipython3",
"nbconvert_exporter": "python",
"file_extension": ".py"
},
"vscode": {
"interpreter": {
"hash": "878db934b706db2770cee331c11f15a67312cefb4f2334de757c7c9b6e34ef9f"
}
}
},
"nbformat_minor": 2,
"nbformat": 4,
"cells": [
{
"cell_type": "markdown",
"metadata": {
"azdata_cell_guid": "e5fb2be9-e904-4821-8473-b69b90760c6a"
},
"source": [
"![Microsoft](https://raw.githubusercontent.com/microsoft/azuredatastudio/main/extensions/resource-deployment/images/microsoft-small-logo.png)\n",
"## Run SQL Server 2022 Preview container image with Docker\n",
@@ -14,27 +37,22 @@
"- Docker Engine. For more information, see [Install Docker](https://docs.docker.com/engine/installation/).\n",
"\n",
"<span style=\"color:red\"><font size=\"3\">Please press the \"Run all\" button to run the notebook</font></span>"
]
],
"metadata": {
"azdata_cell_guid": "e5fb2be9-e904-4821-8473-b69b90760c6a"
}
},
{
"cell_type": "markdown",
"metadata": {
"azdata_cell_guid": "76c571ab-358a-4b07-810c-53020ee1745a"
},
"source": [
"### Check dependencies"
]
],
"metadata": {
"azdata_cell_guid": "76c571ab-358a-4b07-810c-53020ee1745a"
}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"azdata_cell_guid": "6196300e-f896-489b-8dca-b2c42eda2d6d",
"tags": [
"hide_input"
]
},
"outputs": [],
"source": [
"import sys,os,getpass,json,html,time\n",
"from string import Template\n",
@@ -48,52 +66,54 @@
"\n",
"cmd = 'docker version'\n",
"run_command()"
]
],
"metadata": {
"azdata_cell_guid": "6196300e-f896-489b-8dca-b2c42eda2d6d",
"tags": [
"hide_input"
],
"language": "python"
},
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"metadata": {
"azdata_cell_guid": "87b07614-d57d-4731-ac3e-a8b324d231f2"
},
"source": [
"### List existing containers\n",
"You can view the ports that have been used by existing containers"
]
],
"metadata": {
"azdata_cell_guid": "87b07614-d57d-4731-ac3e-a8b324d231f2"
}
},
{
"cell_type": "code",
"execution_count": null,
"source": [
"cmd = f'docker ps -a'\n",
"run_command()"
],
"metadata": {
"azdata_cell_guid": "26170d1b-4332-4383-bcc4-1d97030daffc",
"tags": [
"hide_input"
]
],
"language": "python"
},
"outputs": [],
"source": [
"cmd = f'docker ps -a'\n",
"run_command()"
]
"execution_count": null
},
{
"cell_type": "markdown",
"metadata": {
"azdata_cell_guid": "52b1faf2-d7c7-446b-ba0b-4f8b744da0bb"
},
"source": [
"### Required information"
]
],
"metadata": {
"azdata_cell_guid": "52b1faf2-d7c7-446b-ba0b-4f8b744da0bb"
}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"azdata_cell_guid": "93cb0147-7bf6-4630-b796-3811dfd1354b",
"tags": [
"hide_input"
]
},
"outputs": [],
"source": [
"env_var_flag = \"AZDATA_NB_VAR_DOCKER_PASSWORD\" in os.environ\n",
"password_name = 'SQL Server sa account password'\n",
@@ -110,51 +130,53 @@
" sql_port = '1433'\n",
"print(f'{password_name}: ******')\n",
"print(f'Port: {sql_port}')"
]
],
"metadata": {
"azdata_cell_guid": "93cb0147-7bf6-4630-b796-3811dfd1354b",
"tags": [
"hide_input"
],
"language": "python"
},
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"metadata": {
"azdata_cell_guid": "643ccaca-fd1d-4482-b81e-aee29b627e34"
},
"source": [
"### Pull the container image"
]
],
"metadata": {
"azdata_cell_guid": "643ccaca-fd1d-4482-b81e-aee29b627e34"
}
},
{
"cell_type": "code",
"execution_count": null,
"source": [
"cmd = f'docker pull mcr.microsoft.com/mssql/server:2022-latest'\n",
"run_command()"
],
"metadata": {
"azdata_cell_guid": "7b102447-3198-488f-a995-982ae1fc8555",
"tags": [
"hide_input"
]
],
"language": "python"
},
"outputs": [],
"source": [
"cmd = f'docker pull mcr.microsoft.com/mssql/server:2022-latest'\n",
"run_command()"
]
"execution_count": null
},
{
"cell_type": "markdown",
"metadata": {
"azdata_cell_guid": "a4527a5f-c2c5-4f60-bfd1-b119576178c5"
},
"source": [
"### Start a new container"
]
],
"metadata": {
"azdata_cell_guid": "a4527a5f-c2c5-4f60-bfd1-b119576178c5"
}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"azdata_cell_guid": "82f27460-88eb-4484-92ee-40305e650d70",
"tags": [
"hide_input"
]
},
"outputs": [],
"source": [
"if env_var_flag:\n",
" container_name = os.environ[\"AZDATA_NB_VAR_DOCKER_CONTAINER_NAME\"]\n",
@@ -165,111 +187,97 @@
"template = Template(f'docker run -e ACCEPT_EULA=Y -e \"SA_PASSWORD=$password\" -p {sql_port}:1433 --name {container_name} -d mcr.microsoft.com/mssql/server:2022-latest')\n",
"cmd = template.substitute(password=sql_password)\n",
"run_command(template.substitute(password='******'))"
]
],
"metadata": {
"azdata_cell_guid": "82f27460-88eb-4484-92ee-40305e650d70",
"tags": [
"hide_input"
],
"language": "python"
},
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"metadata": {
"azdata_cell_guid": "e267aa7d-dd22-43ac-9b03-cf282ef15f67"
},
"source": [
"### List all the containers"
]
],
"metadata": {
"azdata_cell_guid": "e267aa7d-dd22-43ac-9b03-cf282ef15f67"
}
},
{
"cell_type": "code",
"execution_count": null,
"source": [
"cmd = f'docker ps -a'\n",
"run_command()"
],
"metadata": {
"azdata_cell_guid": "211ee198-f1d1-4781-9daa-8497c2665de6",
"tags": [
"hide_input"
]
],
"language": "python"
},
"outputs": [],
"source": [
"cmd = f'docker ps -a'\n",
"run_command()"
]
"execution_count": null
},
{
"cell_type": "markdown",
"metadata": {
"azdata_cell_guid": "5f5860c4-7962-439e-a15b-7f24f504dc18"
},
"source": [
"### Connect to SQL Server in Azure Data Studio\n",
"It might take a couple minutes for SQL Server to launch"
]
],
"metadata": {
"azdata_cell_guid": "5f5860c4-7962-439e-a15b-7f24f504dc18"
}
},
{
"cell_type": "code",
"execution_count": null,
"source": [
"from IPython.display import *\n",
"connectionParameter = '{\"serverName\":\"localhost,' + sql_port + '\",\"providerName\":\"MSSQL\",\"authenticationType\":\"SqlLogin\",\"userName\":\"sa\",\"password\":' + json.dumps(sql_password) + ',\"options\": {\"trustServerCertificate\":true}}'\n",
"display(HTML('<br/><a href=\"command:azdata.connect?' + html.escape(connectionParameter)+'\"><font size=\"3\">Click here to connect to SQL Server</font></a><br/>'))\n",
"display(HTML('<br/><span style=\"color:red\"><font size=\"2\">NOTE: The SQL Server password is included in this link, you may want to clear the results of this code cell before saving the notebook.</font></span>'))"
],
"metadata": {
"azdata_cell_guid": "4bc64915-c5ae-4507-8fb0-9e413ccc2fd0",
"tags": [
"hide_input"
]
],
"language": "python"
},
"outputs": [],
"source": [
"from IPython.display import *\n",
"connectionParameter = '{\"serverName\":\"localhost,' + sql_port + '\",\"providerName\":\"MSSQL\",\"authenticationType\":\"SqlLogin\",\"userName\":\"sa\",\"password\":' + json.dumps(sql_password) + '}'\n",
"display(HTML('<br/><a href=\"command:azdata.connect?' + html.escape(connectionParameter)+'\"><font size=\"3\">Click here to connect to SQL Server</font></a><br/>'))\n",
"display(HTML('<br/><span style=\"color:red\"><font size=\"2\">NOTE: The SQL Server password is included in this link, you may want to clear the results of this code cell before saving the notebook.</font></span>'))"
]
"execution_count": null
},
{
"cell_type": "markdown",
"metadata": {
"azdata_cell_guid": "9a1039fa-fdd3-408b-b649-8fde0fcee660"
},
"source": [
"### Stop and remove the container"
]
],
"metadata": {
"azdata_cell_guid": "9a1039fa-fdd3-408b-b649-8fde0fcee660"
}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"azdata_cell_guid": "f9e0f1ad-ba6e-4c17-84ea-cc5dceb1289b",
"tags": [
"hide_input"
]
},
"outputs": [],
"source": [
"stop_container_command = f'docker stop {container_name}'\n",
"remove_container_command = f'docker rm {container_name}'\n",
"display(HTML(\"Use this link to: <a href=\\\"command:workbench.action.terminal.focus\\\">open the terminal window in Azure Data Studio</a> and use the links below to paste the command to the terminal.\"))\n",
"display(HTML(\"Stop the container: <a href=\\\"command:workbench.action.terminal.sendSequence?%7B%22text%22%3A%22\"+stop_container_command.replace(\" \",\"%20\")+\"%22%7D\\\">\" + stop_container_command + \"</a>\"))\n",
"display(HTML(\"Remove the container: <a href=\\\"command:workbench.action.terminal.sendSequence?%7B%22text%22%3A%22\"+remove_container_command.replace(\" \",\"%20\")+\"%22%7D\\\">\" + remove_container_command + \"</a>\"))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.10.1 64-bit",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
],
"metadata": {
"azdata_cell_guid": "f9e0f1ad-ba6e-4c17-84ea-cc5dceb1289b",
"tags": [
"hide_input"
],
"language": "python"
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.1"
},
"vscode": {
"interpreter": {
"hash": "878db934b706db2770cee331c11f15a67312cefb4f2334de757c7c9b6e34ef9f"
}
"outputs": [],
"execution_count": null
}
},
"nbformat": 4,
"nbformat_minor": 2
}
]
}