-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set up the docker image to run the react app
- Loading branch information
1 parent
7128612
commit 3c70b87
Showing
20 changed files
with
552 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,237 @@ | ||
FROM socialengine/nginx-spa:latest | ||
|
||
RUN apt update -y | ||
|
||
RUN apt update && apt install -y --no-install-recommends \ | ||
ca-certificates \ | ||
curl \ | ||
netbase \ | ||
wget \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
RUN set -ex; \ | ||
if ! command -v gpg > /dev/null; then \ | ||
apt update; \ | ||
apt install -y --no-install-recommends \ | ||
gnupg \ | ||
dirmngr \ | ||
; \ | ||
rm -rf /var/lib/apt/lists/*; \ | ||
fi | ||
|
||
|
||
RUN apt update && apt install -y --no-install-recommends \ | ||
git \ | ||
mercurial \ | ||
openssh-client \ | ||
subversion \ | ||
\ | ||
procps \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
RUN set -ex; \ | ||
apt-get update; \ | ||
# make sure debconf doesn't try to prompt (e.g. tzdata on Ubuntu) | ||
DEBIAN_FRONTEND=noninteractive \ | ||
apt install -y --no-install-recommends \ | ||
autoconf \ | ||
automake \ | ||
bzip2 \ | ||
dpkg-dev \ | ||
file \ | ||
g++ \ | ||
gcc \ | ||
imagemagick \ | ||
libbz2-dev \ | ||
libc6-dev \ | ||
libcurl4-openssl-dev \ | ||
libdb-dev \ | ||
libevent-dev \ | ||
libffi-dev \ | ||
libgdbm-dev \ | ||
libglib2.0-dev \ | ||
libgmp-dev \ | ||
libjpeg-dev \ | ||
libkrb5-dev \ | ||
liblzma-dev \ | ||
libmagickcore-dev \ | ||
libmagickwand-dev \ | ||
libmaxminddb-dev \ | ||
libncurses5-dev \ | ||
libncursesw5-dev \ | ||
libpng-dev \ | ||
libpq-dev \ | ||
libreadline-dev \ | ||
libsqlite3-dev \ | ||
libssl-dev \ | ||
libtool \ | ||
libwebp-dev \ | ||
libxml2-dev \ | ||
libxslt-dev \ | ||
libyaml-dev \ | ||
make \ | ||
patch \ | ||
unzip \ | ||
xz-utils \ | ||
zlib1g-dev \ | ||
\ | ||
# https://lists.debian.org/debian-devel-announce/2016/09/msg00000.html | ||
$( \ | ||
# if we use just "apt-cache show" here, it returns zero because "Can't select versions from package 'libmysqlclient-dev' as it is purely virtual", hence the pipe to grep | ||
if apt-cache show 'default-libmysqlclient-dev' 2>/dev/null | grep -q '^Version:'; then \ | ||
echo 'default-libmysqlclient-dev'; \ | ||
else \ | ||
echo 'libmysqlclient-dev'; \ | ||
fi \ | ||
) \ | ||
; \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
|
||
# ensure local python is preferred over distribution python | ||
ENV PATH /usr/local/bin:$PATH | ||
|
||
# http://bugs.python.org/issue19846 | ||
# > At the moment, setting "LANG=C" on a Linux system *fundamentally breaks Python 3*, and that's not OK. | ||
ENV LANG C.UTF-8 | ||
|
||
# extra dependencies (over what buildpack-deps already includes) | ||
RUN apt update && apt install -y --no-install-recommends \ | ||
libbluetooth-dev \ | ||
tk-dev \ | ||
uuid-dev \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
ENV GPG_KEY 0D96DF4D4110E5C43FBFB17F2D347EA6AA65421D | ||
ENV PYTHON_VERSION 3.7.7 | ||
|
||
RUN set -ex \ | ||
\ | ||
&& wget -O python.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" \ | ||
&& wget -O python.tar.xz.asc "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" \ | ||
&& export GNUPGHOME="$(mktemp -d)" \ | ||
&& gpg --batch --keyserver ha.pool.sks-keyservers.net --recv-keys "$GPG_KEY" \ | ||
&& gpg --batch --verify python.tar.xz.asc python.tar.xz \ | ||
&& { command -v gpgconf > /dev/null && gpgconf --kill all || :; } \ | ||
&& rm -rf "$GNUPGHOME" python.tar.xz.asc \ | ||
&& mkdir -p /usr/src/python \ | ||
&& tar -xJC /usr/src/python --strip-components=1 -f python.tar.xz \ | ||
&& rm python.tar.xz \ | ||
\ | ||
&& cd /usr/src/python \ | ||
&& gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)" \ | ||
&& ./configure \ | ||
--build="$gnuArch" \ | ||
--enable-loadable-sqlite-extensions \ | ||
--enable-optimizations \ | ||
--enable-option-checking=fatal \ | ||
--enable-shared \ | ||
--with-system-expat \ | ||
--with-system-ffi \ | ||
--without-ensurepip \ | ||
&& make -j "$(nproc)" \ | ||
# setting PROFILE_TASK makes "--enable-optimizations" reasonable: https://bugs.python.org/issue36044 / https://github.com/docker-library/python/issues/160#issuecomment-509426916 | ||
PROFILE_TASK='-m test.regrtest --pgo \ | ||
test_array \ | ||
test_base64 \ | ||
test_binascii \ | ||
test_binhex \ | ||
test_binop \ | ||
test_bytes \ | ||
test_c_locale_coercion \ | ||
test_class \ | ||
test_cmath \ | ||
test_codecs \ | ||
test_compile \ | ||
test_complex \ | ||
test_csv \ | ||
test_decimal \ | ||
test_dict \ | ||
test_float \ | ||
test_fstring \ | ||
test_hashlib \ | ||
test_io \ | ||
test_iter \ | ||
test_json \ | ||
test_long \ | ||
test_math \ | ||
test_memoryview \ | ||
test_pickle \ | ||
test_re \ | ||
test_set \ | ||
test_slice \ | ||
test_struct \ | ||
test_threading \ | ||
test_time \ | ||
test_traceback \ | ||
test_unicode \ | ||
' \ | ||
&& make install \ | ||
&& ldconfig \ | ||
\ | ||
&& find /usr/local -depth \ | ||
\( \ | ||
\( -type d -a \( -name test -o -name tests -o -name idle_test \) \) \ | ||
-o \ | ||
\( -type f -a \( -name '*.pyc' -o -name '*.pyo' \) \) \ | ||
\) -exec rm -rf '{}' + \ | ||
&& rm -rf /usr/src/python \ | ||
\ | ||
&& python3 --version | ||
|
||
# make some useful symlinks that are expected to exist | ||
RUN cd /usr/local/bin \ | ||
&& ln -s idle3 idle \ | ||
&& ln -s pydoc3 pydoc \ | ||
&& ln -s python3 python \ | ||
&& ln -s python3-config python-config | ||
|
||
# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'" | ||
ENV PYTHON_PIP_VERSION 20.1 | ||
# https://github.com/pypa/get-pip | ||
ENV PYTHON_GET_PIP_URL https://github.com/pypa/get-pip/raw/1fe530e9e3d800be94e04f6428460fc4fb94f5a9/get-pip.py | ||
ENV PYTHON_GET_PIP_SHA256 ce486cddac44e99496a702aa5c06c5028414ef48fdfd5242cd2fe559b13d4348 | ||
|
||
RUN set -ex; \ | ||
\ | ||
wget -O get-pip.py "$PYTHON_GET_PIP_URL"; \ | ||
echo "$PYTHON_GET_PIP_SHA256 *get-pip.py" | sha256sum --check --strict -; \ | ||
\ | ||
python get-pip.py \ | ||
--disable-pip-version-check \ | ||
--no-cache-dir \ | ||
"pip==$PYTHON_PIP_VERSION" \ | ||
; \ | ||
pip --version; \ | ||
\ | ||
find /usr/local -depth \ | ||
\( \ | ||
\( -type d -a \( -name test -o -name tests -o -name idle_test \) \) \ | ||
-o \ | ||
\( -type f -a \( -name '*.pyc' -o -name '*.pyo' \) \) \ | ||
\) -exec rm -rf '{}' +; \ | ||
rm -f get-pip.py | ||
|
||
RUN apt update -y; apt install -y npm | ||
RUN npm install -g n; n stable; | ||
RUN npm install -g latest-version | ||
|
||
COPY . /app | ||
COPY ./docker/nginx-site.conf /etc/nginx/conf.d/default.conf | ||
RUN chmod -R 777 /app | ||
|
||
RUN /usr/local/bin/pip install -r /app/server/requirements.txt | ||
RUN cd /app/server/; ./run_tests.sh; cd ../..; | ||
|
||
ARG REACT_APP_TURN_HOST=${REACT_APP_TURN_HOST} | ||
RUN echo "TURN host set to ${TURN_HOST}" | ||
ARG REACT_APP_TURN_USERNAME=${REACT_APP_TURN_USERNAME} | ||
ARG REACT_APP_TURN_PASSWORD=${REACT_APP_TURN_PASSWORD} | ||
|
||
RUN cd /app/; npm install; npm test -- --watchAll=false; cd ..; | ||
RUN cd /app/; npm run build; cd ..; | ||
|
||
RUN /app/server/app.py >>/app/app.log & | ||
|
||
ENTRYPOINT ["/app/docker/pre-start.sh"] | ||
CMD ["/usr/local/bin/start-container", "nginx"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# pushState friendly! | ||
# The setup: | ||
# * website name is `_` | ||
# * javascript app is located at `/app` | ||
|
||
charset utf-8; | ||
|
||
tcp_nopush on; | ||
tcp_nodelay off; | ||
client_header_timeout 10s; | ||
client_body_timeout 10s; | ||
client_max_body_size 128k; | ||
reset_timedout_connection on; | ||
|
||
gzip on; | ||
gzip_types | ||
text/css | ||
text/javascript | ||
text/xml | ||
text/plain | ||
application/javascript | ||
application/x-javascript | ||
application/json | ||
application/xml | ||
application/rss+xml | ||
application/atom+xml | ||
font/truetype | ||
font/opentype | ||
image/svg+xml; | ||
|
||
upstream websocket { | ||
server 127.0.0.1:8765; | ||
} | ||
|
||
server { | ||
listen 80; | ||
server_name localhost; | ||
root /app/build; | ||
location /ws { | ||
rewrite /ws/(.*) /$1 break; | ||
proxy_pass http://websocket; | ||
proxy_http_version 1.1; | ||
proxy_set_header Upgrade $http_upgrade; | ||
proxy_set_header Connection "upgrade"; | ||
proxy_set_header Host $host; | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
|
||
# Start the signalling server before the container launches nginx | ||
|
||
/app/server/app.py >>/app/app.py.log & | ||
echo $@ | ||
exec $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import asyncio | ||
import websockets | ||
import json | ||
|
||
from lib.message_handler import MessageHandler | ||
from lib.client import Client | ||
from lib.message import Message | ||
|
||
message_handler = MessageHandler() | ||
|
||
async def dispatch(websocket, path): | ||
client = Client(websocket) | ||
print("New client: " + client.address, flush=True) | ||
try: | ||
async for json_message in websocket: | ||
message = Message.from_json(json_message) | ||
if (message.type == "announce"): | ||
message_handler.add_client(client) | ||
await message_handler.broadcast(client, message) | ||
elif (message.type in ["offer","answer","ice"]): | ||
await message_handler.send(client, message) | ||
finally: | ||
message_handler.remove_client(client) | ||
|
||
# broadcast the departure | ||
message = Message(type = "hangup") | ||
await message_handler.broadcast(client, message) | ||
print("Client " + client.address + " left", flush=True) | ||
|
||
print("starting signalling server", flush=True) | ||
start_server = websockets.serve(dispatch, "0.0.0.0", 8765) | ||
|
||
asyncio.get_event_loop().run_until_complete(start_server) | ||
asyncio.get_event_loop().run_forever() |
Empty file.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import uuid | ||
|
||
class Client: | ||
|
||
def __init__(self, websocket): | ||
self.address = uuid.uuid4().hex | ||
self.websocket = websocket |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import json | ||
|
||
class Message: | ||
|
||
def __init__(self, | ||
sender_guid = "", | ||
receiver_guid = "", | ||
type = "", | ||
data = None | ||
): | ||
self.sender_guid = sender_guid | ||
self.receiver_guid = receiver_guid | ||
self.type = type | ||
self.data = data | ||
|
||
def to_json(self): | ||
return json.dumps(self.__dict__) | ||
|
||
@staticmethod | ||
def from_json(json_string): | ||
obj = json.loads(json_string) | ||
return Message( | ||
obj["sender_guid"], | ||
obj["receiver_guid"], | ||
obj["type"], | ||
obj["data"] | ||
) | ||
|
||
|
Binary file not shown.
Oops, something went wrong.