Continuous Delivery with Gitlab and Azure App Services

Continious Delivery from Gitlab and Azure App Service

In this post, we will discuss how to set up a continuous delivery pipeline for an application using GitLab and Azure App Service. Azure App Service is a fully managed Platform as a Service (PaaS) that enables you to build, deploy, and scale web, mobile, and API applications quickly and easily. By combining the power of GitLab and Azure, you can easily automate the build, test, and deployment of your application, saving you time and effort. Using GitLab CD to deploy code to an Azure App Service can improve the reliability, efficiency, and quality of your deployment process. In this post, we will walk you through the steps to set up a continuous delivery pipeline using GitLab and Azure, so you can get your application up and running in no time.

Create Azure App Service

  1. Open the Azure Portal (https://portal.azure.com).
  2. Navigate to App Services using the search bar.
  3. Click on Create.
  4. Select a subscription.
  5. Enter a name for a new resource group, or select Use existing and select one from the dropdown list.
  6. Enter a name for the app.
  7. Choose code as publish setting.
  8. For Publish, Runtime stack, and Operating System, make your selections as appropriate.
  9. For Region, select a region.
  10. Select an existing App Service plan, or create a new one.
  11. Select Next: Deployment.
  12. Select Next: Networking.
  13. Select Next: Monitoring. If you want to enable Application Insights with your: create a new Application Insights using the creation flow.
  14. Choose an existing Application Insights.
  15. Select Next: Tags, and add any tags you want to the app.
  16. Select Review + create. Make sure that the information is correct, and then select Create.

That's it! You should now have an Azure App Service set up.

Deploy multi project solutions (optional)

When a solution includes multiple projects you must specify the app setting PROJECT in Azure App Service to select the project to deploy.

  1. Go to the deployed App Service resource.
  2. In de menu click on Configuration.
  3. Click on New application setting .
  4. Set the name of the application setting "PROJECT".
  5. In the value field provide the relative path to the project file solution/project.csproj.
  6. Click on Save.

Configure the pipeline (deployment center)

Deployment Center configures an Azure DevOps pipeline to deploy the application (updates)

  1. Go to the repository in Gitlab.
  2. Click on Clone.
  3. And copy the URL under Clone with HTTPS.
  4. Open de App Service resource in Azure Portal.
  5. Select Deployment Center.
  6. Select External Git as source.
  7. For Repository paste the URL from clipboard.
  8. Select the appropriate branch.
  9. Select Private as Repository Type.
  10. Provide the username and password.
  11. Click on Save.
  12. Wait for the deployment to finish.
  13. Select Sync and acknowledge to perform the redeploy.

Configure deploy key

In this step you must get the SSH key for the Azure App and add the key to GitLab to grand read/write access to the repository.

  1. In the App Service resource.
  2. Go to Advanced Tools in the menu.
  3. Click on Go ->.
  4. Add /api/sshkey?ensurePublicKey=1 to the URL to obtain the SSH-key. The URL will be like: https://<app-name>.scm.azurewebsites.net/api/sshkey?ensurePublicKey=1
  5. Copy the SSH-key without the quotes.
  6. Select the repository in GitLab.
  7. Go to Settings -> Repository page and find the Deploy Keys area.
  8. Fill Title and Key as appropriate. In Key field you must paste the SSH-key.

Automated deployment

If the repository is updated in Gitlab, the application in the Azure App Service resource isn’t updated. Using Webhook it is possible to inform Kudo that there is a new push to the repository, which will then pull the new files.

Retrieve the userPWD

  1. Open de App Service resource in Azure Portal.
  2. Select Deployment Center.
  3. Select Manage publish profile.
  4. Select Download publish profile.
  5. Obtain the userPWD from the publish profile file.
  6. Construct the correct deployment trigger URL: https://$<app-name>:<password>@<app-name>.scm.azurewebsites.net/deploy

Configure the WebHook in GitLab

  1. Open the repository in GitLab and navigate to the Settings -> Webhooks page.
  2. Enter the Deployment Trigger URL into the URL field.
  3. Make sure that the Push events checkbox is checked.
  4. Provide the branch name.
  5. Make sure the Enable SSL verification is checked.