mirror of
https://github.com/FAUSheppy/icinga-webhook-gateway
synced 2025-12-06 07:21:38 +01:00
feat: docker build & config dir
This commit is contained in:
37
.github/workflows/main.yaml
vendored
Normal file
37
.github/workflows/main.yaml
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
name: ci
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- "master"
|
||||
|
||||
jobs:
|
||||
docker:
|
||||
runs-on: ubuntu-latest
|
||||
environment:
|
||||
name: prod
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
-
|
||||
name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v2
|
||||
-
|
||||
name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v2
|
||||
-
|
||||
name: Login to Docker Registry
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
registry: ${{ secrets.REGISTRY }}
|
||||
username: ${{ secrets.REGISTRY_USER }}
|
||||
password: ${{ secrets.REGISTRY_PASS }}
|
||||
-
|
||||
name: Build and push async-icinga image
|
||||
uses: docker/build-push-action@v3
|
||||
with:
|
||||
context: .
|
||||
platforms: linux/amd64
|
||||
push: true
|
||||
tags: "${{ secrets.REGISTRY }}/athq/async-icinga:latest"
|
||||
19
Dockerfile
Normal file
19
Dockerfile
Normal file
@@ -0,0 +1,19 @@
|
||||
FROM python:3.9-slim-buster
|
||||
|
||||
RUN apt update
|
||||
RUN apt install python3-pip git curl -y
|
||||
RUN python3 -m pip install waitress
|
||||
RUN python3 -m pip install --upgrade pip
|
||||
|
||||
WORKDIR /app
|
||||
COPY ./ .
|
||||
|
||||
RUN python3 -m pip install --no-cache-dir -r req.txt
|
||||
|
||||
#HEALTHCHECK --interval=5m --timeout=5s CMD /usr/bin/curl http://localhost:5000/ || exit 1
|
||||
EXPOSE 5000/tcp
|
||||
|
||||
RUN apt remove git -y
|
||||
RUN apt autoremove -y
|
||||
|
||||
CMD waitress-serve --host 0.0.0.0 --port 5000 --call 'app:createApp'
|
||||
24
server.py
24
server.py
@@ -6,6 +6,7 @@ import argparse
|
||||
import os
|
||||
import datetime
|
||||
import pytimeparse.timeparse as timeparse
|
||||
import sys
|
||||
|
||||
from sqlalchemy import Column, Integer, String, Boolean, or_, and_
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
@@ -18,6 +19,7 @@ from sqlalchemy.sql.expression import func
|
||||
app = flask.Flask("Icinga Report In Gateway")
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.sqlite'
|
||||
app.config['JSON_CONFIG_FILE'] = 'services.json'
|
||||
app.config['JSON_CONFIG_DIR'] = 'config'
|
||||
db = SQLAlchemy(app)
|
||||
|
||||
class Service(db.Model):
|
||||
@@ -67,6 +69,11 @@ def alive():
|
||||
# simple location for icinga alive checks via HTTP #
|
||||
return ("", 204)
|
||||
|
||||
@app.route('/reload-configuration')
|
||||
def reload():
|
||||
init()
|
||||
return ("", 204)
|
||||
|
||||
@app.route('/', methods=["GET", "POST"])
|
||||
def default():
|
||||
if flask.request.method == "GET":
|
||||
@@ -152,14 +159,29 @@ def default():
|
||||
|
||||
@app.before_first_request
|
||||
def init():
|
||||
|
||||
db.create_all()
|
||||
config = {}
|
||||
|
||||
if os.path.isfile(app.config["JSON_CONFIG_FILE"]):
|
||||
with open(app.config["JSON_CONFIG_FILE"]) as f:
|
||||
config = json.load(f)
|
||||
config |= json.load(f)
|
||||
elif os.path.isdir(app.config["JSON_CONFIG_DIR"]):
|
||||
for fname in os.listdir(app.config["JSON_CONFIG_DIR"]):
|
||||
fullpath = os.path.join(app.config["JSON_CONFIG_DIR"], fname)
|
||||
if fname.endswith(".json"):
|
||||
with open(fullpath) as f:
|
||||
config |= json.load(f)
|
||||
|
||||
if not config:
|
||||
raise ValueError("No valid configuration found - need at least one service")
|
||||
|
||||
for key in config:
|
||||
timeout = timeparse.timeparse(config[key]["timeout"])
|
||||
db.session.merge(Service(service=key, token=config[key]["token"], timeout=timeout))
|
||||
db.session.commit()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
parser = argparse.ArgumentParser(description='Start THS-Contract Locations')
|
||||
|
||||
Reference in New Issue
Block a user