From ea4084a63ab7e75572f0234a311f2c041cbbb562 Mon Sep 17 00:00:00 2001 From: Ian Winsemius Date: Thu, 24 Feb 2022 22:46:13 -0800 Subject: [PATCH] getting close --- .dockerignore | 2 ++ docker-compose.yml | 23 +++++++++++++++++++ docker/service_rabbitmq/Dockerfile.rabbitmq | 5 +++++ docker/service_rabbitmq/init.sh | 9 ++++++++ docker/service_web/Dockerfile.web | 25 +++++++++++++++++++++ docker/service_web/init.sh | 7 ++++++ run-cpu-worker | 4 ++-- run-io-worker | 2 +- run-wsgi-dev | 4 ++-- 9 files changed, 76 insertions(+), 5 deletions(-) create mode 100644 .dockerignore create mode 100644 docker-compose.yml create mode 100644 docker/service_rabbitmq/Dockerfile.rabbitmq create mode 100755 docker/service_rabbitmq/init.sh create mode 100644 docker/service_web/Dockerfile.web create mode 100755 docker/service_web/init.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..885c040 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +open_energy_view/frontend/package-lock.json +*/node_modules \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..6451a63 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,23 @@ +services: + rabbit: + build: + dockerfile: ./docker/service_rabbitmq/Dockerfile.rabbitmq + context: ./ + environment: + - RABBITMQ_DEFAULT_USER=jp + - RABBITMQ_DEFAULT_PASS=admin + cpu: + tty: true + depends_on: + - rabbit + build: + context: ./ + dockerfile: ./docker/service_web/Dockerfile.web + args: + NODE_OPTIONS: --openssl-legacy-provider + ports: + - 5001:5001 + links: + - rabbit + + \ No newline at end of file diff --git a/docker/service_rabbitmq/Dockerfile.rabbitmq b/docker/service_rabbitmq/Dockerfile.rabbitmq new file mode 100644 index 0000000..ff3c386 --- /dev/null +++ b/docker/service_rabbitmq/Dockerfile.rabbitmq @@ -0,0 +1,5 @@ +FROM rabbitmq:latest + +copy ./docker/service_rabbitmq/init.sh /app/init.sh + +CMD ["/app/init.sh"] \ No newline at end of file diff --git a/docker/service_rabbitmq/init.sh b/docker/service_rabbitmq/init.sh new file mode 100755 index 0000000..4c60946 --- /dev/null +++ b/docker/service_rabbitmq/init.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +rabbitmqctl wait --timeout 60 +rabbitmqctl add_user $RABBITMQ_USER $RABBITMQ_PASSWORD 2>/dev/null +rabbitmqctl set_user_tags $RABBITMQ_USER administrator +rabbitmqctl add_vhost myvhost +rabbitmqctl set_permissions -p / $RABBITMQ_USER ".*" ".*" ".*" ; + +rabbitmq-server $@ \ No newline at end of file diff --git a/docker/service_web/Dockerfile.web b/docker/service_web/Dockerfile.web new file mode 100644 index 0000000..88b029e --- /dev/null +++ b/docker/service_web/Dockerfile.web @@ -0,0 +1,25 @@ +FROM node:latest as node + + SHELL ["/bin/bash", "--login", "-c"] + WORKDIR /app + COPY . . + + RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash + RUN nvm install 10.19.0 + RUN nvm use 10 + + + ARG NODE_OPTIONS + WORKDIR /app/open_energy_view/frontend + RUN npm install + RUN npm run build + + WORKDIR /app + +FROM python:3.9 + + COPY requirements.txt ./ + COPY --from=node /app ./ + RUN pip install --no-cache-dir -r requirements.txt + + CMD ["./docker/service_web/init.sh"] diff --git a/docker/service_web/init.sh b/docker/service_web/init.sh new file mode 100755 index 0000000..4709928 --- /dev/null +++ b/docker/service_web/init.sh @@ -0,0 +1,7 @@ +#!/bin/sh + + + +./run-wsgi-dev +./run-io-worker +./run-cpu-worker \ No newline at end of file diff --git a/run-cpu-worker b/run-cpu-worker index dd457b8..3286658 100755 --- a/run-cpu-worker +++ b/run-cpu-worker @@ -1,5 +1,5 @@ #!/bin/bash -source venv/bin/activate +#source venv/bin/activate export FLASK_CONFIG=config.DevConfig export FLASK_APP=open_energy_view export FLASK_ENV=production @@ -22,5 +22,5 @@ export OAUTHLIB_INSECURE_TRANSPORT=True export CERT_PATH=test/cert/cert.crt export KEY_PATH=test/cert/private.key export API_RESPONSE_KEY=xS5MqJ6N9CyH-hvqAGrmBVAxFMOyauMpdrdqCZa1eqo= -export IP_AND_PORT=$(hostname -I | awk '{print $1}'):5000 +export IP_AND_PORT=$(hostname -I | awk '{print $1}'):5001 celery worker --app open_energy_view.celery_tasks --hostname=celery.cpus@%h --queues=cpu --loglevel=info --concurrency=1 diff --git a/run-io-worker b/run-io-worker index 8dc16ed..cf534f3 100755 --- a/run-io-worker +++ b/run-io-worker @@ -1,4 +1,4 @@ #!/bin/bash -source venv/bin/activate +#source venv/bin/activate celery worker --app open_energy_view.celery_tasks --hostname=celery.io@%h --queues=io --loglevel=info --pool=gevent --concurrency=500 diff --git a/run-wsgi-dev b/run-wsgi-dev index aa394ff..81310ca 100755 --- a/run-wsgi-dev +++ b/run-wsgi-dev @@ -1,5 +1,5 @@ #!/bin/bash -source venv/bin/activate +#source venv/bin/activate export FLASK_CONFIG=config.DevConfig export FLASK_APP=open_energy_view export FLASK_ENV=production @@ -23,4 +23,4 @@ export CERT_PATH=test/cert/cert.crt export KEY_PATH=test/cert/private.key export API_RESPONSE_KEY=xS5MqJ6N9CyH-hvqAGrmBVAxFMOyauMpdrdqCZa1eqo= export IP_AND_PORT=$(hostname -I | awk '{print $1}'):5000 -./venv/bin/uwsgi --http 0.0.0.0:5000 --gevent 100 --wsgi-file wsgi.py --callable app +./venv/bin/uwsgi --http 0.0.0.0:5001 --gevent 100 --wsgi-file wsgi.py --callable app