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:
Ensure that the application is initialised to use EmbeddedCSI. This is an option in the BNCSFramework.Init method.
<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>
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"]
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"
•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.