commit 9d444505cef4e5fc7cc1209e422590075410bb66 Author: Alexander Mahr Date: Sun Sep 29 09:24:47 2024 +0200 start lovespeech diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..a568e71 --- /dev/null +++ b/LICENSE @@ -0,0 +1,7 @@ +Copyright (c) Alexander Mahr 2024 Berlin + +This software is copyrighted and licensed ONLY subject to the following terms: +* NO-WARRANTY, you use it at your own risk, no liability taken +* NO-SOFTWARE-PATENTS, you use, hold or agree to software-patents, then you are not allowed to use this license +* NO-MEGACORPS, you are directly a megacorps (i.e. company with revenue over 1million 2024 USD) or linked to one, then you cannot use this software. +* ANY modification or redistribution of this software must feature this copyright notice and license and be subject to the same License diff --git a/README.md b/README.md new file mode 100644 index 0000000..9f7b6f3 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# lovespeech + +## license + +there is a [LICENSE](./LICENSE) file diff --git a/client/Dockerfile b/client/Dockerfile new file mode 100644 index 0000000..2c7dbb9 --- /dev/null +++ b/client/Dockerfile @@ -0,0 +1,5 @@ +FROM alpine:edge +RUN apk update && apk add py3-websockets +COPY --chmod=0555 entrypoint.sh /entrypoint.sh +COPY --chmod=0555 entrypoint.py /entrypoint.py +ENTRYPOINT ["/entrypoint.sh"] diff --git a/client/entrypoint.py b/client/entrypoint.py new file mode 100755 index 0000000..ab0f076 --- /dev/null +++ b/client/entrypoint.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python + +import os +import asyncio + +from websockets.asyncio.client import connect + +async def test(): + uri = "ws://server:1080" + async with connect(uri) as websocket: + print(f"Get username via:\n name = os.environ.get('USER')") + msg = os.environ.get('USER') + await websocket.send(msg) + print(f"SENT: {msg}") + + answer = await websocket.recv() + print(f"RECVEIVED: {answer}") + +if __name__ == "__main__": + asyncio.run(test()) diff --git a/client/entrypoint.sh b/client/entrypoint.sh new file mode 100755 index 0000000..e8651af --- /dev/null +++ b/client/entrypoint.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +exec /entrypoint.py diff --git a/compose.yml b/compose.yml new file mode 100644 index 0000000..41c95a4 --- /dev/null +++ b/compose.yml @@ -0,0 +1,19 @@ +services: + # the server + server: + stop_grace_period: 1s + environment: + PYTHONUNBUFFERED: true + build: 'server' + expose: + - 1080 + # the client + client: + stop_grace_period: 1s + environment: + USER: ${USER} + build: 'client' + restart: on-failure + depends_on: + server: + condition: service_started diff --git a/server/Dockerfile b/server/Dockerfile new file mode 100644 index 0000000..2c7dbb9 --- /dev/null +++ b/server/Dockerfile @@ -0,0 +1,5 @@ +FROM alpine:edge +RUN apk update && apk add py3-websockets +COPY --chmod=0555 entrypoint.sh /entrypoint.sh +COPY --chmod=0555 entrypoint.py /entrypoint.py +ENTRYPOINT ["/entrypoint.sh"] diff --git a/server/entrypoint.py b/server/entrypoint.py new file mode 100755 index 0000000..d24c394 --- /dev/null +++ b/server/entrypoint.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python + +import asyncio + +from websockets.asyncio.server import serve + +async def server(websocket): + msg = await websocket.recv() + print(f"IN : {msg}") + + answer = f"echoing {msg}" + + await websocket.send(answer) + print(f"OUT: {answer}") + +async def main(): + async with serve(server, "0.0.0.0", 1080): + await asyncio.get_running_loop().create_future() + +if __name__ == "__main__": + asyncio.run(main()) + diff --git a/server/entrypoint.sh b/server/entrypoint.sh new file mode 100755 index 0000000..a55b7bb --- /dev/null +++ b/server/entrypoint.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +test "" = "$*" || { exec "$@"; } +echo "running /entrypoint.py" +exec /entrypoint.py