feat: docker build & config dir

This commit is contained in:
2023-01-05 19:35:09 +01:00
parent 090d753177
commit 7e118c37f5
4 changed files with 86 additions and 5 deletions

37
.github/workflows/main.yaml vendored Normal file
View 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
View 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'

3
req.txt Normal file
View File

@@ -0,0 +1,3 @@
pytimeparse
flask
flask-sqlalchemy

View File

@@ -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')