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= diff --git a/.github/workflows/on_release.yml b/.github/workflows/on_release.yml index de37545..bf2b83b 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 - multiplatform 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..a26e7a7 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 snmp && \ 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}/ && \ 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 diff --git a/snmpbot.py b/snmpbot.py index 2e742c0..754412f 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)