diff --git a/.github/workflows/container.yaml b/.github/workflows/container.yaml new file mode 100644 index 0000000..2556f4d --- /dev/null +++ b/.github/workflows/container.yaml @@ -0,0 +1,22 @@ +--- +name: container +on: [ push ] + +jobs: + + docker-build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: docker + run: docker build --file Dockerfile --tag ${{ github.REPOSITORY }}:${{ github.SHA }} . + - name: start image + run: docker run --rm -i ${{ github.REPOSITORY }}:${{ github.SHA }} + - name: push the image + uses: mr-smithers-excellent/docker-build-push@v4 + with: + tag: ${{ github.SHA }} + image: ${{ github.REPOSITORY }} + registry: ghcr.io + username: ${{ github.ACTOR }} # todo: are packages per repo or per user?! + password: ${{ secrets.PUSHTOKEN }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6fdc5a9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +FROM python:alpine3.12 + +RUN pip3 install mysql-connector-python +RUN mkdir /app +COPY syslogserver.py /app/syslogserver.py + + +CMD [ "python3", "/app/syslogserver.py" ] \ No newline at end of file diff --git a/syslogserver.py b/syslogserver.py index c30b863..966424c 100644 --- a/syslogserver.py +++ b/syslogserver.py @@ -1,6 +1,7 @@ import socketserver from datetime import datetime import time +import sys import mysql.connector as mariadb @@ -110,6 +111,7 @@ def handle(self): mariadb_connection = mariadb.connect(user = db_user, password = db_password, host = db_host, port = db_port) except mariadb.Error as error: print('Error: {}'.format(error)) + sys.exit() #every time a new cursor is created because the old one gets closed #in the called write_to_db function @@ -137,3 +139,5 @@ def handle(self): #handle requests until explicit shutdown(), see python docs server.serve_forever() + + sys.exit()