Skip to content

Commit

Permalink
Merge 00e9561 into 8a5469c
Browse files Browse the repository at this point in the history
  • Loading branch information
helto4real committed Dec 12, 2020
2 parents 8a5469c + 00e9561 commit 469ad34
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 37 deletions.
21 changes: 12 additions & 9 deletions .github/workflows/tags_docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,25 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@main
- name: Login to docker hub
run: docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_TOKEN }}
# - uses: olegtarasov/get-tag@v2
# name: Set tag envronment variable
- name: "Set version number"
run: |
sed -i '/ private const string Version = /c\ private const string Version = "${GITHUB_REF#refs/tags/}";' ${{github.workspace}}/src/DaemonRunner/DaemonRunner/Service/RunnerService.cs
- name: Set up Docker Buildx
-
name: Set up QEMU
uses: docker/setup-qemu-action@v1
-
name: Set up Docker Buildx
id: buildx
uses: crazy-max/ghaction-docker-buildx@v1
with:
version: latest
uses: docker/setup-buildx-action@v1
-
name: Available platforms
run: echo ${{ steps.buildx.outputs.platforms }}
- name: Login to docker hub
run: docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_TOKEN }}
- name: Run Buildx
run: |
docker buildx build \
--platform linux/arm,linux/arm64,linux/amd64 \
--platform linux/arm, linux/amd64 \
--output "type=image,push=true" \
--no-cache \
--file ./Dockerfile . \
Expand Down
12 changes: 12 additions & 0 deletions Docker/build_dotnet.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
ARCH=$(uname -m)

if [ $ARCH == "armv7l" ]; then
dotnet publish /usr/src/Service/Service.csproj -v q -c Release -r "linux-arm" -o "/daemon"
elif [ $ARCH == "aarch64" ]; then
dotnet publish /usr/src/Service/Service.csproj -v q -c Release -r "linux-arm64" -o "/daemon"
elif [ $ARCH == "x86_64" ]; then
dotnet publish /usr/src/Service/Service.csproj -v q -c Release -r "linux-x64" -o "/daemon"
else
echo 'NOT VALID BUILD'; exit 1;
fi
31 changes: 16 additions & 15 deletions Docker/rootfs/etc/services.d/NetDaemonApp/run
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,24 @@ echo "Starting NetDaemon Runner"

declare runtype="Service"
declare daemondir="/daemon"

cd "${NETDAEMON__PROJECTFOLDER}" || echo -e "\\033[31mCould not change directory to run project\\033[0m" >&2

if [[ "${PWD}" != "${NETDAEMON__PROJECTFOLDER}" ]]; then
declare custom_daemondir="/custom_daemon"
if [ ! -d "/data" ]; then
echo -e "\\033[31mMissing mapping to apps, please map '/data' to your apps folder\\033[0m" >&2
exit 1
fi

echo -e "\\033[32mBuilding NetDaemon source...\\033[0m" >&2
if dotnet publish -v q -c Release -o "${daemondir}"; then
dotnet build-server shutdown || exit 1
fi
if [ -z "${NETDAEMON__PROJECTFOLDER}" ]; then
echo -e "\\033[32mRunning pre-compiled NetDaemon...\\033[0m" >&2
cd "${daemondir}"
exec "./${runtype}"
else
echo -e "\\033[32mRun the custom project provided...\\033[0m" >&2
cd "${NETDAEMON__PROJECTFOLDER}" || echo -e "\\033[31mCould not change directory to run project\\033[0m" >&2

if test -f "${daemondir}/Service"; then
echo -e "\\033[32mStarting NetDaemon...\\033[0m" >&2
elif test -f "${daemondir}/daemonapp"; then
echo -e "\\033[32mStarting custom NetDaemon project...\\033[0m" >&2
runtype="daemonapp"
if [[ "${PWD}" != "${NETDAEMON__PROJECTFOLDER}" ]]; then
echo -e "\\033[31mCould not change directory to run custom project\\033[0m" >&2
exit 1
fi

dotnet run -c Release
fi

exec "${daemondir}/${runtype}"
29 changes: 17 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Build the NetDaemon Admin with build container
FROM ludeeus/container:frontend as builder

ARG TARGETPLATFORM
ARG BUILDPLATFORM

RUN echo "I am running on $BUILDPLATFORM, building for $TARGETPLATFORM" > /log

RUN \
apk add make \
\
Expand All @@ -11,39 +16,40 @@ RUN \
\
&& rm -fr /var/lib/apt/lists/* \
&& rm -fr /tmp/* /var/{cache,log}/*
# && rm -R /admin/node_modules

# Build the NetDaemon with build container
# FROM ludeeus/container:dotnet5-base-s6
FROM mcr.microsoft.com/dotnet/sdk:5.0.100
# Pre-build .NET NetDaemon core project
FROM mcr.microsoft.com/dotnet/sdk:5.0.101-buster-slim-amd64 as netbuilder

# Copy the source to docker container
COPY ./src /usr/src
COPY ./Docker/build_dotnet.sh /build.sh
RUN chmod 700 /build.sh

# COPY Docker/rootfs/etc /etc
COPY ./Docker/rootfs/etc /etc
# Run build script for all platforms since dotnet is not QEMU compatible
RUN /build.sh

# Final stage, create the runtime container
FROM mcr.microsoft.com/dotnet/sdk:5.0.100

COPY ./Docker/rootfs/etc /etc
COPY ./Docker/s6.sh /s6.sh

RUN chmod 700 /s6.sh
RUN /s6.sh

# COPY admin
COPY --from=builder /admin /admin

COPY --from=netbuilder /daemon /daemon
# Install S6 and the Admin site
RUN apt update && apt install -y \
nodejs \
yarn \
make



# Set default values of NetDaemon env
ENV \
DOTNET_NOLOGO=true \
DOTNET_CLI_TELEMETRY_OPTOUT=true \
NETDAEMON__PROJECTFOLDER=/usr/src/Service \
HOMEASSISTANT__HOST=localhost \
HOMEASSISTANT__PORT=8123 \
HOMEASSISTANT__TOKEN=NOT_SET \
Expand All @@ -53,5 +59,4 @@ ENV \
ASPNETCORE_URLS=http://+:5000 \
HASS_DISABLE_LOCAL_ASM=true


ENTRYPOINT ["/init"]
ENTRYPOINT ["/init"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Welcome to the NetDaemon project. This is the application daemon for Home Assist

Please see [https://netdaemon.xyz](https://netdaemon.xyz) for detailed instructions how to get started using NetDaemon.

> **The NetDaemon is currently in alpha release so expect things to change.**
> **The NetDaemon is currently in beta release so expect things to change.**
## Issues

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ public DaemonAppCompiler(ILogger<DaemonAppCompiler> logger, IOptions<NetDaemonSe

public IEnumerable<Type> GetApps()
{
_logger.LogDebug("Loading dynamically compiled apps...");
var assembly = Load();
var apps = assembly.GetTypesWhereSubclassOf<NetDaemonAppBase>();

if (!apps.Any())
_logger.LogWarning("No .cs files found, please add files to {sourceFolder}/apps", _netDaemonSettings.Value.SourceFolder);
else
_logger.LogDebug("Found total of {nr_of_apps} apps", apps.Count());

return apps;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ public LocalDaemonAppCompiler(ILogger<DaemonAppCompiler> logger)

public IEnumerable<Type> GetApps()
{
_logger.LogDebug("Loading local assembly apps...");
var assembly = Load();

var apps = assembly.GetTypesWhereSubclassOf<NetDaemonAppBase>();

if (!apps.Any())
_logger.LogWarning("No local daemon apps found.");
else
_logger.LogDebug("Found total of {nr_of_apps} apps", apps.Count());

return apps;
}
Expand Down
7 changes: 7 additions & 0 deletions src/DaemonRunner/DaemonRunner/Service/RunnerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)

var sourceFolder = Path.Combine(_netDaemonSettings.SourceFolder!, "apps");

_logger.LogDebug("Finding apps in {folder}...", sourceFolder);

// Automatically create source directories
if (!Directory.Exists(sourceFolder))
Directory.CreateDirectory(sourceFolder);
Expand Down Expand Up @@ -122,7 +124,10 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
_loadedDaemonApps = _daemonAppCompiler.GetApps();

if (_loadedDaemonApps is null || !_loadedDaemonApps.Any())
{
_logger.LogError("No apps found, exiting...");
return;
}

IInstanceDaemonApp? codeManager = new CodeManager(_loadedDaemonApps, _logger, _yamlConfig);
await daemonHost.Initialize(codeManager).ConfigureAwait(false);
Expand Down Expand Up @@ -190,6 +195,8 @@ private async Task GenerateEntities(NetDaemonHost daemonHost, string sourceFolde
if (_entitiesGenerated)
return;

_logger.LogDebug("Generating entities ..");

_entitiesGenerated = true;
var codeGen = new CodeGenerator();
var source = codeGen.GenerateCode(
Expand Down

0 comments on commit 469ad34

Please sign in to comment.