From b5b1b87b8d56e4e2784673bf18051e0a8e863b37 Mon Sep 17 00:00:00 2001 From: Alexander Koehler Date: Fri, 2 Oct 2020 20:52:34 +0200 Subject: [PATCH 1/8] add proper exit code if script fails. makes it easier to wrap this in container --- syslogserver.py | 4 ++++ 1 file changed, 4 insertions(+) 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() From 5b44491dd6a8d58ce7dc58b32ca31b49b6d49126 Mon Sep 17 00:00:00 2001 From: Alexander Koehler Date: Fri, 2 Oct 2020 20:57:42 +0200 Subject: [PATCH 2/8] add github action workflow to build a docker image and push it to the ghcr.io --- .github/workflows/docker.yaml | 20 ++++++++++++++++++++ Dockerfile | 8 ++++++++ 2 files changed, 28 insertions(+) create mode 100644 .github/workflows/docker.yaml create mode 100644 Dockerfile diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml new file mode 100644 index 0000000..160e2dd --- /dev/null +++ b/.github/workflows/docker.yaml @@ -0,0 +1,20 @@ +--- +name: docker +on: [ push ] + +jobs: + + docker-build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: docker + run: docker build --file Dockerfile --tag ${{ github.GITHUB_REPOSITORY }}:${{ github.SHA }} . + - name: push the image + uses: mr-smithers-excellent/docker-build-push@v4 + with: + tag: ${{ github.GITHUB_REF }} + image: ${{ github.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 From 67233757e3185a627d565652b331b80710f82552 Mon Sep 17 00:00:00 2001 From: Alexander Koehler Date: Fri, 2 Oct 2020 21:05:39 +0200 Subject: [PATCH 3/8] added debug message, changed image tagging --- .github/workflows/docker.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 160e2dd..56b6357 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -8,8 +8,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 + - name: print commit sha + run: echo ${{ github.GITHUB_REPOSITORY }} - name: docker - run: docker build --file Dockerfile --tag ${{ github.GITHUB_REPOSITORY }}:${{ github.SHA }} . + run: docker build --file Dockerfile --tag temp/temp:${{ github.GITHUB_REF }} . - name: push the image uses: mr-smithers-excellent/docker-build-push@v4 with: From 31e9555e3e9b8fabc8f35ab8dc94fb22d5f317ab Mon Sep 17 00:00:00 2001 From: Alexander Koehler Date: Fri, 2 Oct 2020 21:10:42 +0200 Subject: [PATCH 4/8] added debug message, changed image tagging --- .github/workflows/docker.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 56b6357..de26f60 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -8,10 +8,12 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - - name: print commit sha + - name: debug + run: echo ${{ github.GITHUB_REF }} + - name: debug run: echo ${{ github.GITHUB_REPOSITORY }} - name: docker - run: docker build --file Dockerfile --tag temp/temp:${{ github.GITHUB_REF }} . + run: docker build --file Dockerfile --tag temp/temp:latest . - name: push the image uses: mr-smithers-excellent/docker-build-push@v4 with: From 99b5b887fd1425dd05cfc9d4e2672770e89ddb68 Mon Sep 17 00:00:00 2001 From: Alexander Koehler Date: Fri, 2 Oct 2020 21:13:51 +0200 Subject: [PATCH 5/8] change variables --- .github/workflows/docker.yaml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index de26f60..e5fbb17 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -8,17 +8,13 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - - name: debug - run: echo ${{ github.GITHUB_REF }} - - name: debug - run: echo ${{ github.GITHUB_REPOSITORY }} - name: docker - run: docker build --file Dockerfile --tag temp/temp:latest . + run: docker build --file Dockerfile --tag ${{ github.REPOSITORY }}:${{ github.REF }} . - name: push the image uses: mr-smithers-excellent/docker-build-push@v4 with: - tag: ${{ github.GITHUB_REF }} - image: ${{ github.GITHUB_REPOSITORY }} + tag: ${{ github.REF }} + image: ${{ github.REPOSITORY }} registry: ghcr.io username: ${{ github.ACTOR }} # todo: are packages per repo or per user?! password: ${{ secrets.PUSHTOKEN }} From 3308d6fb449aee1a633a026daa9ddf5dcae318d7 Mon Sep 17 00:00:00 2001 From: Alexander Koehler Date: Fri, 2 Oct 2020 21:15:19 +0200 Subject: [PATCH 6/8] change variables; change job name --- .github/workflows/docker.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index e5fbb17..15bf898 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -1,5 +1,5 @@ --- -name: docker +name: container on: [ push ] jobs: @@ -9,11 +9,11 @@ jobs: steps: - uses: actions/checkout@v1 - name: docker - run: docker build --file Dockerfile --tag ${{ github.REPOSITORY }}:${{ github.REF }} . + run: docker build --file Dockerfile --tag ${{ github.REPOSITORY }}:${{ github.SHA }} . - name: push the image uses: mr-smithers-excellent/docker-build-push@v4 with: - tag: ${{ github.REF }} + tag: ${{ github.SHA }} image: ${{ github.REPOSITORY }} registry: ghcr.io username: ${{ github.ACTOR }} # todo: are packages per repo or per user?! From 96a04003f3fab1f97697a48e9390ba90074fc459 Mon Sep 17 00:00:00 2001 From: Alexander Koehler Date: Fri, 2 Oct 2020 21:17:47 +0200 Subject: [PATCH 7/8] rename file; added new step --- .github/workflows/{docker.yaml => container.yaml} | 2 ++ 1 file changed, 2 insertions(+) rename .github/workflows/{docker.yaml => container.yaml} (84%) diff --git a/.github/workflows/docker.yaml b/.github/workflows/container.yaml similarity index 84% rename from .github/workflows/docker.yaml rename to .github/workflows/container.yaml index 15bf898..8805d64 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/container.yaml @@ -10,6 +10,8 @@ jobs: - uses: actions/checkout@v1 - name: docker run: docker build --file Dockerfile --tag ${{ github.REPOSITORY }}:${{ github.SHA }} . + - name: start image + run: docker run --rm -it ${{ github.REPOSITORY }}:${{ github.SHA }} - name: push the image uses: mr-smithers-excellent/docker-build-push@v4 with: From 2c6d7d6d0cec68ee8a70bd34e206d033b8e8c1ec Mon Sep 17 00:00:00 2001 From: Alexander Koehler Date: Fri, 2 Oct 2020 21:18:35 +0200 Subject: [PATCH 8/8] no tty --- .github/workflows/container.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/container.yaml b/.github/workflows/container.yaml index 8805d64..2556f4d 100644 --- a/.github/workflows/container.yaml +++ b/.github/workflows/container.yaml @@ -11,7 +11,7 @@ jobs: - name: docker run: docker build --file Dockerfile --tag ${{ github.REPOSITORY }}:${{ github.SHA }} . - name: start image - run: docker run --rm -it ${{ github.REPOSITORY }}:${{ github.SHA }} + run: docker run --rm -i ${{ github.REPOSITORY }}:${{ github.SHA }} - name: push the image uses: mr-smithers-excellent/docker-build-push@v4 with: