From d9a33adb3b90ccbfc1ed1b30b8ec6dbf38b6e982 Mon Sep 17 00:00:00 2001 From: Sylvain Maucourt Date: Tue, 15 Aug 2023 20:18:36 +0200 Subject: [PATCH] first try (#13) --- .github/workflows/create-docker-exporter.yml | 23 ++++++++++++++++++++ exporter/Dockerfile | 4 ++++ exporter/main.rb | 11 ++++++++++ 3 files changed, 38 insertions(+) create mode 100644 .github/workflows/create-docker-exporter.yml create mode 100644 exporter/Dockerfile create mode 100644 exporter/main.rb diff --git a/.github/workflows/create-docker-exporter.yml b/.github/workflows/create-docker-exporter.yml new file mode 100644 index 0000000..b60cc8b --- /dev/null +++ b/.github/workflows/create-docker-exporter.yml @@ -0,0 +1,23 @@ +name: create docker exporter +on: + workflow_dispatch: + branches: + - master +jobs: + create-docker-bridge: + name: create docker Domotik Exporter + runs-on: ubuntu-latest + steps: + - uses: docker/setup-qemu-action@v2 + - uses: docker/setup-buildx-action@v2 + - uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - uses: docker/build-push-action@v2 + with: + context: '{{defaultContext}}:exporter' + push: true + platforms: linux/amd64,linux/arm64 + tags: ghcr.io/sylvek/domotik-exporter:latest diff --git a/exporter/Dockerfile b/exporter/Dockerfile new file mode 100644 index 0000000..292bc94 --- /dev/null +++ b/exporter/Dockerfile @@ -0,0 +1,4 @@ +FROM ruby:slim +RUN gem install sqlite3 httparty +COPY main.rb /main.rb +CMD ["ruby", "main.rb"] \ No newline at end of file diff --git a/exporter/main.rb b/exporter/main.rb new file mode 100644 index 0000000..3ea3dd7 --- /dev/null +++ b/exporter/main.rb @@ -0,0 +1,11 @@ +require 'sqlite3' +require 'httparty' + +entrypoint = ENV['ENTRYPOINT'] +db = SQLite3::Database.new ENV['DATABASE'] + +db.execute("SELECT ts,value FROM data WHERE name='daily_power_consumption' ORDER BY ts DESC LIMIT 1") do |row| + title = "#{row[1].to_i/1000.0} kW.h" + response = HTTParty.get("#{entrypoint}?title=#{title}×tamp=#{row[0]}") + puts response.body +end \ No newline at end of file