From e030b87eb64d5a293040d5744637768d0a2f0b18 Mon Sep 17 00:00:00 2001 From: Alex Thomae Date: Sun, 27 Sep 2020 07:15:08 +0200 Subject: [PATCH 1/5] Restructure the files and update requests from 2.22.0 to 2.24.0 --- .pylintrc | 2 +- Dockerfile | 6 +++--- build.sh | 4 ++-- {src => grafana-email}/__init__.py | 0 {src => grafana-email}/constants.py | 0 {src => grafana-email}/grafana-email.py | 23 ++++++++++++----------- {src => grafana-email}/requirements.txt | 2 +- 7 files changed, 19 insertions(+), 18 deletions(-) rename {src => grafana-email}/__init__.py (100%) rename {src => grafana-email}/constants.py (100%) rename {src => grafana-email}/grafana-email.py (88%) rename {src => grafana-email}/requirements.txt (62%) diff --git a/.pylintrc b/.pylintrc index 892e10c..a55afb4 100644 --- a/.pylintrc +++ b/.pylintrc @@ -60,7 +60,7 @@ confidence= # --enable=similarities". If you want to run only the classes checker, but have # no Warning level messages displayed, use "--disable=all --enable=classes # --disable=W". -disable=logging-format-interpolation, +disable=logging-fstring-interpolation, # too-few-public-methods, invalid-name, no-self-use, diff --git a/Dockerfile b/Dockerfile index 3a21833..b7ffbd4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,11 +2,11 @@ FROM alpine:latest LABEL maintainer="docker@ix.ai" \ ai.ix.repository="ix.ai/etherscan-exporter" -WORKDIR /app +WORKDIR /grafana-email -COPY src/ /app +COPY grafana-email/ /grafana-email RUN apk --no-cache add python3 py3-pillow py3-requests && \ pip3 install --no-cache-dir -r requirements.txt -ENTRYPOINT ["python3", "/app/grafana-email.py"] +ENTRYPOINT ["python3", "/grafana-email/grafana-email.py"] diff --git a/build.sh b/build.sh index 2f1b58c..d931bae 100644 --- a/build.sh +++ b/build.sh @@ -1,4 +1,4 @@ #!/usr/bin/env sh -echo "Setting VERSION='${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHORT_SHA}' in src/constants.py" -echo "VERSION = '${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHORT_SHA}'" >> src/constants.py +echo "Setting VERSION='${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHORT_SHA}' in grafana-email/constants.py" +echo "VERSION = '${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHORT_SHA}'" >> grafana-email/constants.py diff --git a/src/__init__.py b/grafana-email/__init__.py similarity index 100% rename from src/__init__.py rename to grafana-email/__init__.py diff --git a/src/constants.py b/grafana-email/constants.py similarity index 100% rename from src/constants.py rename to grafana-email/constants.py diff --git a/src/grafana-email.py b/grafana-email/grafana-email.py similarity index 88% rename from src/grafana-email.py rename to grafana-email/grafana-email.py index af04f27..4a04be1 100644 --- a/src/grafana-email.py +++ b/grafana-email/grafana-email.py @@ -80,9 +80,10 @@ def __init__(self): self.message['Subject'] = os.environ.get('SMTP_SUBJECT', 'Grafana Email Report') self.message['From'] = self.smtp['from'] self.message['To'] = self.smtp['to'] - LOG.debug('Panel options: {}'.format(self.panel_args)) - LOG.debug('SMTP options: {}'.format(self.smtp)) - LOG.debug('Grafana options: {}'.format(self.grafana)) + + LOG.debug(f'Panel options: {self.panel_args}') + LOG.debug(f'SMTP options: {self.smtp}') + LOG.debug(f'Grafana options: {self.grafana}') def get_panels(self): """ downloads each panel and saves it to a variable """ @@ -99,18 +100,18 @@ def get_panels(self): ) if self.grafana.get('url_params'): - uri = '{uri}?{url_params}'.format(uri=uri, url_params=self.grafana['url_params']) + uri = f'{uri}?{self.grafana["url_params"]}' - LOG.info('Setting download URI to {}'.format(uri)) + LOG.info(f'Setting download URI to {uri}') params = {} for param, arg in self.panel_args.items(): if arg: params.update({param: arg}) - headers = {'Authorization': 'Bearer {}'.format(self._token)} + headers = {'Authorization': f'Bearer {self._token}'} if self.grafana.get('header_host'): - headers.update({'Host': '{}'.format(self.grafana['header_host'])}) + headers.update({'Host': f"{self.grafana['header_host']}"}) for panel in self.grafana['panel_ids'].split(','): params['panelId'] = panel @@ -140,7 +141,7 @@ def send_email(self):

""" - html = html.replace('[[image]]', '{}_panel_{}.png'.format(host, panel)) + html = html.replace('[[image]]', f'{host}_panel_{panel}.png') html = html.replace('[[width]]', str(self.panel_args['width'])) html = html.replace('[[height]]', str(self.panel_args['height'])) html += '' @@ -150,11 +151,11 @@ def send_email(self): for panel, image in [(k, v) for x in self.panels for (k, v) in x.items()]: img = MIMEImage(image, 'png') - img.add_header('Content-ID', '<{host}_panel_{panel}.png>'.format(host=host, panel=panel)) + img.add_header('Content-ID', f'<{host}_panel_{panel}.png>') img.add_header( 'Content-Disposition', 'inline', - filename='{host}_panel_{panel}.png'.format(host=host, panel=panel) + filename=f'{host}_panel_{panel}.png', ) self.message.attach(img) @@ -177,7 +178,7 @@ def send_email(self): if __name__ == '__main__': configure_logging() # pylint: disable=no-member - LOG.info("Starting {} {}".format(FILENAME, constants.VERSION)) + LOG.info(f"Starting {FILENAME} {constants.VERSION()}") grafana = GrafanaEmail() grafana.get_panels() grafana.send_email() diff --git a/src/requirements.txt b/grafana-email/requirements.txt similarity index 62% rename from src/requirements.txt rename to grafana-email/requirements.txt index 0dde2fb..3bc235c 100644 --- a/src/requirements.txt +++ b/grafana-email/requirements.txt @@ -1,3 +1,3 @@ -requests==2.22.0 +requests==2.24.0 pygelf==0.3.6 pillow>=6.2.1 From c6b8ba65d005e29f78d5e154c92189e3ed34a6de Mon Sep 17 00:00:00 2001 From: Alex Thomae Date: Sun, 27 Sep 2020 07:16:11 +0200 Subject: [PATCH 2/5] Add `386` build --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index dfa1fb0..dba6ae1 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,6 +3,7 @@ variables: ENABLE_ARM64: 'true' ENABLE_ARMv7: 'true' ENABLE_ARMv6: 'true' + ENABLE_386: 'true' include: - project: 'ix.ai/ci-templates' From 8da0c7a496e23c669624fb9f420fa74ce6166ba5 Mon Sep 17 00:00:00 2001 From: Alex Thomae Date: Sun, 27 Sep 2020 07:16:56 +0200 Subject: [PATCH 3/5] Fix the `ai.ix.repository` label --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index b7ffbd4..e3febad 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM alpine:latest LABEL maintainer="docker@ix.ai" \ - ai.ix.repository="ix.ai/etherscan-exporter" + ai.ix.repository="ix.ai/grafana-email" WORKDIR /grafana-email From a2e6360e68c81648f7861ff3767a90d7f86b6e75 Mon Sep 17 00:00:00 2001 From: Alex Thomae Date: Sun, 27 Sep 2020 07:29:41 +0200 Subject: [PATCH 4/5] Add missing alpine dependencies and fix `constants.VERSION` --- Dockerfile | 7 +++---- grafana-email/grafana-email.py | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index e3febad..541569d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,10 +3,9 @@ LABEL maintainer="docker@ix.ai" \ ai.ix.repository="ix.ai/grafana-email" WORKDIR /grafana-email - COPY grafana-email/ /grafana-email - -RUN apk --no-cache add python3 py3-pillow py3-requests && \ - pip3 install --no-cache-dir -r requirements.txt +RUN set -xeu; \ + apk --no-cache add python3 py3-pillow py3-requests py3-pip; \ + pip install --no-cache-dir -r requirements.txt ENTRYPOINT ["python3", "/grafana-email/grafana-email.py"] diff --git a/grafana-email/grafana-email.py b/grafana-email/grafana-email.py index 4a04be1..90b5537 100644 --- a/grafana-email/grafana-email.py +++ b/grafana-email/grafana-email.py @@ -178,7 +178,7 @@ def send_email(self): if __name__ == '__main__': configure_logging() # pylint: disable=no-member - LOG.info(f"Starting {FILENAME} {constants.VERSION()}") + LOG.info(f"Starting {FILENAME} {constants.VERSION}") grafana = GrafanaEmail() grafana.get_panels() grafana.send_email() From ec3cecda8ff13b99478330cec049c88949e31b5f Mon Sep 17 00:00:00 2001 From: Alex Thomae Date: Sun, 27 Sep 2020 07:32:43 +0200 Subject: [PATCH 5/5] Prepare v0.4.0 Signed-off-by: Alex Thomae --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0f2c80c..b44ea3d 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,8 @@ [![Pipeline Status](https://gitlab.com/ix.ai/grafana-email/badges/master/pipeline.svg)](https://gitlab.com/ix.ai/grafana-email/) [![Docker Stars](https://img.shields.io/docker/stars/ixdotai/grafana-email.svg)](https://hub.docker.com/r/ixdotai/grafana-email/) [![Docker Pulls](https://img.shields.io/docker/pulls/ixdotai/grafana-email.svg)](https://hub.docker.com/r/ixdotai/grafana-email/) +[![Docker Image Version (latest)](https://img.shields.io/docker/v/ixdotai/grafana-email/latest)](https://hub.docker.com/r/ixdotai/grafana-email/) +[![Docker Image Size (latest)](https://img.shields.io/docker/image-size/ixdotai/grafana-email/latest)](https://hub.docker.com/r/ixdotai/grafana-email/) [![Gitlab Project](https://img.shields.io/badge/GitLab-Project-554488.svg)](https://gitlab.com/ix.ai/grafana-email/) Connects to Grafana and sends an e-mail with attached graphs. @@ -130,7 +132,9 @@ services: ## Tags and Arch -Starting with version v0.3.0, the images are multi-arch, with builds for amd64, arm64 and armv7. +Starting with version v0.3.0, the images are multi-arch, with builds for amd64, arm64 and armv7. Version v0.4.0 also +adds 386 build. + * `vN.N.N` - for example v0.3.0 * `latest` - always pointing to the latest version * `dev-master` - the last build on the master branch