This course will guide you through scaling cloud applications using Docker and Azure services, with a focus on Bicep deployments. Below are detailed instructions for cloning the course code, setting up your local environment, configuring and integrating accounts, and deploying infrastructure and applications.
-
Microsoft Visual Studio Code (VS Code)
- Download and install from: https://code.visualstudio.com/
- Install helpful extensions: Docker and Git.
-
Git (if that is not already on your computer)
- Download and install from: https://git-scm.com/
- Configure Git with your name and email:
git config --global user.name "Your Name" git config --global user.email "[email protected]"
- Verify Git installation:
git --version
-
GitHub Account
- Sign up: https://github.com/join
- Configure ssh access to GitHub by following this instruction
-
Fork the course Repository into your GitHub Account
- Go to the course reporitory
- Select "Fork" to create your own disconnected version of the course code repository
- Name the repository "scalecloud" click on "Create fork"
-
Download the repository localy
- Go to the newly created repo in your github account and click on the green "<>Code" button. Copy the SSH URL and open a comand shell on your computer. Paste in this command to create a local repository (connected to the github repository)
git clone [email protected]:<your-username>/scalecloud.git
- Replace
<your-username>
with your GitHub username. - Change directory into the repo:
cd scalecloud
- Verify the repo with the command
You sould see something like:
git remove -v
origin [email protected]:<your usernam>/scalingcloud.git (push)
- Go to the newly created repo in your github account and click on the green "<>Code" button. Copy the SSH URL and open a comand shell on your computer. Paste in this command to create a local repository (connected to the github repository)
-
Docker (requires local admin)
- Download and install from: https://www.docker.com/products/docker-desktop
- Ensure Docker is running and verify installation:
docker --version
-
DockerHub
- Login or sign up for a DockerHub account at https://hub.docker.com/
-
Open the code in VS Code
- Start VS Code and open the directory by selecting "Open folder..." from the File meny
This part explores some of the avaliable tools to build, deploy and monitor applications in Azure. There are a few things required to be setup to be able to run the labs.
-
Azure Account
- Sign up: https://azure.microsoft.com/free/
- Ensure your subscription is active (you should be able to create a free tier subscriptioin)
-
(Optional) Azure CLI
- Install from: https://docs.microsoft.com/en-us/cli/azure/install-azure-cli
- Log in to your Azure account:
az login
-
(Optional) Bicep CLI
- Install Bicep using Azure CLI:
az bicep install
- Verify Bicep installation:
az bicep version
- Install Bicep using Azure CLI:
You need to configure the following GitHub Secrets in your repository for secure deployment. These secrets are referenced in the actions workflows and in bicep files.
- Go to your repository's Settings.
- Navigate to Secrets and variables > Actions.
- Add the following secrets:
AZURE_SUBSCRIPTION_ID
: Your Azure subscription ID.AZURE_RESOURCE_GROUP
: Provide a suitable name of the resource groups that will be created and used for the labs.DOCKERHUB_PASSWORD
: Your password to dockerhub.com (used for rebuilding and pushing a new version ofmy-website
)DOCKERHUB_IMAGE
: The name of your image that ws pushed to dockerhub.com in lab1. It will be used as input into the bicep file that sets up the labs in azure.
To deploy Azure resources using GitHub Actions, you need to create and configure Azure credentials securely in your GitHub repository. We need to create a service principal (server account) in Azure and give to GitHub to allow access from GitHub Actions into Azure. Here's how to do it:
-
Create a Service Principal
- Run the following command to create a new service principal and capture the output, which includes your
appId
,password
, andtenant
:az account show --query id --output tsv az ad sp create-for-rbac --name "github-actions-deploy" --role contributor --scopes /subscriptions/<AZURE_SUBSCRIPTION_ID> --sdk-auth
- Replace
<AZURE_SUBSCRIPTION_ID>
with your actual Azure subscription ID from the first command. (You can also find the subscription ID in the portal) - The output will look like this:
{ "appId": "YOUR_APP_ID", "displayName": "github-actions-deploy", "password": "YOUR_PASSWORD", "tenant": "YOUR_TENANT_ID" }
- Run the following command to create a new service principal and capture the output, which includes your
-
Store Azure Credentials in GitHub Secrets
- Go to your GitHub repository and navigate to Settings.
- Under Secrets and variables, click on Actions.
- Click New repository secret and add a secret named
AZURE_CREDENTIALS
. - Past in the JSON ouput from step 2 so that
AZURE_CREDENTIALS
secret is a JSON string containing your credentials.
The GitHub Actions workflow .github/workflows/lab-bicep-deploy.yml
is designed to deploy Azure resources using Bicep files located in specific directories for Labs 3, 4, and 5. It allows you to specify which lab's Bicep file to deploy using manual workflow dispatch.
This allows you to trigger the workflow and provide an input specifying the lab number (labPath
), which points to the directory where the Bicep file is located. By default, it deploys the Bicep file for lab3
.
AZURE_SUBSCRIPTION_ID
: Retrieved from GitHub Secrets and used to identify your Azure subscription.AZURE_CREDENTIALS
RESOURCE_GROUP
: The name of the Azure resource group, dynamically constructed using the lab path input. It appends the lab number to the base resource group name.LOCATION
: Set toswedencentral
, which is the default location for all resources.
The workflow contains a single job, deploy
, that runs on an ubuntu-latest
virtual environment and executes the following steps:
-
Checkout Repository
- Action:
actions/checkout@v2
This step checks out the code from the repository, making the Bicep files available for deployment.
- Action:
-
Log in to Azure
- Action:
azure/login@v1
This step logs into your Azure account using the credentials stored in GitHub Secrets (AZURE_CREDENTIALS
). This is necessary to authenticate and interact with Azure resources.
- Action:
-
Ensure the Resource Group Exists
- Command:
az group create --name ${{ env.RESOURCE_GROUP }} --location ${{ env.LOCATION }} --subscription ${{ secrets.AZURE_SUBSCRIPTION_ID }} --tags Project=scalingCloudLab
- Description: This command creates the resource group if it does not already exist. It uses the
RESOURCE_GROUP
environment variable, which incorporates the lab path, and assigns a tagProject=scalingCloudLab
to the resource group.
- Command:
-
Deploy Bicep File for the Specified Lab
- Command:
az deployment group create --resource-group ${{ env.RESOURCE_GROUP }} --subscription ${{ secrets.AZURE_SUBSCRIPTION_ID }} --template-file ${{ github.event.inputs.labPath }}/lab.bicep --mode Incremental
- Description: This command deploys the Bicep file for the specified lab. It uses the
az deployment group create
command to deploy the infrastructure defined in thelab.bicep
file located in the directory specified by thelabPath
input. The--mode Incremental
flag ensures that existing resources are not deleted and only new or updated resources are deployed.
- Command:
-
Trigger the Workflow Manually:
- Navigate to the Actions tab in your GitHub repository.
- Select the Lab Bicep Deployment workflow.
- Click on Run workflow and specify the
labPath
input (e.g.,lab3
,lab4
, orlab5
) to choose which lab's Bicep file to deploy.
-
Bicep Deployment:
- The workflow will create or update the Azure resource group and then deploy the infrastructure using the appropriate Bicep file.
- Resource Group Naming: The resource group name is constructed dynamically, combining a base name with the lab number. This helps in organizing resources by lab.
- Incremental Deployment: The
--mode Incremental
flag ensures that only changes are applied, preventing the deletion of existing resources.
This workflow provides a structured and automated way to manage Azure deployments for multiple labs, making it easy to set up and scale cloud infrastructure.
You can deploy the test web application by:
- Pushing a Change: Any change in the repository (e.g., code or configuration updates) will automatically trigger the deployment workflow.
- Manually Triggering: Use the
webapp-workflow
in GitHub Actions to manually deploy the web app.
This will build and deploy the web application to your Azure environment.
To remove all resources and delete the resource groups created in the labs. They all have the tag: Project=scalingCloudLab
There are two ways to delete all of them.
- Go to the "action" tab in your GitHub account and select the
Lab bicep deployment
workflow to the left, click on "Run workflow", this will start a workflow that thoes the same thing as described below: - If you have Azure CLI and is loggedin to your subscription run this command in a terminal:
az group list --tag Project=scalingCloudLab --query "[].name" -o tsv | xargs -I {} az group delete --name {} --yes --no-wait