diff --git a/.gitignore b/.gitignore index 097f5c9..57612dd 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,3 @@ configuration-production.yaml .env -run-docker.sh diff --git a/microservices/weather/.env b/microservices/weather/.env index d98824c..d3c36eb 100644 --- a/microservices/weather/.env +++ b/microservices/weather/.env @@ -1,6 +1,6 @@ -weather_weather_api_base_url=https://api.openweathermap.org/data/2.5/weather -weather_weather_api_key=4ce897f7ce77f84919fd990cc68d9d20 -weather_influx_db_base_url=http://192.168.1.44:8092 -weather_influx_db_token=R1BGVaxWrX_ySaovweRz6ZTBDvHa5omQkricJGmn3PrI44jpfU7411PSmHOCjGcNR7OcBjmtE9gA62boHHXoKg== -weather_latitude=50.854019 -weather_longitude=3.355230 +weather_weather_api_base_url= +weather_weather_api_key= +weather_influx_db_base_url= +weather_influx_db_token= +weather_latitude= +weather_longitude= diff --git a/microservices/weather/Dockerfile b/microservices/weather/Dockerfile index 7369127..ad5ed6f 100644 --- a/microservices/weather/Dockerfile +++ b/microservices/weather/Dockerfile @@ -1,4 +1,4 @@ -FROM rust:1.67 as builder +FROM rust:1.71 as builder WORKDIR /usr/src/weather COPY . . RUN cargo install --path . diff --git a/microservices/weather/build-docker.sh b/microservices/weather/build-docker.sh deleted file mode 100755 index 34d3345..0000000 --- a/microservices/weather/build-docker.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash - -docker build . -t weather-microservice:latest -docker tag weather-microservice:latest registry.willemserruys.com/weather-microservice:latest -docker push registry.willemserruys.com/weather-microservice:latest diff --git a/microservices/weather/run-docker.sh b/microservices/weather/run-docker.sh deleted file mode 100755 index a9ea35c..0000000 --- a/microservices/weather/run-docker.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash -file=/home/willem/repos/homeAutomation/microservices/weather/logs.$(date "+%F").txt - -docker run --env RUST_LOG=info --env-file /home/willem/repos/homeAutomation/microservices/weather/.env registry.willemserruys.com/weather-microservice:latest &>> $file diff --git a/microservices/weather/scripts/build-docker.sh b/microservices/weather/scripts/build-docker.sh new file mode 100755 index 0000000..1b7895a --- /dev/null +++ b/microservices/weather/scripts/build-docker.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +docker build ../ -t weather-service:latest diff --git a/microservices/weather/scripts/install.sh b/microservices/weather/scripts/install.sh new file mode 100755 index 0000000..d5081f4 --- /dev/null +++ b/microservices/weather/scripts/install.sh @@ -0,0 +1,21 @@ +#!/usr/bin/bash + +# This script should be run as root +# Build and install weather service + +./build-docker.sh + +ln -s $HOME/repos/homeAutomation/microservices/weather/run-docker.sh /usr/bin/weather-service + +cp weather.service /etc/systemd/system/ +cp weather.timer /etc/systemd/system/ + +systemctl daemon-reload + +systemctl enable weather.service +systemctl enable weather.timer + +systemctl start weather.service +systemctl start weather.timer + + diff --git a/microservices/weather/scripts/run-docker.sh b/microservices/weather/scripts/run-docker.sh new file mode 100755 index 0000000..ac6e739 --- /dev/null +++ b/microservices/weather/scripts/run-docker.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +# Make sure the weather-service-image exists locally (e.g. by running the build-docker script) +docker run --env RUST_LOG=info --env-file /home/pi/repos/homeAutomation/microservices/weather/.env.production weather-service:latest diff --git a/microservices/weather/scripts/weather.service b/microservices/weather/scripts/weather.service new file mode 100644 index 0000000..7378f4e --- /dev/null +++ b/microservices/weather/scripts/weather.service @@ -0,0 +1,8 @@ +[Unit] +Description=Weather Service + +[Service] +ExecStart=/usr/bin/weather-service + +[Install] +WantedBy=multi-user.target diff --git a/microservices/weather/scripts/weather.timer b/microservices/weather/scripts/weather.timer new file mode 100644 index 0000000..b274785 --- /dev/null +++ b/microservices/weather/scripts/weather.timer @@ -0,0 +1,8 @@ +[Unit] +Description=Run weather service each 2 minutes + +[Timer] +OnCalendar=*:0/2 + +[Install] +WantedBy=timers.target