Containerisation

<< Click to Display Table of Contents >>

Navigation:  »No topics above this level«

Containerisation

 

NOTE:  This functionality is only available within BNCS V6 and above

 

An application implementing the framework can be configured to run as a container by implementing the following steps with docker or an equivalent containerisation host:

Step 1: Enable Embedded CSI

Ensure that the application is initialised to use EmbeddedCSI.  This is an option in the BNCSFramework.Init method.

Step 2: Configure private sources in a NuGet.Config file.

Create a NuGet.Config file in your project directory and add the configuration for the sources that are required for the application to build, replacing the username & password with your own.

Example: Adding the DDK feedz.io sources.

<configuration>
<packageSources>
                <add  key="nuget.org"  value="https://api.nuget.org/v3/index.json"  protocolVersion="3"  />
                <add  key="BNCS"  value="https://f.feedz.io/bncs/driver-development-kit/nuget/index.json"  />
</packageSources>
<packageRestore>
        <add  key="enabled"  value="True"  />
        <add  key="automatic"  value="True"  />
</packageRestore>
<packageSourceCredentials>
<BNCS>
        <add  key="Username"  value="<username>"  />
        <add  key="ClearTextPassword"  value="<password>"  />
</BNCS>
</packageSourceCredentials>
</configuration>

Step 3: Create an Image

Create Dockerfile in your project root:

This can be automatically added with visual studio by including docker support when configuring your project.

The NuGet.Config file should be made available and configured to restore the dependencies as part of the build process. It can be removed afterwards.

Example:

ARG BUILD.CONFIGURATION=Release
WORKDIR /src
 
# Copy NuGet.Config and project file
COPY ["./NuGet.Config", "."]
COPY ["./FrameworkTest.csproj", "FrameworkTest/"]
 
# Restores NuGet dependencies for the project using a custom configuration
RUN dotnet restore "FrameworkTest/FrameworkTest.csproj" --configfile NuGet.Config
 
# Remove NuGet.Config after restore
RUN rm NuGet.Config
 
# Copy all source files to the FrameworkTest subdirectory
COPY . ./FrameworkTest/
 
# Build the project
WORKDIR "/src/FrameworkTest"
RUN dotnet build "./FrameworkTest.csproj" -c $BUILD.CONFIGURATION -o /app/build
 
FROM build AS publish
ARG BUILD.CONFIGURATION=Release
RUN dotnet publish "./FrameworkTest.csproj" -c $BUILD.CONFIGURATION -o /app/publish /p:UseAppHost=false
 
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "FrameworkTest.dll"]

Step 4: Configure runtime environment of the container

Using docker compose files you can define the application configurations and expose which ports to listen on.

Example:

docker-compose.yml
services:
 frameworktest:
   image: ${DOCKER.REGISTRY-}frameworktest
   build:
     context: .
     dockerfile: FrameworkTest/Dockerfile
   
   volumes:
   #root directory
   # Bind mount: Host system root directory access
   # Maps host path /home/bncs/bncs to container's /root directory
   # Provides read-write access for configuration and data persistence
     - type: bind
       #Linux systems
       source: /home/bncs/bncs
       ##Windows system
       #source: C:\bncs #host's bncs config directory in a windows system
       target: /root
       read.only: false  # Remove if write access is needed
 
   environment:
     - CC.ROOT=/root
     - CC.WORKSTATION=1
     - CC.SYSTEM=nmostest
     - ASPNETCORE.URLS=http://*:5000
   restart: unless-stopped
 
   network.mode: host
   # microsoft windows config
   # extra.hosts:
   #   - "host.docker.internal:host-gateway"

Behavior Notes:

•It is recommended to build linux containers and run on a linux kernel on bare-metal machine instead of a VM. This setup optimal for using embeddedCSI .

•Currently supporting plain HTTP without TLS . So expose only HTTP port.

•A container requires access to BNCS config files from the host system and the appropriate volume mounting should be configured to enable this:

#Linux Host
   volumes:
     - type: bind
       source: /home/bncs/bncs #host's bncs config directory
       target: /root #container's /root directory
       read.only: false  # Remove if write access is needed
#Windows Host
   volumes:
     - type: bind
       source: C:\bncs #host's bncs config directory
       target: /root #container's /root directory
       read.only: false  # Remove if write access is needed

•Supply appropriate environment configurations on the environment: section of the docker-compose file. Note the CC.ROOT variable points to the mounted container volume /root.