ASP.NET 5: Seamless integration with Drone and Docker

ASP.NET 5: Seamless integration with Drone and Docker

ASP.NET 5 and Docker   Microsoft provides dockerfiles to create images and docker containers containing the ASP.NET

Our Software Developers have deep knowledge on ASP.NET 5 and Seamless integration with Drone and Docker. Learn more about it in this article.

ASP.NET 5 and Docker

Microsoft provides dockerfiles to create images and docker containers containing the ASP.NET 5 execution environment applications. The image contains the following applications:

  • dnvm: .NET runtime versions manager. Equivalent of ruby’s RVM, or virtualenv from python.
  • dnx: SDK and execution environment multi-platform of .NET applications.
  • dnu: Utility to install nuget development agencies. Equivalent to rubygems / bundler in ruby, or NPM in nodejs

Note: At this time (December 2015), dotnet is under development, a tool that combines dnx and dnu.

To serve as an example, a repository on github was created containing a simple test implemented with xunit. It can be cloned as follows:

git clone
cd asp.net5-drone-ci-example

Then we can test the application using the aforementioned image docker:

docker run -i -t -v `pwd`:/app microsoft/aspnet:1.0.0-rc1-update1-coreclr /bin/bash

The parameters indicate the following:

  • -i: interactive mode.
  • -t: Pseudo-tty.
  • -v: Create a volume, which means, mounting the pwd within / app in the container.
  • microsoft/ aspnet: Image in which we can initiate our container
  • :1.0.0-rc1-update1-coreclr: Version of the image to use
  • /bin/ bash: command to execute within our container

Then, within the container, execute the following dependencies to install and run the xunit tests implemented:

cd /app
dnu restore
dnx test

We should have a similar output to this one:

Feeds used:

    89 package(s) to /root/.dnx/packages
root@a074a96c419a:/app# dnx test DNX Runner (64-bit DNXCore 5.0)
Discovering: app
Discovered:  app
Starting:    app
Finished:    app
app  Total: 1, Errors: 0, Failed: 0, Skipped: 0, Time: 0.375s


Drone is a continuous integration platform that works on docker. Each build is performed on a new container, so if we have a docker image that provides us the tools to build and test our application, we can use drone very easily.

Webhook y github

Drone is responsible for conducting a build for each push that we’ll make to our github repository (it also supports bitbucket and gitlab). To set up drone with github, we go to “our applications” and record a new application. Github then we will give us a Client ID and Client Secret that we will use to configure drone.

Once we have the ID and Client Secret, we create a file with the following format:


Finally, we can start drone with the following command:

docker run 
    --volume /var/lib/drone:/var/lib/drone 
    --volume /var/run/docker.sock:/var/run/docker.sock 
    --env-file /etc/drone/dronerc 

In -env-file we indicate the file created above, and in -publish we indicate the port that will be running on the host (80 in this case).


.drone.yml is the configuration file required to use drone on our application and should be at the root of the repository. Below, we can see the minimum .drone.yml to run the tests in our application:

    image: microsoft/aspnet:1.0.0-rc1-update1-coreclr
        - dnu restore
        - dnx test

Note: dnx test runs the test command as defined in project.json as dnx.runner.xunit.

In the configuration file, we define the services that we will use and configure these services. Here, build represents the service that will be configured and will handle the building and testing of the application. image indicates the docker image that we will use and commands is a list of commands to run within the container docker. All commands should return a successful exit code for the continued integration of success.

NuGet cache

Each build that drone makes will download and install all the dependencies again. To avoid this, we must cache the dependencies and retrieve them on each build. If the dependencies change, dnu restore will be responsible for resolving it.

To define a cache in drone, we use the cache service where we define files or folders to be cached. One drawback is that drone can only cache files within /drone (the working directory that defines drone inside the container), while the image of aspnet that we use installs the packages in /root/.dnx. There are ways around this, the one that we will show here is defining the DNX_PACKAGES environment variable that defines the directory where the nuget packages will be installed.

Then, we only have to define the environment variable in any folder inside /drone and cache it:

    image: microsoft/aspnet:1.0.0-rc1-update1-coreclr
        - DNX_PACKAGES=/drone/nuget_cache
        - dnu restore
        - dnx test

        - /drone/nuget_cache
        - project.lock.json

The first thing we must do is to add in the environment configuration of the build service the DNX_PACKAGES environment variable, indicating a directory in which the packages nuget will be stored inside /drone.

Finally, we configure the cache service files or folders that you wish to cache the next build.

To finish, here is the drone output when making the corresponding build on the example repository:

[info] Pulling image plugins/drone-cache:latest
Restoring cache /drone/nuget_cache
Restoring cache project.lock.json
[info] Pulling image plugins/drone-git:latest
$ git init
Initialized empty Git repository in /drone/src/
$ git remote add origin
$ git fetch --no-tags --depth=50 origin +refs/heads/master:
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> origin/master
$ git reset --hard -q 9771386ff4aaa292f1b3653e3e92b129b4417ecb
$ dnu restore
Microsoft .NET Development Utility CoreClr-x64-1.0.0-rc1-16231

  OK 1550ms
Restoring packages for /drone/src/
  OK 935ms
  OK 1005ms
  OK 420ms
  OK 2281ms
  OK 424ms
  OK 478ms
  OK 1200ms
  OK 1318ms
Installing System.Net.Http.4.0.0
Installing Microsoft.Win32.Primitives.4.0.0
Installing System.IO.Compression.4.0.0
Writing lock file /drone/src/
Restore complete, 6756ms elapsed

Feeds used:

    3 package(s) to /drone/nuget_cache
$ dnx test DNX Runner (64-bit DNXCore 5.0)
  Discovering: asp.net5-drone-ci-example
  Discovered:  asp.net5-drone-ci-example
  Starting:    asp.net5-drone-ci-example
  Finished:    asp.net5-drone-ci-example
   asp.net5-drone-ci-example  Total: 1, Errors: 0, Failed: 0, Skipped: 0, Time: 0.379s
[info] Pulling image plugins/drone-cache:latest
Building cache /drone/nuget_cache
Building cache project.lock.json