Adding CD to your Azure Container App

In one of my previous articles, we set up an Azure Container App with a small web API in Go. In this article I will discuss adding CD to your App. That mean that you can deploy directly from Github without having to go through building a Docker image, pushing it, and then pulling it again in your app.

In order to follow along, it is necessary that you built and configured the App as detailed in this article.

Set up Managed Identity

In order to set up access rights correctly we need to set up Managed Identiy. To do that, go to the Azure Container App we created in our previous article:

On this screen, click the ‘Identity’ item in the left pane:

Set the status to ‘On’ and click ‘Save’ After a while you will be presented with this screen:

That is it, now we can start setting up our github repository.

Setting up Git

First log in to Github, you will see the following screen:

Click on the ‘New’ button and you will see the following screen:

Do the following:

  1. Enter ‘rusttutrepos’ in the Name field.
  2. Make it Private. You can of course make it public but then anyone can see it, this might not be what you want at this moment.

After filling all of this in, click on ‘Create repository’ and you will be presented with the following screen detailing the next steps.

Let’s go through them, one by one. Make sure you are in a terminal and in the same directory as the Rust project. Now type the following:

cargo clean
git init
git add *
git status

This will clean your build directory, initialize a local git repository, add the files and show you which files will be committed.

Now type:

git commit -m 'first commit'

This will do a local commit, now switch to the main branch:

git branch -m main

And add the remote:

git remote add origin https://github.com/<your githubusername>/rusttutrepos.git

Now we can push the code to the server:

git push -u origin main

Now if you click on the Code tab in the top left of the screen, you will see a screen like this:

Congratulations! We have set up Git for our repository. The next step is to integrate this with our Azure Container App.

Integration with the Azure Container App

Go back into Azure and into our Azure Container App:

Now in the left pane, click on ‘Continuous Deployment’:

Enter the following:

  1. Make sure you are signed in with the right credentials. If not you can change them here.
  2. Choose the right organization, usually this equals your github username.
  3. The repository is ‘rusttutrepos’ and the branch ‘main’
  4. Choose ‘Docker Hub or other registries’
  5. The image name is ‘rusttut’
  6. Login server URL is docker.io
  7. Enter your docker hub username.
  8. Enter your docker hub password. The password will become a github pipeline secret and will never be visible in any code.
  9. Leave the Dockerfile location empty, it will find it automatically.

It should look something like this:

Now click on ‘Start continuous deployment’

Once you have done that, go back to github and click on the actions tab. You will see a pipeline action has been started:

When the pipeline has finished, and that can take quite a while, go to you dockerhub and look in your rusttut repository:

You will see a new tag appear, with the sha of th git build.

Now go back to your rusttut container app in the Azure portal and click ‘Revision Management’ in the left pane, and you should see something similar to this:

It could well be that you see one revision instead of two: the Revision mode has been set to single, so old revisions are removed. What matters is the timestamp, that should be close to your current time.

Putting it to the test

Now it is time to put the CD pipeline to the test. In order to do that, open your Visual Studio Code (or your favorite text-editor) in your webapp directory. You should see something like this:

Now change line 5:

Save this file, either by using File -> Save All in the menu, or Ctrl S/Cmd S. Now click on the Source Control Icon, and VS Code should look like this:

Now type a message in the Message in the Messagbox in the top left, and click ‘Commit’:

You are now making a local commit, nothing will happen now. Once you push the code to the server, the pipeline will start. To do that, click on ‘Sync Changes’:

Go back to your project on Github and click the ‘Actions’ tab, and you will see something like this:

If you want to know more about the progress of the pipeline, you click on the pipeline, and you will get information.

Wait till the pipeline has finished, then go your Container App in the Azure Portal and try it out. Copy the Application Url:

Now paste it into a browser and add /ping after the URL:

Presto! The message is changed, and the integration works.

Conclusion

As you can see, automating your deployment workflow is not rocket-science (Pun intended). Of course, this is a very simplified example, but it could form the basis for something more elaborate.

Leave a Reply

Your email address will not be published. Required fields are marked *