Skip to content

Commit

Permalink
Merge pull request #45 from lukibahr/bump/versions
Browse files Browse the repository at this point in the history
Bump/versions
  • Loading branch information
lukibahr committed Oct 10, 2023
2 parents 769bd79 + a0e676e commit 67ff562
Show file tree
Hide file tree
Showing 16 changed files with 478 additions and 689 deletions.
32 changes: 32 additions & 0 deletions .air.toml
@@ -0,0 +1,32 @@
root = "."
tmp_dir = "tmp"

[build]
bin = "./tmp/main"
cmd = "go build -o ./tmp/main ."
delay = 1000
exclude_dir = ["assets", "tmp", "vendor"]
exclude_file = []
exclude_regex = []
exclude_unchanged = false
follow_symlink = false
full_bin = ""
include_dir = []
include_ext = ["go", "tpl", "tmpl", "html"]
kill_delay = "0s"
log = "build-errors.log"
send_interrupt = false
stop_on_error = true

[color]
app = ""
build = "yellow"
main = "magenta"
runner = "green"
watcher = "cyan"

[log]
time = false

[misc]
clean_on_exit = false
37 changes: 37 additions & 0 deletions .github/workflows/ci.yaml
@@ -0,0 +1,37 @@
name: build

on:
push:
branches:
- '*'

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-go@v3
with:
go-version: '1.19.1'
check-latest: true
cache: false
- name: Run Revive Action by pulling pre-built image
uses: docker://morphy/revive-action:v2
with:
config: revive.toml
path: "./..."
- name: Cache Go modules
uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Build
run: |
go version
go mod tidy
go build
47 changes: 47 additions & 0 deletions .github/workflows/release.yaml
@@ -0,0 +1,47 @@
name: release

on:
push:
tags:
- '*'

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-go@v3
with:
go-version: '1.19.1'
check-latest: true
cache: false
- name: Cache Go modules
uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
# - name: Tests
# run: |
# go mod tidy
# go test -v ./...
-
name: Docker Login
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GH_PAT }}
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v3
if: success() && startsWith(github.ref, 'refs/tags/')
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
78 changes: 0 additions & 78 deletions .github/workflows/workflow.yml

This file was deleted.

30 changes: 28 additions & 2 deletions .goreleaser.yaml
@@ -1,17 +1,43 @@
---
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com
project_name: Prometheus-BME280-exporter
before:
hooks:
- go mod tidy
builds:
- env: [CGO_ENABLED=0]
- env:
- CGO_ENABLED=0
goos:
- linux
goarch:
- amd64
- arm64
- arm
binary: prometheus-bme280-exporter
ldflags:
- "-X 'github.com/lukibahr/Prometheus-BME280-exporter/cmd.buildVersion={{.Version}}'"
- "-X 'github.com/lukibahr/Prometheus-BME280-exporter/cmd.buildCommit={{.ShortCommit}}'"
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ incpatch .Version }}-next"
changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
- Merge pull request
- Merge branch
dockers:
- image_templates: ["ghcr.io/lukibahr/Prometheus-BME280-exporter:{{ .Version }}"]
dockerfile: Dockerfile
build_flag_templates:
- --label=org.opencontainers.image.source=github.com/lukibahr/Prometheus-BME280-exporter
- --label=org.opencontainers.image.version={{ .Version }}
- --label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }}
- --label=org.opencontainers.image.revision={{ .FullCommit }}
- --label=org.opencontainers.image.revision={{ .FullCommit }}
- --label=org.opencontainers.image.title={{ .ProjectName }}
- --label=org.opencontainers.image.description={{ .ProjectName }}
- --label=org.opencontainers.image.url=https://github.com/lukibahr/prometheus-bme280-exporter
14 changes: 6 additions & 8 deletions Dockerfile
@@ -1,9 +1,7 @@
FROM golang:1.21-alpine as builder
WORKDIR /go/src/app
COPY . /go/src/app
RUN CGO_ENABLED=0 GOARCH=arm GOARM=7 GOOS=linux go build -a -installsuffix cgo -o /go/bin/exporter .
# syntax=docker/dockerfile:1
FROM gcr.io/distroless/base

FROM alpine:3.16
COPY --from=builder /go/bin/exporter /
ENTRYPOINT ["/exporter"]
CMD [""]
LABEL maintainer="hello@lukasbahr.de"

COPY prometheus-bme280-exporter /usr/bin/prometheus-bme280-exporter
ENTRYPOINT ["/usr/bin/prometheus-bme280-exporter"]
9 changes: 9 additions & 0 deletions Dockerfile.local
@@ -0,0 +1,9 @@
FROM golang:1.21-alpine as builder
WORKDIR /go/src/app
COPY . /go/src/app
RUN CGO_ENABLED=0 GOARCH=arm GOARM=7 GOOS=linux go build -a -installsuffix cgo -o /go/bin/exporter .

FROM alpine:3.16
COPY --from=builder /go/bin/exporter /
ENTRYPOINT ["/exporter"]
CMD [""]
6 changes: 6 additions & 0 deletions Makefile
Expand Up @@ -21,3 +21,9 @@ cleanup:

index:
$(CR) index --charts-repo $(GHBASE)$(REPO)

build:
go build -o prometheus-bme280-exporter main.go

armv6:
CC=arm-linux-gnueabi-gcc GOOS=linux GOARM=6 GOARCH=arm go build -o prometheus-bme280-exporter main.go
30 changes: 26 additions & 4 deletions README.md
Expand Up @@ -8,6 +8,21 @@ A prometheus exporter for a BOSH BME280 sensor, this time, written in go :green_

VIN, GND, SCL and SDA are the notations on the sensor board of the GYBME280 sensor.

For testing, you can install `i2c-tools` with the following command: `sudo apt-get install i2c-tools` and then check with i2cdetect -y 1, if the sensor is connected to either 0x76 or 0x77 address:

```bash
$ i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- 76 --
```

## Running the exporter

After you've successfully mounted the sensor, you have to enable the I2C interface. You can either use `sudo raspi-config` and enable it in the UI or add the following to the `/boot/config.txt
Expand All @@ -23,17 +38,24 @@ dtparam=i2c1=on

A reboot of your Pi is required to take changes effect. Run the exporter with:

`docker run -it -v /dev/i2c-1:/dev/i2c-1 --privileged -p 9123:9123 lukasbahr/prometheus-bme280-exporter:74b2a86 --loglevel=info`
`docker run -it -v /dev/i2c-1:/dev/i2c-1 --privileged -p 9123:9123 lukasbahr/prometheus-bme280-exporter:74b2a86 --loglevel=info`

The privileged mode is currently required to grant access to the i2c device. Not the best solution but ad-hoc the first working one.


### Because Kubernetes is noice
For a quick-start to run the exporter in a kubernetes cluster, refer to the [kubernetes/daemonset.yaml](kubernetes/daemonset.yaml). The daemonset is configured to run on the nodes of the cluster with a nodeSelector enabled. If you've installed the sensor on all nodes, leave it empty.
For a more customizable setup, refer to the helm chart.

For a quick-start to run the exporter in a kubernetes cluster, refer to the [kubernetes/daemonset.yaml](kubernetes/daemonset.yaml). The daemonset is configured to run on the nodes of the cluster with a nodeSelector enabled. If you've installed the sensor on all nodes, leave it empty.
For a more customizable setup, refer to the helm chart.
## Further reading
- Releaser action used for releasing the charts: [https://github.com/helm/chart-releaser-action](https://github.com/helm/chart-releaser-action)
- Chart releaser used for publishing helm chart: [https://github.com/helm/chart-releaser](https://github.com/helm/chart-releaser)
## Rebiulding
- rebuilding with mqtt: <https://github.com/hessu/mqtt-bme280/blob/master/mqtt-bme280.py>
## Open ToDos
- create CI/CD Pipeline with drone
44 changes: 44 additions & 0 deletions Taskfile.yaml
@@ -0,0 +1,44 @@
# I just wanted to give taskfile.dev another try. This is optional. Get task here https://taskfile.dev/#/
# Next create a .env file

version: '3'

vars:
GOLANGCILINT:
sh: which golangci-lint
GOLANG:
sh: which go

tasks:
default:
cmds:
- task --list
silent: true

lint:
desc: Run golangci-lint on your sourcecode
preconditions:
- sh: "[ '{{.GOLANGCILINT}}' != '<no value>' ]"
msg: "golangci-lint executable not found"
cmds:
- |
golangci-lint run -v
silent: false

build:
desc: build binary
preconditions:
- sh: "[ '{{.GOLANG}}' != '<no value>' ]"
msg: "go executable not found"
cmds:
- |
GOOS=linux GOARCH=arm GOARM=7 go build
GOOS=darwin GOARCH=arm64 go build -ldflags="-X 'github.com/lukibahr/prometheus-bme280-exporter/cmd.buildVersion=v0.0.4' -X 'github.com/lukibahr/prometheus-bme280-exporter/cmd.buildCommit=$(git rev-parse --short HEAD)'" -o release/rclone-daemon-darwin-arm64 main.go
silent: false

test:
desc: Run go test on your sourcecode
cmds:
- |
go test -v
silent: false

0 comments on commit 67ff562

Please sign in to comment.