Skip to content

Commit

Permalink
Add on build (#38)
Browse files Browse the repository at this point in the history
* Pushing dev releases on addon

* adjusted tests
  • Loading branch information
helto4real committed Mar 24, 2020
1 parent 2c5fc00 commit 535ba6d
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 1 deletion.
17 changes: 17 additions & 0 deletions .github/workflows/push_addon_dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#### Publish tags to docker hub
name: Deploy dev builds to Docker Hub
on:
push:
branches:
- dev
- add_on_build
paths:
- 'src/*'
jobs:
deploy:
name: Deploy addon (dev)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Run deploy script using builder
run: docker run --rm --privileged -v /var/run/docker.sock:/var/run/docker.sock -v $(Build.SourcesDirectory)/addon:/data homeassistant/amd64-builder -t /data --all --docker-user $(docker_user) --docker-password $(docker_password)
88 changes: 88 additions & 0 deletions addon/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@

ARG BUILD_FROM=hassioaddons/base-amd64:5.0.3
#ARG BUILD_FROM=alpine

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-alpine as build

# Avoid warnings by switching to noninteractive
#ENV DEBIAN_FRONTEND=noninteractive

# Build arguments
ARG BUILD_ARCH
# Add-on version
ENV ADDON_VERSION 0.0.36

# Configure apt and install packages
RUN \
apk add --no-cache git \
&& git clone https://github.com/helto4real/netdaemon.git \
&& cd netdaemon \
&& git checkout master

# Build a self contained executable and trim the executable
RUN \
if [ "${BUILD_ARCH}" = "armhf" ]; then \
export RID="linux-arm"; \
elif [ "${BUILD_ARCH}" = "armv7" ]; then \
export RID="linux-arm"; \
elif [ "${BUILD_ARCH}" = "aarch64" ]; then \
export RID="linux-arm"; \
elif [ "${BUILD_ARCH}" = "amd64" ]; then \
export RID="linux-musl-x64"; \
else \
echo 'NOT VALID BUILD'; exit 1; \
fi \
&& \
cd netdaemon/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:TrimUnusedDependencies=true

# STAGE 2: Include binary in target add-on container
FROM ${BUILD_FROM} AS runtime

# Build arguments
ARG BUILD_ARCH

# Copy binary and the config from build container
COPY --from=build /netdaemon/bin/publish /daemon

COPY install_dotnet_dep.sh /install_dotnet_dep.sh

# Install .net core runtime deps
RUN chmod +x /install_dotnet_dep.sh && /install_dotnet_dep.sh

# Configure web servers to bind to port 80 when present
ENV ASPNETCORE_URLS=http://+:80 \
# Enable detection of running in a container
DOTNET_RUNNING_IN_CONTAINER=true \
# Set the invariant mode since icu_libs isn't included (see https://github.com/dotnet/announcements/issues/20)
DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=true

ENV HASS_DAEMONAPPFOLDER /config/netdaemon

CMD [ "/daemon/Service" ]

#
# LABEL target docker image
#
ARG BUILD_DATE
ARG BUILD_REF
ARG BUILD_VERSION

# Labels
LABEL \
io.hass.name="Netdaemon" \
io.hass.description="An application daemon for c# and .NET core 3.1" \
io.hass.arch="${BUILD_ARCH}" \
io.hass.type="addon" \
io.hass.version=${BUILD_VERSION} \
maintainer="Tomas Hellström <tomas.hellstrom@yahoo.se>" \
org.label-schema.description="Netdaemon, a community add-on written in .NET core 3.1" \
org.label-schema.build-date=${BUILD_DATE} \
org.label-schema.name="Netdaemon" \
org.label-schema.schema-version="1.0" \
org.label-schema.url="https://addons.community" \
org.label-schema.usage="https://helto4real.github.io/netdaemon/" \
org.label-schema.vcs-ref=${BUILD_REF} \
org.label-schema.vcs-url="https://helto4real.github.io/netdaemon/" \
org.label-schema.vendor="Community Hass.io Addons"
6 changes: 6 additions & 0 deletions addon/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# NetDaemon addon

This is the code to build the NetDaemon Home Assistant addon. This is used for the build system. To add the addon to Home Assistant, please use https://... TODO:



9 changes: 9 additions & 0 deletions addon/build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"build_from": {
"aarch64": "hassioaddons/debian-base-aarch64:3.0.1",
"amd64": "hassioaddons/base-amd64:7.0.2",
"armhf": "hassioaddons/debian-base-armhf:3.0.1",
"armv7": "hassioaddons/debian-base-armv7:3.0.1"
},
"args": {}
}
29 changes: 29 additions & 0 deletions addon/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "NetDaemon",
"version": "dev",
"slug": "netdaemon",
"description": "Application daemon written in .NET core 3.1",
"url": "http://netdaemon.xyz",
"startup": "application",
"image": "netdaemon/homeassistant-addon-{arch}",
"arch": [
"aarch64",
"amd64",
"armhf",
"armv7"
],
"boot": "auto",
"map": [
"config:rw"
],
"hassio_api": true,
"hassio_role": "default",
"homeassistant_api": true,
"host_network": false,
"options": {
"log_level": "info"
},
"schema": {
"log_level": "match(^(trace|debug|info|warning|error)$)"
}
}
27 changes: 27 additions & 0 deletions addon/install_dotnet_dep.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Install .net core runtime deps
if [ "$BUILD_ARCH" == 'amd64' ]; then
apk update &&
apk add --no-cache \
ca-certificates \
krb5-libs \
libgcc \
libintl \
libssl1.1 \
libstdc++ \
wget \
zlib
fi

# arm 32/64 buster slim
if [ "$BUILD_ARCH" == 'armhf' ] || [ "$BUILD_ARCH" == 'armv7' ] || [ "$BUILD_ARCH" == 'aarch64' ]; then
apt-get update &&
apt-get install -y --no-install-recommends \
ca-certificates libc6 \
libgcc1 \
libgssapi-krb5-2 \
libicu63 \
libssl1.1 \
libstdc++6 \
wget \
zlib1g && rm -rf /var/lib/apt/lists/*
fi
2 changes: 1 addition & 1 deletion tests/NetDaemon.Daemon.Tests/FluentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ public async Task TimerTurnOffShouldCallCorrectServiceCall()
.TurnOff()
.Execute();

await RunDefauldDaemonUntilCanceled(200);
await RunDefauldDaemonUntilCanceled(300);

// ASSERT
DefaultHassClientMock.VerifyCallServiceTimes("turn_off", Times.AtLeast(2));
Expand Down

0 comments on commit 535ba6d

Please sign in to comment.