Skip to content

Commit

Permalink
fix: cron env var from config file
Browse files Browse the repository at this point in the history
  • Loading branch information
Dim145 committed May 29, 2024
1 parent 6fe29e6 commit 0f04b84
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ RUN dotnet publish "Hariane2Mqtt.csproj" -c $BUILD_CONFIGURATION -o /app/publish

FROM mcr.microsoft.com/dotnet/runtime-deps:8.0-alpine AS final
WORKDIR /app

RUN apk add libc6-compat

COPY --from=publish /app/publish .

COPY entrypoint.sh /entrypoint.sh

RUN chmod +x /entrypoint.sh
RUN chmod -R +x /entrypoint.sh /app

CMD ["/entrypoint.sh"]
2 changes: 1 addition & 1 deletion addon/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ CMD ["/entrypoint.sh"]
############

LABEL \
io.hass.version="0.1.1" \
io.hass.version="0.1.3" \
io.hass.type="addon" \
io.hass.arch="armv7|amd64|arm64"
2 changes: 1 addition & 1 deletion addon/config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: "Hariane 2 MQTT"
description: "Extracts Hariane water data into MQTT a.o."
version: 0.1.1
version: 0.1.3
slug: "hariane_2_mqtt"
url: https://github.com/Dim145/Hariane2Mqtt
init: true
Expand Down
15 changes: 10 additions & 5 deletions addon/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,26 @@ if [ ! -d /config ]; then
fi

# Default location
CONFIGSOURCE="/config/gazpar_2_mqtt/config.yaml"
CONFIGSOURCE="/config/hariane_2_mqtt/config.yaml"

mkdir -p /config/gazpar_2_mqtt
mkdir -p /config/hariane_2_mqtt

cat /config/hariane_2_mqtt/config.yaml

# transform each config.yaml entries to env variables
if [ -f $CONFIGSOURCE ]; then
echo "Loading config from $CONFIGSOURCE"
while IFS=': ' read -r key value
do
if [ ! -z "$key" ] && [ ! -z "$value" ]; then
key=$(echo $key | tr '[:lower:]' '[:upper:]' | tr '-' '_' | tr '.' '_')
value=$(echo $value | sed 's/^ *//g' | sed 's/ *$//g')
key=$(echo "$key" | tr '[:lower:]' '[:upper:]' | tr '-' '_' | tr '.' '_')
value=$(echo "$value" | sed 's/^ *//g' | sed 's/ *$//g')

# add to env for cron jobs
export $key=$value
export "$key=$value"

# append to .env file
echo "export $key=$value;" >> /.env
fi
done < $CONFIGSOURCE
fi
Expand Down
4 changes: 2 additions & 2 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/ash

if [ -z "$CRON" ]; then
echo "CRON is not set. Exiting."
Expand All @@ -7,6 +7,6 @@ fi

echo "$CRON"

echo "$CRON /app/Hariane2Mqtt > /dev/stdout 2> /dev/stdout" > /etc/crontabs/root
echo "$CRON ASH_ENV=/.env /app/Hariane2Mqtt > /dev/stdout 2> /dev/stdout" > /etc/crontabs/root

crond -f -L /dev/stdout

0 comments on commit 0f04b84

Please sign in to comment.