Now you can set up continuous deployment from DockerHub using Visual Studio Team Sservices Release management. A release can get triggered automatically once an image is updated in Docker Hub.
We will see how this can help us automatically keep our Azure Web App updated with the source code siting in GitHub.
Step 1: (Code): You can keep your code on GitHub. For example https://github.com/jikuma/nodeJsSampleService. This is a simple site which displays "Hello Docker Hub".
We want to automatically create/update a container image once any edit is made to source code. Once an image is pushed to Docker hub, we further want to automatically trigger VSTS release to update my website hosted in Azure web app.
Step 2: (CI): Once we have a code we want to automatically build and push an image to docker hub.
Step: 2.1 (Link GitHub to your Docker Hub Account):
Log in to your docker hub account
If you have not already connected your GitHub account to DockerHub account. You will have to link these account. Here are steps to do it.
Step: 2.1.a Click on link account
Select link GitHub and then provide details to link your GitHub account
If a GitHub account is already linked you will get list of your GitHub repository
Step: 2.2 (Create a Docker Hub image/repository using GitHub repo)
Click on 'Create Automated build.'
Select the repository you want to create image from
Enter repo detail and select Ok.
A docker hub repository will be created for you.
Step: 2.3 (Verify that CI is setup for you)
Go to Build setting tab of Dockerhub repo and check if the setting is correct.
It's saying that whenever a change is made to master branch of the GitHub repo it will trigger image build and will update the docker hub repo.
Your CI is set up. You can now make changes to your Github repo and check if Docker hub repository/image is getting updated or not.
You can see a build getting trigger in build details tab
Step 3: (Setting up CD: update my website as soon as the new image is pushed to Docker hub).
Step 3.1 Let's create an Azure web app using this docker hub image
Step 3.1.a Log into the Azure portal
Step 3.1.b Select App service
Click o the plus to create new web app
Then select web app for containers
Click create and give details, like app name and click on configure the container.
Input the image details.
Click ok to create the web app.
Once the web app is created, visit the site to check if deployment is successful.
Once you have successfully deployed your web app , we will setup a CD so that whenever the image is updated in the DockerHub, web app gets updated automatically.
Step 3.2: (Setup CD using VSTS Release Definition)
Let's create a Release Definition in VSTS to achieve Continuous deployment
Log in to your VSTS account. If you don't already have a VSTS account, here are steps to get started.
Step 3.2.a: Create Docker Registry endpoint.
Step 3.2.b : Now, Create new release definition.
Step 3.2.c: Add Artifact of type Docker hub and select the namespace and repo from the drop-down.
Step 3.2.d: Once Artifact is created click on the lightning icon and enable continuous deployment.
Step 3.2.e: No, let's add the tasks to update the web app.
Add a task to deploy webapp and another to restart the web app.
Deploy Web app: Enter the details of the web app. Inside tag field input the variable name $(BUILD.BUILDID). The value of BUILD.BUILDID is the image tag name for which release has been queued.
Restart Web App:
Enter the details in the task and save the RD.
Now you are all set.
Step 4: Validation (Validate that a check-in in GitHub will automatically update your web app)
Step 4.1: Make a change in your github repo.
We have changed the message on the site from "Hello DockerHub - updated - 15" to "Hello Docker hub. CD should automatically update the azure web app."
Commit the change.
Step 4.2: (Validate CI)
It will automatically trigger a build in docker hub to update the docker hub repo. Validate that in docker hub, check if a new build to update the image is triggered.
Step 4.3 (Validate CD):
Once new image in dockerhub is updated, a release will automatically get triggered in VSTS. This will updated your webapp.
Step 4.4 (Validate web app):
Refresh the website for the change to take effect
You can also manually select the image tag to deploy without setting the CD. For this, you have to create a release and select the tag from the drop-down with which you want to update the web app.
This post first appeared on MSDN Blogs | Get The Latest Information, Insights, Announcements, And News From Microsoft Experts And Developers In The MSDN Blogs., please read the originial post: here