Steps:
- Intro
- VSO
- Docker
- xUnit
- Build
- Back end
- Selenium
- Docker
- Release Management
- Testing
In this post, we are going to build the Docker image and
store it in DockerHub. The goal is to only produce the image once
and simply deploy it to multiple hosts as we promote the image from one
environment to the next.
We are going to use the new ASP.NET 5 configuration feature
to allow us to change configuration information as we run the image. This will enable changing connection strings
and other information using the same image we produce and store in DockerHub.
We are going to tag each image with the build number generated from VSTS. The
tag will let us identify the correct version of the image to run on each host.
Using tags allows multiple images to be in flight at the same time.
If you do not have an account on DockerHub, create one now
and create a repository. We will use the
repository you create to store the images we create.
To build the image, we must first publish our ASP.NET 5
application. We are going to do that using a simple batch file. The batch file will take two arguments. The
first will be where to find the project.json file for the ASP.NET project. The
second argument will be where we want to store the published files from which
we will build our Docker image.
-
Create package site batch file
-
Open PeopleTracker.sln
-
Right-click on PublishProfile and select Add / New Item…

- Select Text File
- Name the file packagesite.cmd
-
Copy and paste the code below into the file
set
path=%USERPROFILE%\.dnx\runtimes\dnx-clr-win-x86.1.0.0-beta8\bin;%ProgramFiles(x86)%\Microsoft
Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web
Tools\External;%1\node_modules\.bin;%path%
dnu.cmd
publish "%1" --out "%2" --wwwroot-out "wwwroot"
exit
/b 0
-
Update
dnx-clr-win-x86.1.0.0-beta8 to your current runtime
-
You can find this from the build output for the first PowerShell we run in our build
- Commit and Push your changes
-
Update build to call batch
file
- Edit your build
- Click Add build step…
- Select the Utility section
-
Add a Batch Script task and
close the Add Tasks dialog
-
Drag and drop the task above
the Copy and Publish Build Artifacts task
-
Use the browse button and
select the packagesite.cmd file we just added
-
Copy and paste the code below into the Arguments text box
$(Build.SourcesDirectory)\PeopleTracker\src\PeopleTracker.Preview
$(Build.SourcesDirectory)\DockerStage
-
Check the Modify Environment
check box
- Save and Queue your build
-
Confirm
it builds as expected
Now that our build is able to produce the packaged version of
our ASP.NET 5 application, we need to build an image and publish it to
DockerHub. When we originally published
to our Docker Hosts from Visual Studio, several PowerShell scripts were
created. We are going to use and modify some of them for use in our build.
-
Modify PowerShell to publish
to DockerHub
-
Open the
publish.ps1 file for your dev environment in the PublishProfiles folder
-
Add
the following code above the if(!$buildOnly) { line
Write-Verbose 'Time to push to Docker Hub'
$command = 'docker{0} -H {1} push {2}' -f $authOptions, $dockerServerUrl, $imageName
$command | Print-CommandString
$command | Execute-CommandString | Write-Verbose
'The
Docker image "{0}" was pushed successfully.'
-f $imageName
|
Write-Output
- Repeat this for the QA and Prod versions as well
For the agent to be able to execute those new lines, you have
to log in to DockerHub from your agent machine. Once you do, your credentials
will be saved on the agent.
-
Log in to DockerHub from
agent
-
Open a command
prompt on your agent machine
-
Execute the following
command
docker -H tcp://{DockerHost}:2376 --tls login -e
[DockerHubEmail] -p [DockerHubPassword] -u [DockerHubUsername]
The PowerShell script takes three arguments. The first is a hash table you can use to
override values supplied in the pubxml created for us by the Docker Tools for
Visual Studio when we created our Docker Hosts. The second is the directory we
want to place our image into. The final argument is to the pubxml file.
We are going to use the first argument to instruct the
PowerShell to simply build the image and not start it. We are also going to override the image name
by appending the build number as a tag. This will allow us to identify which
build created each image in DockerHub.
-
Update build to call
PowerShell
- Edit your build
- Click Add build step…
- Select the Utility section
-
Add a PowerShell task and
close the Add Tasks dialog
-
Drag and drop the task above
the Copy and Publish Build Artifacts task
-
Use the browse button and
select the devdockerhost-publish.ps1file we just modified
-
Set the Arguments to
-publishProperties
@{"DockerRemoveConflictingContainers" = "false";
"DockerBuildOnly" = "true"; "DockerImageName" =
"{YourDockerHubUserName}/{YourDockerHubRepo}:$(Build.BuildId)"}
-packOutput $(Build.SourcesDirectory)\DockerStage -pubxmlfile
".\devdockerhost.pubxml"
-
Under the Advanced section
set the Working Folder to the PublishProfiles folder
- Save and Queue your build
-
Confirm
it builds as expected
After you build succeeds, you can return to DockerHub and see
your new image.

With our build complete, we will move into Release Management
in the next post.