create websocket-docket test repo
This commit is contained in:
commit
20d74610ce
10 changed files with 212 additions and 0 deletions
50
LICENSE
Normal file
50
LICENSE
Normal file
|
@ -0,0 +1,50 @@
|
|||
Copyright (c) Aymeric Augustin and contributors
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of the copyright holder nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
Modifications are
|
||||
Copyright (c) Alexander Mahr 2024 Berlin
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of the copyright holder nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.DAMAGE
|
81
README.md
Normal file
81
README.md
Normal file
|
@ -0,0 +1,81 @@
|
|||
# A compose containerized test of websockets
|
||||
|
||||
* based on containers
|
||||
* can run rootless, in docker, nerdctl or podman
|
||||
* uses alpine:edge
|
||||
* uses python3 py3-websockets (i.e. version 13+)
|
||||
|
||||
## Adopted code
|
||||
|
||||
[https://websockets.readthedocs.io/en/13.1/howto/quickstart.html](https://websockets.readthedocs.io/en/13.1/howto/quickstart.html)
|
||||
|
||||
## Usage
|
||||
|
||||
clone the repo
|
||||
```
|
||||
docker compose up
|
||||
```
|
||||
|
||||

|
||||
|
||||
## Copyright and LICENSES
|
||||
|
||||
* client/entrypoint.py and server/entrypoint.py are copyrighted and licensed under
|
||||
```
|
||||
Copyright (c) Aymeric Augustin and contributors
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of the copyright holder nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
```
|
||||
* all modificatios are Copyright 2024 Alexander Mahr and licensed as:
|
||||
```
|
||||
Copyright (c) Alexander Mahr Berlin
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of the copyright holder nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
5
client/Dockerfile
Normal file
5
client/Dockerfile
Normal 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"]
|
21
client/entrypoint.py
Executable file
21
client/entrypoint.py
Executable file
|
@ -0,0 +1,21 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import asyncio
|
||||
import os
|
||||
|
||||
from websockets.asyncio.client import connect
|
||||
|
||||
async def hello():
|
||||
uri = "ws://server:1080"
|
||||
async with connect(uri) as websocket:
|
||||
print(f"Get username via:\n name = os.environ.get('USER')")
|
||||
name = os.environ.get('USER')
|
||||
# name = name == NULL ? std::string() : std::string(name);
|
||||
await websocket.send(name)
|
||||
print(f">>> {name}")
|
||||
|
||||
greeting = await websocket.recv()
|
||||
print(f"<<< {greeting}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(hello())
|
3
client/entrypoint.sh
Executable file
3
client/entrypoint.sh
Executable file
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
|
||||
exec /entrypoint.py
|
19
compose.yml
Normal file
19
compose.yml
Normal 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
|
BIN
images/screenshot1.png
Normal file
BIN
images/screenshot1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 41 KiB |
5
server/Dockerfile
Normal file
5
server/Dockerfile
Normal 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"]
|
23
server/entrypoint.py
Executable file
23
server/entrypoint.py
Executable file
|
@ -0,0 +1,23 @@
|
|||
#!/usr/bin/python
|
||||
##!/usr/bin/env python
|
||||
|
||||
import asyncio
|
||||
|
||||
from websockets.asyncio.server import serve
|
||||
|
||||
async def hello(websocket):
|
||||
name = await websocket.recv()
|
||||
print(f"<<< {name}")
|
||||
|
||||
greeting = f"Hello {name}!"
|
||||
|
||||
await websocket.send(greeting)
|
||||
print(f">>> {greeting}")
|
||||
|
||||
async def main():
|
||||
async with serve(hello, "0.0.0.0", 1080):
|
||||
await asyncio.get_running_loop().create_future() # run forever
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
|
5
server/entrypoint.sh
Executable file
5
server/entrypoint.sh
Executable file
|
@ -0,0 +1,5 @@
|
|||
#!/bin/sh
|
||||
|
||||
test "" = "$*" || { exec "$@"; }
|
||||
echo "running /entrypoint.py"
|
||||
exec /entrypoint.py
|
Loading…
Add table
Reference in a new issue