Publish NuGet packages via Docker Release Container

Oleksii Nikiforov
2 min readMay 9, 2021

TL;DR

You can use Docker to push packages to a NuGet feed. This blog post shows how to release a NuGet package to Amazon CodeArtifact via Docker. Source code can be found at https://github.com/NikiforovAll/docker-release-container-sample.

General

The idea behind having a release container is pretty straightforward — you can bundle artifacts and tools so the release mechanism is portable and unified because of Docker. Also, another advantage of building NuGet packages in Docker is that you don’t need any dependencies installed on the build-server itself. I invite you to read Andrew’s Lock post to get more details about the use case ( https://andrewlock.net/pushing-nuget-packages-built-in-docker-by-running-the-container/). This blog post is focused on the practical side, let’s dive into it by reviewing the Dockerfile:

  1. Base layer is used for publishing. It contains aws-cli and credential provider (AWS.CodeArtifact.NuGet.CredentialProvider) so we can deploy to private NuGet feed as described in here. Please see the excellent guide on how to work with Docker and NuGet feeds https://github.com/dotnet/dotnet-docker/blob/main/documentation/scenarios/nuget-credentials.md.
  2. Build layer is used for building and packing.
  3. Entrypoint defines custom publishing script, essentially, dotnet nuget push is called. Note that, you can specify additional arguments. (e.g: override --source or provide --api-key).

For source code, please see: https://nikiforovall.github.io/dotnet/nuget/docker/2021/05/09/nuget-release-container.html

Summary

In this blog post, I showed how you can build NuGet packages via Docker, and push them to your NuGet feed when you run the container.

Pros:

  • Easy to release. The solution is portable. It’s our goal after all.
  • Extendable approach. You are in charge of how to build NuGet package and can install all required tools and dependencies when you need it.

Cons:

  • Images can be quite sizable. Additional space is required to release containers, so a retention policy should be applied.
  • Adds unnecessary complexity if you already use dotnet toolchain and you have all dependencies installed on build server.

Reference

Originally published at https://nikiforovall.github.io.

--

--