Skip to content

Commit

Permalink
New docker base and S6 support
Browse files Browse the repository at this point in the history
  • Loading branch information
helto4real committed Apr 12, 2020
1 parent 41b3fae commit 0229dcf
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 23 deletions.
37 changes: 21 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
# Build the NetDaemon with build container
FROM mcr.microsoft.com/dotnet/core/sdk:3.1.200-alpine as build

COPY . ./temp/

RUN \
mkdir -p /data \
\
&& dotnet \
publish \
./temp/src/Service/Service.csproj \
-c Release \
-o ./temp/dist \
\
&& mv ./temp/dist /app \
&& rm -R ./temp
RUN apk add \
bash

# Copy the source to docker container
COPY ./src /tmp/src

# Copy the build script for minimal single binary build
COPY addon/rootfs/build/build.sh /tmp/build.sh
RUN chmod +x /tmp/build.sh

# Build the minimal single binary
RUN /bin/bash /tmp/build.sh

# Build the target container
FROM ludeeus/container:dotnet-base
FROM netdaemon/base

# Copy the built binaries and set execute permissions
COPY --from=build /netdaemon/bin/publish /daemon
RUN chmod +x /daemon/Service

COPY --from=build /app /app
# Copy the S6 service scripts
COPY addon/rootfs/etc /etc

# Set default values of NetDaemon env
ENV \
HASS_HOST=localhost \
HASS_PORT=8123 \
HASS_TOKEN=NOT_SET \
HASS_DAEMONAPPFOLDER=/data

ENTRYPOINT ["dotnet", "/app/Service.dll"]
ENTRYPOINT ["/init"]
22 changes: 22 additions & 0 deletions addon/rootfs/build/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

cd /tmp

ARC=$(uname -m)

echo "Building NetDaemon for platform $ARC"

if [ "$ARC" == "armhf" ]; then
export RID="linux-arm"
elif [ "$ARC" == "aarch64" ]; then
export RID="linux-arm"
elif [ "$ARC" == "x86_64" ]; then
export RID="linux-x64"
else
echo 'NOT VALID ARCHITECTURE' && exit 1

fi

cd src/Service/
dotnet add package Microsoft.Packaging.Tools.Trimming --version 1.1.0-preview1-26619-01
dotnet publish -c Release -o /netdaemon/bin/publish -r $RID /p:PublishSingleFile=true /p:PublishTrimmed=true /p:TrimUnusedDependencies=true
2 changes: 1 addition & 1 deletion addon/rootfs/etc/services.d/NetDaemon/finish
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/execlineb -S0
# ==============================================================================
# NetDaemon add-on
# NetDaemon Service
# Take down the S6 supervision tree when NetDaemon fails
# ==============================================================================
if -n { s6-test $# -ne 0 }
Expand Down
12 changes: 6 additions & 6 deletions addon/rootfs/etc/services.d/NetDaemon/run
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/with-contenv bashio
#!/usr/bin/with-contenv /bin/bash

# ==============================================================================
# NetDaemon Add-on
# NetDaemon Service
# Starts NetDaemon
# ==============================================================================
cd /daemon || echo -e "\033[31mCould not change directory to daemon\033[0m" >&2

cd /daemon || bashio::exit.nok "Could not change directory to Node-RED"

bashio::log.info "Starting NetDaemon..."
echo -e "\033[32mStarting NetDaemon...\033[0m" >&2

exec ./Service
./Service
1 change: 1 addition & 0 deletions src/DaemonRunner/DaemonRunner/Service/RunnerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
if (config == null)
{
_logger.LogError("No config specified, file or environment variables! Exiting...");

return;
}

Expand Down

0 comments on commit 0229dcf

Please sign in to comment.