From 700dac3e33d597ca893405dab9cf8d1510b05e1d Mon Sep 17 00:00:00 2001 From: Anze Date: Tue, 10 Nov 2020 21:10:53 +0100 Subject: [PATCH 1/6] Multiplatform build --- .github/workflows/on_release.yml | 22 ++++++++++++++++------ Dockerfile | 4 ++-- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/.github/workflows/on_release.yml b/.github/workflows/on_release.yml index de37545..db7b91a 100644 --- a/.github/workflows/on_release.yml +++ b/.github/workflows/on_release.yml @@ -13,8 +13,18 @@ jobs: - name: Checkout source code uses: actions/checkout@v1 + - name: Set up QEMU for more platforms + uses: docker/setup-qemu-action@v1 + with: + platforms: all - - name: Deploy to Docker Hub + - name: Set docker build as alias to buildx (multiarch build) + uses: docker/setup-buildx-action@v1 + id: buildx + with: + install: false + + - name: Deploy to Docker Hub - ARMv7 if: success() && startsWith(github.ref, 'refs/tags/v') env: GITHUB_REF_TAG: ${{ github.ref }} @@ -22,14 +32,14 @@ jobs: DOCKER_IMAGE: grafolean/grafolean-snmp-bot DOCKER_USER: grafolean DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + BUILD_PLATFORMS: linux/amd64,linux/arm/v7,linux/arm64 run: | + echo "Available plaftorms: ${{ steps.buildx.outputs.platforms }}" + echo "Building for plaftorms: $BUILD_PLATFORMS" export VERSION=${GITHUB_REF_TAG:10:50} echo "Version is $VERSION" export LAST_KNOWN_VERSION=`git tag -l --sort=-version:refname "v*.*.*" | grep -v rc | head -n 1 | tr -d '[:space:]'` echo "Last known version is $LAST_KNOWN_VERSION" docker login -u $DOCKER_USER -p $DOCKER_PASSWORD $DOCKER_REGISTRY - docker build -t "docker.io/$DOCKER_IMAGE:$VERSION" -t "docker.io/$DOCKER_IMAGE:latest" --build-arg VERSION=$VERSION --build-arg VCS_REF=$GITHUB_SHA --build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') . - [ "$LAST_KNOWN_VERSION" == "$VERSION" ] && docker tag "docker.io/$DOCKER_IMAGE:$VERSION" "docker.io/$DOCKER_IMAGE:latest" || echo "NOT MARKING AS LATEST!" - docker images - docker push "docker.io/$DOCKER_IMAGE:$VERSION" - [ "$LAST_KNOWN_VERSION" == "$VERSION" ] && docker push "docker.io/$DOCKER_IMAGE:latest" || echo "NOT LATEST!" + [ "$LAST_KNOWN_VERSION" == "$VERSION" ] && echo "MARKING AS LATEST!" || echo "NOT MARKING AS LATEST!" + [ "$LAST_KNOWN_VERSION" == "$VERSION" ] && docker buildx build --push --platform "$BUILD_PLATFORMS" -t "docker.io/$DOCKER_IMAGE:$VERSION" -t "docker.io/$DOCKER_IMAGE:latest" --build-arg VERSION=$VERSION --build-arg VCS_REF=$GITHUB_SHA --build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') . || docker buildx build --push --platform "$BUILD_PLATFORMS" -t "docker.io/$DOCKER_IMAGE:$VERSION" --build-arg VERSION=$VERSION --build-arg VCS_REF=$GITHUB_SHA --build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') . diff --git a/Dockerfile b/Dockerfile index 52d0745..3bf3b63 100644 --- a/Dockerfile +++ b/Dockerfile @@ -31,9 +31,9 @@ LABEL org.label-schema.vendor="Grafolean" \ COPY --from=python-requirements /requirements.txt /requirements.txt RUN \ apt-get update && \ - apt-get install --no-install-recommends -q -y libsnmp-dev build-essential git && \ + apt-get install --no-install-recommends -q -y libsnmp-dev build-essential libpq-dev python3-dev git && \ pip install --no-cache-dir -r /requirements.txt && \ - apt-get purge -y build-essential && \ + apt-get purge -y build-essential libpq-dev python3-dev && \ apt-get clean autoclean && \ apt-get autoremove --yes && \ rm -rf /var/lib/{apt,dpkg,cache,log}/ && \ From 9ceb951b5c5a4fde888b73b8bb09b9039e25c4cd Mon Sep 17 00:00:00 2001 From: Anze Date: Wed, 18 Nov 2020 21:00:24 +0100 Subject: [PATCH 2/6] Update .env.example --- .env.example | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index c80139b..d64cf73 100644 --- a/.env.example +++ b/.env.example @@ -1,7 +1,8 @@ -BACKEND_URL=https://grafolean.com/api +BACKEND_URL=https://app.grafolean.com/api BOT_TOKEN= JOBS_REFRESH_INTERVAL=120 DB_DIR= +# only matters if database is not started via docker-compose: DB_HOST= DB_DATABASE= DB_USERNAME= From 03e9541c10019352c5a4befa0fc40937430a94e0 Mon Sep 17 00:00:00 2001 From: Anze Date: Wed, 18 Nov 2020 21:01:12 +0100 Subject: [PATCH 3/6] Add SNMP tools by default --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 3bf3b63..a26e7a7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -31,7 +31,7 @@ LABEL org.label-schema.vendor="Grafolean" \ COPY --from=python-requirements /requirements.txt /requirements.txt RUN \ apt-get update && \ - apt-get install --no-install-recommends -q -y libsnmp-dev build-essential libpq-dev python3-dev git && \ + apt-get install --no-install-recommends -q -y libsnmp-dev build-essential libpq-dev python3-dev git snmp && \ pip install --no-cache-dir -r /requirements.txt && \ apt-get purge -y build-essential libpq-dev python3-dev && \ apt-get clean autoclean && \ From 5b634b3c4f1d576641e5d51e2105a2ab9bda4708 Mon Sep 17 00:00:00 2001 From: Anze Date: Wed, 18 Nov 2020 21:02:34 +0100 Subject: [PATCH 4/6] Use TimescaleDB instead of base PostgreSQL --- docker-compose.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index ab27071..f606f9b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -36,7 +36,7 @@ services: db: - image: postgres:12.1-alpine + image: timescale/timescaledb:latest-pg12 container_name: grafolean-snmp-db volumes: # You should always save DB data to a host directory unless you are prepared to lose it. By default @@ -50,7 +50,7 @@ services: - POSTGRES_PASSWORD=${DB_PASS:-admin} restart: always healthcheck: - test: ["CMD-SHELL", "pg_isready -h db -t 1 -q"] + test: ["CMD-SHELL", "pg_isready -h db -U ${DB_USER:-admin} -t 1 -q"] interval: 10s timeout: 5s retries: 3 From 1f622b7ba09c885e33e75ad960c093c4e6e4ff2c Mon Sep 17 00:00:00 2001 From: Anze Date: Wed, 18 Nov 2020 21:03:18 +0100 Subject: [PATCH 5/6] Display URL in log while waiting for Grafolean --- snmpbot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/snmpbot.py b/snmpbot.py index 5636164..b1632a8 100644 --- a/snmpbot.py +++ b/snmpbot.py @@ -428,8 +428,8 @@ def jobs(self): def wait_for_grafolean(backend_url): + url = '{}/status/info'.format(backend_url) while True: - url = '{}/status/info'.format(backend_url) log.info("Checking Grafolean status...") try: r = requests.get(url) @@ -440,7 +440,7 @@ def wait_for_grafolean(backend_url): return except: pass - log.info("Grafolean backend not available / initialized yet, waiting.") + log.info(f"Grafolean backend (url: {url}) not available / initialized yet, waiting.") time.sleep(10) From 3a3f4af4e4a9ff8449324c506ef8ca4a53d791a7 Mon Sep 17 00:00:00 2001 From: Anze Date: Wed, 18 Nov 2020 21:15:09 +0100 Subject: [PATCH 6/6] Fix GitHub Action name --- .github/workflows/on_release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/on_release.yml b/.github/workflows/on_release.yml index db7b91a..bf2b83b 100644 --- a/.github/workflows/on_release.yml +++ b/.github/workflows/on_release.yml @@ -24,7 +24,7 @@ jobs: with: install: false - - name: Deploy to Docker Hub - ARMv7 + - name: Deploy to Docker Hub - multiplatform if: success() && startsWith(github.ref, 'refs/tags/v') env: GITHUB_REF_TAG: ${{ github.ref }}