-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e4410b4
commit 050d808
Showing
13 changed files
with
150 additions
and
118 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 |
---|---|---|
|
@@ -18,6 +18,20 @@ If you are a PG&E customer you can link your account now! If you are not a PG&E | |
|
||
# Development | ||
|
||
## Environment Setup (Docker) | ||
|
||
You can get an environment setup easily using Docker. Make sure you have Docker and Docker Compose installed. | ||
|
||
``` | ||
git clone [email protected]:JPHutchins/open-energy-view.git | ||
cd open-energy-view | ||
docker-compose up | ||
``` | ||
|
||
On your host OS, open a Chrome or Firefox web browser and navigate to `http://localhost:5000` | ||
|
||
# Production | ||
|
||
## Environment Setup (Ubuntu 20.04) | ||
|
||
Process notes here: https://github.com/JPHutchins/open-energy-view/issues/31 | ||
|
@@ -73,10 +87,8 @@ cd open-energy-view | |
sudo rabbitmqctl add_vhost myvhost | ||
sudo rabbitmqctl set_permissions -p myvhost jp ".*" ".*" ".*" | ||
``` | ||
### Install frontend dependencies and build | ||
* **Install nvm** (if you don't have it) | ||
notes: https://github.com/nvm-sh/nvm | ||
``` | ||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash | ||
|
@@ -99,23 +111,6 @@ cd open-energy-view | |
npm run build | ||
``` | ||
### Run the development server and workers | ||
* **Start the server and workers** | ||
* Open four terminals (example from VSCode) | ||
![Four-Terminals](/docs/four-terminals.png) | ||
* First terminal: `./run-wsgi-dev` | ||
* Second terminal: `./run-io-worker` | ||
* Third terminal: `./run-cpu-worker` | ||
* **Open the development site in a browser** | ||
* Fourth terminal: `ip a` | ||
* Note the IP address of your WSL2 instance, in this case `172.31.30.203` | ||
![ip-a](/docs/ip-a.png) | ||
* On your host OS, open a Chrome or Firefox web browser and navigate to `http://<YOUR_WSL2_IP>:5000` | ||
![browser-address](/docs/browser-address.png) | ||
### Example account setup | ||
For first time setup you must register a user to your local database. Use something easily memorable and keep in mind that you can register as many users as you need while testing. | ||
* Click "Register now!" | ||
|
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,103 @@ | ||
version: "3.9" | ||
services: | ||
rabbitmq: | ||
container_name: oev-rabbit | ||
image: rabbitmq:3.11-alpine | ||
ports: | ||
- "5672:5672" | ||
- "15672:15672" | ||
hostname: "rabbitmq" # Important for how persistence works. | ||
volumes: | ||
- oev-rabbit:/var/lib/rabbitmq | ||
rabbitmqsetup: | ||
image: rabbitmq:3.11-alpine | ||
restart: "no" | ||
entrypoint: ["bash", "-c", "sleep 10 && rabbitmqctl -n rabbit@rabbitmq add_user jp admin && rabbitmqctl -n rabbit@rabbitmq set_user_tags jp administrator && rabbitmqctl -n rabbit@rabbitmq add_vhost myvhost && rabbitmqctl -n rabbit@rabbitmq set_permissions -p myvhost jp \".*\" \".*\" \".*\""] | ||
volumes: | ||
- oev-rabbit:/var/lib/rabbitmq | ||
depends_on: | ||
- rabbitmq # Make use of the cookie in the main container so we can run rabbitmqctl commands. | ||
app: | ||
container_name: oev | ||
build: | ||
context: ./ | ||
dockerfile: ./docker/Dockerfile-app | ||
ports: | ||
- "5000:5000" | ||
environment: | ||
- FLASK_CONFIG=config.DevConfig | ||
- FLASK_APP=open_energy_view | ||
- FLASK_ENV=production | ||
- SECRET_KEY=dev | ||
- JWT_SECRET_KEY=dev | ||
- JWT_BLACKLIST_ENABLED=True | ||
- JWT_TOKEN_LOCATION=cookies | ||
- JWT_ACCESS_COOKIE_PATH=/ | ||
- JWT_REFRESH_COOKIE_PATH=/api/web/token/refresh | ||
- JWT_COOKIE_CSRF_PROTECT=True | ||
- PROD_JWT_COOKIE_SECURE=True | ||
- DEV_JWT_COOKIE_SECURE=False | ||
- PROD_DATABASE_URI=sqlite:///../test/data/energy_history_test.db | ||
- DEV_DATABASE_URI=sqlite:///../test/data/energy_history_test.db | ||
- PGE_CLIENT_ID=client_id | ||
- PGE_CLIENT_SECRET=client_secret | ||
- GOOGLE_CLIENT_ID=GOOGLE_CLIENT_ID | ||
- GOOGLE_CLIENT_SECRET=GOOGLE_CLIENT_SECRET | ||
- OAUTHLIB_INSECURE_TRANSPORT=True | ||
- CERT_PATH=test/cert/cert.crt | ||
- KEY_PATH=test/cert/private.key | ||
- API_RESPONSE_KEY=xS5MqJ6N9CyH-hvqAGrmBVAxFMOyauMpdrdqCZa1eqo= | ||
- PORT=5000 | ||
depends_on: | ||
- rabbitmqsetup | ||
cpu-worker: | ||
restart: unless-stopped | ||
container_name: oev-cpu-worker | ||
build: | ||
context: ./ | ||
dockerfile: ./docker/Dockerfile-worker | ||
environment: | ||
- HOSTNAME=celery.cpus@%h | ||
- QUEUES=cpu | ||
- CONCURRENCY=1 | ||
- POOL=prefork | ||
- FLASK_CONFIG=config.DevConfig | ||
- FLASK_APP=open_energy_view | ||
- FLASK_ENV=production | ||
- SECRET_KEY=dev | ||
- JWT_SECRET_KEY=dev | ||
- JWT_BLACKLIST_ENABLED=True | ||
- JWT_TOKEN_LOCATION=cookies | ||
- JWT_ACCESS_COOKIE_PATH=/ | ||
- JWT_REFRESH_COOKIE_PATH=/api/web/token/refresh | ||
- JWT_COOKIE_CSRF_PROTECT=True | ||
- PROD_JWT_COOKIE_SECURE=True | ||
- DEV_JWT_COOKIE_SECURE=False | ||
- PROD_DATABASE_URI=sqlite:///../test/data/energy_history_test.db | ||
- DEV_DATABASE_URI=sqlite:///../test/data/energy_history_test.db | ||
- PGE_CLIENT_ID=client_id | ||
- PGE_CLIENT_SECRET=client_secret | ||
- GOOGLE_CLIENT_ID=GOOGLE_CLIENT_ID | ||
- GOOGLE_CLIENT_SECRET=GOOGLE_CLIENT_SECRET | ||
- OAUTHLIB_INSECURE_TRANSPORT=True | ||
- CERT_PATH=test/cert/cert.crt | ||
- KEY_PATH=test/cert/private.key | ||
- API_RESPONSE_KEY=xS5MqJ6N9CyH-hvqAGrmBVAxFMOyauMpdrdqCZa1eqo= | ||
- PORT=5000 | ||
depends_on: | ||
- app | ||
io-worker: | ||
restart: unless-stopped | ||
container_name: oev-io-worker | ||
build: | ||
context: ./ | ||
dockerfile: ./docker/Dockerfile-worker | ||
environment: | ||
- HOSTNAME=celery.io@%h | ||
- QUEUES=io | ||
- CONCURRENCY=500 | ||
- POOL=gevent | ||
depends_on: | ||
- app | ||
volumes: | ||
oev-rabbit: |
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,14 @@ | ||
FROM node:10.19.0-slim AS ui | ||
ADD open_energy_view/frontend /frontend | ||
WORKDIR /frontend | ||
RUN npm ci && npm run build | ||
|
||
FROM python:3.8-slim | ||
ADD . /app | ||
WORKDIR /app | ||
RUN apt update && apt install -y build-essential | ||
RUN pip3 install -r ./requirements.txt | ||
RUN apt purge -y build-essential | ||
COPY --from=ui /frontend/dist /app/open_energy_view/frontend/dist | ||
COPY --from=ui /frontend/node_modules /app/open_energy_view/frontend/node_modules | ||
ENTRYPOINT uwsgi --http 0.0.0.0:"$PORT" --gevent 100 --wsgi-file wsgi.py --callable app |
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,2 @@ | ||
FROM open-energy-view_app | ||
ENTRYPOINT celery worker --app open_energy_view.celery_tasks --hostname="$HOSTNAME" --queues="$QUEUES" --loglevel=info --pool="$POOL" --concurrency="$CONCURRENCY" |
Binary file not shown.
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
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.