diff --git a/.github/workflows/tags_docker.yml b/.github/workflows/tags_docker.yml index ba44f3769..7330ccbbb 100644 --- a/.github/workflows/tags_docker.yml +++ b/.github/workflows/tags_docker.yml @@ -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 . \ diff --git a/Docker/build_dotnet.sh b/Docker/build_dotnet.sh new file mode 100644 index 000000000..4dd8f3a50 --- /dev/null +++ b/Docker/build_dotnet.sh @@ -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 diff --git a/Docker/rootfs/etc/services.d/NetDaemonApp/run b/Docker/rootfs/etc/services.d/NetDaemonApp/run index bb3421a47..f6c53a69b 100755 --- a/Docker/rootfs/etc/services.d/NetDaemonApp/run +++ b/Docker/rootfs/etc/services.d/NetDaemonApp/run @@ -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}" \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 249b97a39..8647b4eff 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 \ \ @@ -11,18 +16,22 @@ 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 @@ -30,20 +39,17 @@ 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 \ @@ -53,5 +59,4 @@ ENV \ ASPNETCORE_URLS=http://+:5000 \ HASS_DISABLE_LOCAL_ASM=true - -ENTRYPOINT ["/init"] \ No newline at end of file +ENTRYPOINT ["/init"] diff --git a/README.md b/README.md index 4171842f5..cd9163813 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/DaemonRunner/DaemonRunner/Service/App/DaemonAppCompiler.cs b/src/DaemonRunner/DaemonRunner/Service/App/DaemonAppCompiler.cs index da291b3fe..b1473bcd6 100644 --- a/src/DaemonRunner/DaemonRunner/Service/App/DaemonAppCompiler.cs +++ b/src/DaemonRunner/DaemonRunner/Service/App/DaemonAppCompiler.cs @@ -24,11 +24,14 @@ public DaemonAppCompiler(ILogger logger, IOptions GetApps() { + _logger.LogDebug("Loading dynamically compiled apps..."); var assembly = Load(); var apps = assembly.GetTypesWhereSubclassOf(); 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; } diff --git a/src/DaemonRunner/DaemonRunner/Service/App/LocalDaemonAppCompiler.cs b/src/DaemonRunner/DaemonRunner/Service/App/LocalDaemonAppCompiler.cs index c782a6fa4..5c2025404 100644 --- a/src/DaemonRunner/DaemonRunner/Service/App/LocalDaemonAppCompiler.cs +++ b/src/DaemonRunner/DaemonRunner/Service/App/LocalDaemonAppCompiler.cs @@ -19,12 +19,15 @@ public LocalDaemonAppCompiler(ILogger logger) public IEnumerable GetApps() { + _logger.LogDebug("Loading local assembly apps..."); var assembly = Load(); var apps = assembly.GetTypesWhereSubclassOf(); if (!apps.Any()) _logger.LogWarning("No local daemon apps found."); + else + _logger.LogDebug("Found total of {nr_of_apps} apps", apps.Count()); return apps; } diff --git a/src/DaemonRunner/DaemonRunner/Service/RunnerService.cs b/src/DaemonRunner/DaemonRunner/Service/RunnerService.cs index bf2a9b5d9..365ec00c3 100644 --- a/src/DaemonRunner/DaemonRunner/Service/RunnerService.cs +++ b/src/DaemonRunner/DaemonRunner/Service/RunnerService.cs @@ -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); @@ -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); @@ -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(