In this lab, we will configure release management for our sample application. We will create a Docker Registry service endpoint that enables us to pull a TomCat image from Docker Hub and run it to create a container. We will retrieve the artifact created by our automated build in Lab 3, and using the VSTS build agent created in Lab 4, we will run a docker command to deploy the artifact to the TomCat container running on a Linux machine in Azure.
You must have completed all previous labs.
-
Browse to the Docker Integration extension on the Visual Studio marketplace.
-
Install the extension by clicking "Install" and selecting the account you want to install the extension for.
-
Register for a Docker ID by creating an account on Docker Hub as explained in the Docker documentation.
-
Create a new Docker Registry connection by clicking on "+ New Service Endpoint" and selecting "Docker Registry"
-
Specify the following information for your connection and click OK:
Connection name: Docker Hub
Docker registry: https://index.docker.io/v1/
Docker ID: The Docker ID you created in step 1
Password: Your Docker Hub Password
Email: Optional -
You should now see the service endpoint you just created in the overview:
-
Create a new Docker Host connection by clicking on "+ New Service Endpoint" and selecting "Docker Host"
-
Specify the following information for your connection and click OK:
Connection Name: Docker Host
Server URL: Specify the server URL of the Docker Machine you created in LABX CA Certificate: Paste in the CA certificate you saved to disk in LABX Certificate: Paste in the certificate you saved to disk in LABX Key: Paste in the key you saved to disk in LABX -
You should now see the service endpoint you just created in the overview:
We will now create a new Release Definition that contains all the steps to be executed when we deploy a release. We will enable Continous Deployment so that a new release is created every time a build is successful.
-
Create a new release definition by clicking "+ New definition"
-
This time we will not base our release definition on a template, therefore you select "Empty" and click "Next"
-
Select "Build" as the artifact source and fill out the fields as specified below and click "Create":
Source (Build definition): Point to the build we created in Lab 03
Continous deployment: Check
Queue: Select the queue containing the VSTS agent we installed in Lab 04. -
You should now see a default release definition that is empty.
We will now configure the release tasks for the Staging environment of our release definition.
-
Go to "Releases" under "Build & Release" and select the release definition you created earlier.
-
Select "All" in the menu to show all the tasks that are available. Find the task called "Docker" and click "Add" twice to add two Docker tasks.
-
When you close the pop-up, your release definition should look like this:
-
Select the first "Docker" task and edit it to match the following fields:
Docker Registry Connection: Select your Docker Registry endpoint
Action: Run an image
Image Name: tomcat:8.0
Container Name: ossdevops-v$(Release.ReleaseId)-staging
Ports: 8888:8080
Run in Background: CheckedAdvanced options
Docker Host Connection: Select your Docker Host endpoint
Working Directory: $(System.DefaultWorkingDirectory)
Note that we name our container using a variable: $(Release.ReleaseId). This is a built-in variable that will insert the ID of the release into the name of the container being created in this task.
-
Select the second "Docker" task and edit it to match the following fields:
Docker Registry Connection: Select your Docker Registry endpoint
Action: Run a Docker command
Command:cp $(System.DefaultWorkingDirectory)/ArtifactSource/drop/sample-app/target/OSSDevOpsHOL.war ossdevops-v$(Release.ReleaseId)-test:/usr/local/tomcat/webapps/OSSDevOpsHOL.warAdvanced options
Docker Host Connection: Select your Docker Host endpoint
Working Directory: $(System.DefaultWorkingDirectory)
The command above copies the .war file contained in our artifact to the newly created container running on our Docker Host.
-
If you haven't done so already, save your release definition.
-
In the command in step 6, you can see that the path contains "ArtifactSource". This refers to the source of our artifact, which default is the name of our build. As we want our source to be called "ArtifactSource", we need to specify this. Go to the "Artifacts" tab of your release definition:
-
As you can see there, the "Source alias" is currently "Queue Jenkins Job & Publish", which is a painful name to include in a path. Click the three dots next to the alias and select Edit:
-
Rename the value of "Source Alias" to "ArtifactSource" so that it matches we value we specified in our path in step 6. Click "Save".
-
Go to the "Trigger" tab of your release definition and update the "Set trigger on artifact source" to point to the artifact source called "ArtifactSource".
-
Save your release definition again.
-
Create a new release by clicking "+ Release" and selecting "Create Release".
-
A new release has now been created and you can click the link to navigate to the release:
-
Click on the "Logs" tab of the release to see the details of your deployment and verify that the release was successful.
-
Browse to your webapp deployed in the release.
You should use the machine's Hostname created in Lab 4
You should make sure to open the port(Check Lab 4, section 4.2, steps 2 and 3) defined in section 5.5 step 5 in this lab
You should make sure to use the port defined in section 5.5 step 5 in this Lab