start lovespeech

This commit is contained in:
Alexander Mahr 2024-09-29 09:24:47 +02:00
commit 9d444505ce
9 changed files with 91 additions and 0 deletions

7
LICENSE Normal file
View file

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

5
README.md Normal file
View file

@ -0,0 +1,5 @@
# lovespeech
## license
there is a [LICENSE](./LICENSE) file

5
client/Dockerfile Normal file
View file

@ -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"]

20
client/entrypoint.py Executable file
View file

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

3
client/entrypoint.sh Executable file
View file

@ -0,0 +1,3 @@
#!/bin/sh
exec /entrypoint.py

19
compose.yml Normal file
View file

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

5
server/Dockerfile Normal file
View file

@ -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"]

22
server/entrypoint.py Executable file
View file

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

5
server/entrypoint.sh Executable file
View file

@ -0,0 +1,5 @@
#!/bin/sh
test "" = "$*" || { exec "$@"; }
echo "running /entrypoint.py"
exec /entrypoint.py