Bunch of tweaks (#1)

* 🚑 Fix GitLab CI to have the right base images

* ✏️ Docs cleanup

* 👕 Dockerfile tweaks

* 🔥 Remove unused variable from proemetheus init

* 👕 Prettier on JSON & YAML files

* 👕 Other minor styling

* 🔥 Removal of disabled shellcheck rule

* 👕 Fix shellcheck linter warning

* ✏️ Small tweak to Python code

* 🔨 Reduce resulting image with 68Mb
This commit is contained in:
Franck Nijhof 2020-07-26 20:47:36 +02:00 committed by GitHub
parent 84b7286ef5
commit 5158849871
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 43 additions and 39 deletions

View file

@ -9,6 +9,6 @@ variables:
ADDON_ARMHF: "false" ADDON_ARMHF: "false"
ADDON_I386: "false" ADDON_I386: "false"
ADDON_AARCH64_BASE: "hassioaddons/base-aarch64:3.2.1" ADDON_AARCH64_BASE: "hassioaddons/base-aarch64:8.0.1"
ADDON_AMD64_BASE: "hassioaddons/base-amd64:3.2.1" ADDON_AMD64_BASE: "hassioaddons/base-amd64:8.0.1"
ADDON_ARMV7_BASE: "hassioaddons/base-armv7:3.2.1" ADDON_ARMV7_BASE: "hassioaddons/base-armv7:8.0.1"

View file

@ -104,8 +104,6 @@ SOFTWARE.
[forum-shield]: https://img.shields.io/badge/community-forum-brightgreen.svg [forum-shield]: https://img.shields.io/badge/community-forum-brightgreen.svg
[forum]: https://example.net [forum]: https://example.net
[mjrider]: https://github.com/mjrider [mjrider]: https://github.com/mjrider
[github-sponsors-shield]: https://frenck.dev/wp-content/uploads/2019/12/github_sponsor.png
[github-sponsors]: https://github.com/sponsors/frenck
[gitlabci-shield]: https://gitlab.com/hassio-addons/addon-prometheus/badges/master/pipeline.svg [gitlabci-shield]: https://gitlab.com/hassio-addons/addon-prometheus/badges/master/pipeline.svg
[gitlabci]: https://gitlab.com/hassio-addons/addon-prometheus/pipelines [gitlabci]: https://gitlab.com/hassio-addons/addon-prometheus/pipelines
[i386-shield]: https://img.shields.io/badge/i386-no-red.svg [i386-shield]: https://img.shields.io/badge/i386-no-red.svg

View file

@ -36,17 +36,17 @@ static_configs:
**Note**: _This is just an example, don't copy and paste it! Create your own!_ **Note**: _This is just an example, don't copy and paste it! Create your own!_
The job names `home-assistant` and `prometheus` are already defined by default. The job names `home-assistant` and `prometheus` are already defined by default.
Rules can be created under /share/prometheus/rules/ Rules can be created under `/share/prometheus/rules/`
The addon will reload the configuration if a valid configuration is available. If not it will log errors in the addon log The addon will reload the configuration if a valid configuration is available.
If not it will log errors in the addon log
## Known issues and limitations ## Known issues and limitations
* Job name must be unique, but this has to be enforced by the user. - Job name must be unique, but this has to be enforced by the user.
* no alert manager yet - no alert manager yet
## Changelog & Releases ## Changelog & Releases
@ -88,7 +88,7 @@ check [the contributor's page][contributors].
MIT License MIT License
Copyright (c) 2018-2020 Franck Nijhof Copyright (c) 2020-2020 Robbert Müller
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View file

@ -16,12 +16,19 @@ RUN \
ARCH="${BUILD_ARCH}" \ ARCH="${BUILD_ARCH}" \
&& if [ "${BUILD_ARCH}" = "aarch64" ]; then ARCH="arm64"; fi \ && if [ "${BUILD_ARCH}" = "aarch64" ]; then ARCH="arm64"; fi \
\ \
&& apk update \ && apk --no-cache add \
&& apk --no-cache add python3 py3-idna py3-certifi py3-chardet py3-yaml py3-urllib3 py3-requests \ python3 \
&& apk --no-cache add --virtual builddeps py-pip \ py3-idna \
py3-certifi \
py3-chardet \
py3-yaml \
py3-urllib3 \
py3-requests \
&& apk --no-cache add --virtual .builddeps \
py-pip \
\ \
&& curl -J -L -o /tmp/prometheus.tar.gz \ && curl -J -L -o /tmp/prometheus.tar.gz \
https://github.com/prometheus/prometheus/releases/download/v${PROMETHEUS_VERSION}/prometheus-${PROMETHEUS_VERSION}.linux-${ARCH}.tar.gz \ "https://github.com/prometheus/prometheus/releases/download/v${PROMETHEUS_VERSION}/prometheus-${PROMETHEUS_VERSION}.linux-${ARCH}.tar.gz" \
&& adduser -s /bin/false -D -H prometheus \ && adduser -s /bin/false -D -H prometheus \
&& cd /tmp \ && cd /tmp \
&& tar -xvf /tmp/prometheus.tar.gz \ && tar -xvf /tmp/prometheus.tar.gz \
@ -32,8 +39,15 @@ RUN \
&& cp -R prometheus-${PROMETHEUS_VERSION}.linux-${ARCH}/consoles/ /etc/prometheus/ \ && cp -R prometheus-${PROMETHEUS_VERSION}.linux-${ARCH}/consoles/ /etc/prometheus/ \
&& rm -r prometheus-${PROMETHEUS_VERSION}.linux-${ARCH} \ && rm -r prometheus-${PROMETHEUS_VERSION}.linux-${ARCH} \
&& chown -R prometheus:prometheus /etc/prometheus \ && chown -R prometheus:prometheus /etc/prometheus \
&& pip3 install -r /opt/prometheus-configgen/requirements.txt \ && pip3 install \
&& apk del builddeps --no-cache-dir \
--prefer-binary \
--find-links "https://wheels.home-assistant.io/alpine-3.12/${BUILD_ARCH}/" \
-r /opt/prometheus-configgen/requirements.txt \
\
&& apk --no-cache del .builddeps \
&& rm -f -r \
/tmp/*
# Build arguments # Build arguments
ARG BUILD_DATE ARG BUILD_DATE

View file

@ -16,14 +16,12 @@
"homeassistant_api": true, "homeassistant_api": true,
"hassio_role": "default", "hassio_role": "default",
"map": ["share:rw"], "map": ["share:rw"],
"options": { "options": {},
},
"ports": { "ports": {
"9090/tcp": null "9090/tcp": null
}, },
"ports_description": { "ports_description": {
"9090/tcp": "Not required for Ingress" "9090/tcp": "Not required for Ingress"
}, },
"schema": { "schema": {}
}
} }

View file

@ -3,7 +3,4 @@
# Home Assistant Community Add-on: Prometheus # Home Assistant Community Add-on: Prometheus
# Configures Prometheus # Configures Prometheus
# ============================================================================== # ==============================================================================
readonly CONFIG="/etc/prometheus/prometheus.yml"
echo "${HASSIO_TOKEN}" > '/run/home-assistant.token' echo "${HASSIO_TOKEN}" > '/run/home-assistant.token'

View file

@ -21,20 +21,20 @@ rule_files:
# Here it's Prometheus itself. # Here it's Prometheus itself.
scrape_configs: scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config. # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'prometheus' - job_name: "prometheus"
# metrics_path defaults to '/metrics' # metrics_path defaults to '/metrics'
# scheme defaults to 'http'. # scheme defaults to 'http'.
static_configs: static_configs:
- targets: ['localhost:9090'] - targets: ["localhost:9090"]
- job_name: 'home-assistant' - job_name: "home-assistant"
scrape_interval: 60s scrape_interval: 60s
metrics_path: /core/api/prometheus metrics_path: /core/api/prometheus
# Long-Lived Access Token # Long-Lived Access Token
bearer_token_file: '/run/home-assistant.token' bearer_token_file: "/run/home-assistant.token"
scheme: http scheme: http
static_configs: static_configs:
- targets: ['supervisor:80'] - targets: ["supervisor:80"]

View file

@ -1,6 +1,4 @@
#!/usr/bin/with-contenv bashio #!/usr/bin/with-contenv bashio
# shellcheck disable=SC2191
bashio::log.info 'Starting prometheus config generator...' bashio::log.info 'Starting prometheus config generator...'
if [[ ! -d /share/promethus/targets ]] ; then if [[ ! -d /share/promethus/targets ]] ; then
@ -8,7 +6,8 @@ if [[ ! -d /share/promethus/targets ]] ; then
chown -R prometheus:prometheus /share/prometheus/targets chown -R prometheus:prometheus /share/prometheus/targets
fi fi
cd /opt/prometheus-configgen cd /opt/prometheus-configgen || bashio::exit.nok \
"Could not change working directory for prometheus-configgen."
# Run Prometheus # Run Prometheus
exec s6-setuidgid prometheus python3 combiner exec s6-setuidgid prometheus python3 combiner

View file

@ -39,7 +39,7 @@ def testConfig(config):
except: except:
print("Failed to validate") print("Failed to validate")
raise raise
if result == False: if not result:
raise Exception("validation error") raise Exception("validation error")
return result return result
@ -51,7 +51,6 @@ def writeConfig(config, file):
r = requests.post(url="http://localhost:9090/-/reload", data={}) r = requests.post(url="http://localhost:9090/-/reload", data={})
except: except:
print("Exception") print("Exception")
pass
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()

View file

@ -1,5 +1,4 @@
PyYAML>=5.3.1
pyyaml-include>=1.2
requests>=2.23.0
aionotify aionotify
pyyaml-include>=1.2
PyYAML>=5.3.1
requests>=2.23.0