diff --git a/scenarios/ocd/CreateLinuxVMAndSSH/README.md b/scenarios/ocd/CreateLinuxVMAndSSH/README.md index 20fc414b..73f4dc2f 100644 --- a/scenarios/ocd/CreateLinuxVMAndSSH/README.md +++ b/scenarios/ocd/CreateLinuxVMAndSSH/README.md @@ -1,120 +1,120 @@ -# Create a Linux VM and SSH On Azure - -## Define Environment Variables - -The First step in this tutorial is to define environment variables. - -```bash -export RANDOM_ID="$(openssl rand -hex 3)" -export MY_RESOURCE_GROUP_NAME="myVMResourceGroup$RANDOM_ID" -export REGION=EastUS -export MY_VM_NAME="myVM$RANDOM_ID" -export MY_USERNAME=azureuser -export MY_VM_IMAGE="Canonical:0001-com-ubuntu-minimal-jammy:minimal-22_04-lts-gen2:latest" -``` - -# Login to Azure using the CLI - -In order to run commands against Azure using the CLI you need to login. This is done, very simply, though the `az login` command: - -# Create a resource group - -A resource group is a container for related resources. All resources must be placed in a resource group. We will create one for this tutorial. The following command creates a resource group with the previously defined $MY_RESOURCE_GROUP_NAME and $REGION parameters. - -```bash -az group create --name $MY_RESOURCE_GROUP_NAME --location $REGION -``` - -Results: - - -```json -{ - "id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myVMResourceGroup", - "location": "eastus", - "managedBy": null, - "name": "myVMResourceGroup", - "properties": { - "provisioningState": "Succeeded" - }, - "tags": null, - "type": "Microsoft.Resources/resourceGroups" -} -``` - -## Create the Virtual Machine - -To create a VM in this resource group we need to run a simple command, here we have provided the `--generate-ssh-keys` flag, this will cause the CLI to look for an avialable ssh key in `~/.ssh`, if one is found it will be used, otherwise one will be generated and stored in `~/.ssh`. We also provide the `--public-ip-sku Standard` flag to ensure that the machine is accessible via a public IP. Finally, we are deploying the latest `Ubuntu 22.04` image. - -All other values are configured using environment variables. - -```bash -az vm create \ - --resource-group $MY_RESOURCE_GROUP_NAME \ - --name $MY_VM_NAME \ - --image $MY_VM_IMAGE \ - --admin-username $MY_USERNAME \ - --assign-identity \ - --generate-ssh-keys \ - --public-ip-sku Standard -``` - -Results: - - -```json -{ - "fqdns": "", - "id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myVMResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM", - "location": "eastus", - "macAddress": "00-0D-3A-10-4F-70", - "powerState": "VM running", - "privateIpAddress": "10.0.0.4", - "publicIpAddress": "52.147.208.85", - "resourceGroup": "myVMResourceGroup", - "zones": "" -} -``` - -### Enable Azure AD login for a Linux Virtual Machine in Azure - -The following example has deploys a Linux VM and then installs the extension to enable Azure AD login for a Linux VM. VM extensions are small applications that provide post-deployment configuration and automation tasks on Azure virtual machines. - -```bash -az vm extension set \ - --publisher Microsoft.Azure.ActiveDirectory \ - --name AADSSHLoginForLinux \ - --resource-group $MY_RESOURCE_GROUP_NAME \ - --vm-name $MY_VM_NAME -``` - -# Store IP Address of VM in order to SSH -run the following command to get the IP Address of the VM and store it as an environment variable - -```bash -export IP_ADDRESS=$(az vm show --show-details --resource-group $MY_RESOURCE_GROUP_NAME --name $MY_VM_NAME --query publicIps --output tsv) -``` - -# SSH Into VM - - - - - -You can now SSH into the VM by running the output of the following command in your ssh client of choice - -```bash -ssh -o StrictHostKeyChecking=no $MY_USERNAME@$IP_ADDRESS -``` - -# Next Steps - -* [VM Documentation](https://learn.microsoft.com/en-us/azure/virtual-machines/) -* [Use Cloud-Init to initialize a Linux VM on first boot](https://learn.microsoft.com/en-us/azure/virtual-machines/linux/tutorial-automate-vm-deployment) -* [Create custom VM images](https://learn.microsoft.com/en-us/azure/virtual-machines/linux/tutorial-custom-images) -* [Load Balance VMs](https://learn.microsoft.com/en-us/azure/load-balancer/quickstart-load-balancer-standard-public-cli) +# Create a Linux VM and SSH On Azure + +## Define Environment Variables + +The First step in this tutorial is to define environment variables. + +```bash +export RANDOM_ID="$(openssl rand -hex 3)" +export MY_RESOURCE_GROUP_NAME="myVMResourceGroup$RANDOM_ID" +export REGION=EastUS +export MY_VM_NAME="myVM$RANDOM_ID" +export MY_USERNAME=azureuser +export MY_VM_IMAGE="Canonical:0001-com-ubuntu-minimal-jammy:minimal-22_04-lts-gen2:latest" +``` + +# Login to Azure using the CLI + +In order to run commands against Azure using the CLI you need to login. This is done, very simply, though the `az login` command: + +# Create a resource group + +A resource group is a container for related resources. All resources must be placed in a resource group. We will create one for this tutorial. The following command creates a resource group with the previously defined $MY_RESOURCE_GROUP_NAME and $REGION parameters. + +```bash +az group create --name $MY_RESOURCE_GROUP_NAME --location $REGION +``` + +Results: + + +```json +{ + "id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myVMResourceGroup", + "location": "eastus", + "managedBy": null, + "name": "myVMResourceGroup", + "properties": { + "provisioningState": "Succeeded" + }, + "tags": null, + "type": "Microsoft.Resources/resourceGroups" +} +``` + +## Create the Virtual Machine + +To create a VM in this resource group we need to run a simple command, here we have provided the `--generate-ssh-keys` flag, this will cause the CLI to look for an avialable ssh key in `~/.ssh`, if one is found it will be used, otherwise one will be generated and stored in `~/.ssh`. We also provide the `--public-ip-sku Standard` flag to ensure that the machine is accessible via a public IP. Finally, we are deploying the latest `Ubuntu 22.04` image. + +All other values are configured using environment variables. + +```bash +az vm create \ + --resource-group $MY_RESOURCE_GROUP_NAME \ + --name $MY_VM_NAME \ + --image $MY_VM_IMAGE \ + --admin-username $MY_USERNAME \ + --assign-identity \ + --generate-ssh-keys \ + --public-ip-sku Standard +``` + +Results: + + +```json +{ + "fqdns": "", + "id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myVMResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM", + "location": "eastus", + "macAddress": "00-0D-3A-10-4F-70", + "powerState": "VM running", + "privateIpAddress": "10.0.0.4", + "publicIpAddress": "52.147.208.85", + "resourceGroup": "myVMResourceGroup", + "zones": "" +} +``` + +### Enable Azure AD login for a Linux Virtual Machine in Azure + +The following example has deploys a Linux VM and then installs the extension to enable Azure AD login for a Linux VM. VM extensions are small applications that provide post-deployment configuration and automation tasks on Azure virtual machines. + +```bash +az vm extension set \ + --publisher Microsoft.Azure.ActiveDirectory \ + --name AADSSHLoginForLinux \ + --resource-group $MY_RESOURCE_GROUP_NAME \ + --vm-name $MY_VM_NAME +``` + +# Store IP Address of VM in order to SSH +run the following command to get the IP Address of the VM and store it as an environment variable + +```bash +export IP_ADDRESS=$(az vm show --show-details --resource-group $MY_RESOURCE_GROUP_NAME --name $MY_VM_NAME --query publicIps --output tsv) +``` + +# SSH Into VM + + + + + +You can now SSH into the VM by running the output of the following command in your ssh client of choice + +```bash +ssh -o StrictHostKeyChecking=no $MY_USERNAME@$IP_ADDRESS +``` + +# Next Steps + +* [VM Documentation](https://learn.microsoft.com/en-us/azure/virtual-machines/) +* [Use Cloud-Init to initialize a Linux VM on first boot](https://learn.microsoft.com/en-us/azure/virtual-machines/linux/tutorial-automate-vm-deployment) +* [Create custom VM images](https://learn.microsoft.com/en-us/azure/virtual-machines/linux/tutorial-custom-images) +* [Load Balance VMs](https://learn.microsoft.com/en-us/azure/load-balancer/quickstart-load-balancer-standard-public-cli) \ No newline at end of file diff --git a/scenarios/ocd/CreateStaticWebApp/README.md b/scenarios/ocd/CreateStaticWebApp/README.md new file mode 100644 index 00000000..6030270b --- /dev/null +++ b/scenarios/ocd/CreateStaticWebApp/README.md @@ -0,0 +1,134 @@ +# Azure Static Web Apps Quickstart: Building Your First Static Site Using the Azure CLI + +Azure Static Web Apps publishes websites to production by building apps from a code repository. In this quickstart, you deploy a web application to Azure Static Web Apps using the Azure CLI. + +## Define Environment Variables + +The First step in this tutorial is to define environment variables. + +```bash +export RANDOM_ID="$(openssl rand -hex 3)" +export MY_RESOURCE_GROUP_NAME="myStaticWebAppResourceGroup$RANDOM_ID" +export REGION=EastUS2 +export MY_STATIC_WEB_APP_NAME="myStaticWebApp$RANDOM_ID" +``` + +## Create a Repository (optional) + +(Optional) This article uses a GitHub template repository as another way to make it easy for you to get started. The template features a starter app to deploy to Azure Static Web Apps. + +- Navigate to the following location to create a new repository: https://github.com/staticwebdev/vanilla-basic/generate +- Name your repository `my-first-static-web-app` + +> **Note:** Azure Static Web Apps requires at least one HTML file to create a web app. The repository you create in this step includes a single `index.html` file. + +Select `Create repository`. + +## Deploy a Static Web App + +You can deploy the app as a static web app from the Azure CLI. + +1. Create a resource group. + +```bash +az group create \ + --name $MY_RESOURCE_GROUP_NAME \ + --location $REGION +``` + +Results: + + +```json +{ + "id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/my-swa-group", + "location": "eastus2", + "managedBy": null, + "name": "my-swa-group", + "properties": { + "provisioningState": "Succeeded" + }, + "tags": null, + "type": "Microsoft.Resources/resourceGroups" +} +``` + +2. Deploy a new static web app from your repository. + +```bash +az staticwebapp create \ + --name $MY_STATIC_WEB_APP_NAME \ + --resource-group $MY_RESOURCE_GROUP_NAME \ + --location $REGION +``` + +There are two aspects to deploying a static app. The first operation creates the underlying Azure resources that make up your app. The second is a workflow that builds and publishes your application. + +Before you can go to your new static site, the deployment build must first finish running. + +3. Return to your console window and run the following command to list the website's URL. + +```bash +export MY_STATIC_WEB_APP_URL=$(az staticwebapp show --name $MY_STATIC_WEB_APP_NAME --resource-group $MY_RESOURCE_GROUP_NAME --query "defaultHostname" -o tsv) +``` + +```bash +runtime="1 minute"; +endtime=$(date -ud "$runtime" +%s); +while [[ $(date -u +%s) -le $endtime ]]; do + if curl -I -s $MY_STATIC_WEB_APP_URL > /dev/null ; then + curl -L -s $MY_STATIC_WEB_APP_URL 2> /dev/null | head -n 9 + break + else + sleep 10 + fi; +done +``` + +Results: + + +```HTML + + +
+ + + +