Skip to content

Commit

Permalink
Merge branch 'feature/multiplatform'
Browse files Browse the repository at this point in the history
  • Loading branch information
Anze committed Nov 19, 2020
2 parents 0c16c3e + 3a3f4af commit 648ed67
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 13 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -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=
Expand Down
22 changes: 16 additions & 6 deletions .github/workflows/on_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,33 @@ 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 }}
DOCKER_REGISTRY: docker.io
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') .
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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}/ && \
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions snmpbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)


Expand Down

0 comments on commit 648ed67

Please sign in to comment.