This tutorial shows you how to deploy this containerized app to Azure Web App for Containers using Azure App Service Plugin. Below are the major steps in this tutorial.
- Create Azure Container Registry
- Prepare Jenkins server
- Create job
- Build and Deploy Docker Container Image to Azure Web App for Containers
- Clean Up Resources
-
login your Azure CLI, and set your subscription id
az login az account set -s <your-subscription-id>
-
Run below command to create an Azure Container Registry. After creation, use
login server
as Container Registry URL in the next section.az acr create -n <your-registry-name> -g <your-resource-group-name> --sku <sku-name> --admin-enabled true
-
Run below command to show your Azure Container Registry credentials. You will use Docker registry username and password in the next section.
az acr credential show -n <your-registry-name>
-
Deploy a Jenkins Master on Azure
-
Connect to the server with SSH and install the build tools:
sudo apt-get install git maven docker.io
-
Install the plugins in Jenkins. Click 'Manage Jenkins' -> 'Manage Plugins' -> 'Available', then search and install the following plugins: EnvInject, Azure App Service Plugin.
-
Add a Credential in type "Microsoft Azure Service Principal" with your service principal.
-
Add a Credential in type "Username with password" with your account of docker registry.
-
Add a new job in type "Pipeline".
-
Enable "Prepare an environment for the run", and put the following environment variables in "Properties Content":
AZURE_CRED_ID=[your credential id of service principal] RES_GROUP=[your resource group of the web app] WEB_APP=[the name of the web app] ACR_SERVER=[your address of azure container registry] ACR_CRED_ID=[your credential id of ACR account] DOCUMENTDB_URI=[your documentdb uri] DOCUMENTDB_KEY=[your documentdb key] DOCUMENTDB_DBNAME=[your documentdb databasename]
-
Choose "Pipeline script from SCM" in "Pipeline" -> "Definition".
-
Fill in the SCM repo url and script path.
-
Verify you can run your project successfully in your local environment. (Run project on local machine)
-
Run jenkins job.
-
Navigate to the website from your favorite browser. You will see this app successfully running on Azure Web App for Containers.
Delete the Azure resources you just created by running below command:
az group delete -y --no-wait -n <your-resource-group-name>