Setting up net service - Arthyon/microservice-poc GitHub Wiki
This section describes how to set up a production- and development image for a .Net service.
Production image
A production image is created using a multi stage build. The first stage is based on the .Net-sdk.
Copy the csproj-file into the image and restore packages with dotnet restore. Copy everything else into the image and run dotnet publish to create a release build.
The next stage should be the test stage.
The last stage should be based on the lean runtime image.
Copy the output of the publish command and set the entrypoint to dotnet <servicename>.dll.
Development image
The development image should be based on the sdk, as we will watch for local changes and rebuild on the fly.
We must set the environment variable DOTNET_USE_POLLING_FILE_WATCHER to 1 to enable the watcher, as docker file systems do not work well with file system events.
Rule of thumb: All file watchers used in docker must use some form of polling.
We will also need to install the vsdbg-debugger into our container. See an existing image for the command.
Next, copy the *.csproj and Directory.Build.props-files into the image and restore dependencies.
NOTE: It is important to specify a directory further up in the Directory.Build.props-file to avoid collisions when mounting the local directory. This means that a .Net-project's source code should be at least two levels from root of the repository.
Finally, set the entrypoint as dotnet watch run --no-restore. This enables us to watch the local directory and rebuild, without needing to restore packages all the time. A drawback of this is that we have to rebuild the image if our dependencies (nuget-packages) changes.
Helm
In the values.dev.yml-file, the only special thing to watch out for is to mount the local service directory into the directory inside the docker-container. You don't need to expose any ports, as .Net-debugging executes directly on a pod.
launch.json
A launch-configuration must be added for the service of type coreclr. Start out by copying an existing one for easy setup.
sourceFileMap must be changed to point to the physical path on disk.
Right now, a new ps1-script must be created pr. service. See Issue #10 for updates on this.
Api Definition
.Net has many great tools to autogenerate openapi-specifications based on the api. You could leverage these tools to create and maintain the api definition.