-
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
ba09e02
commit a375923
Showing
13 changed files
with
142 additions
and
191 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,103 +18,17 @@ If you are a PG&E customer you can link your account now! If you are not a PG&E | |
|
||
# Development | ||
|
||
## Environment Setup (Ubuntu 20.04) | ||
## Environment Setup (Docker) | ||
|
||
Process notes here: https://github.com/JPHutchins/open-energy-view/issues/31 | ||
You can get an environment setup easily using Docker. Make sure you have Docker and Docker Compose installed. | ||
|
||
The following notes are for setting up the environment with a Windows 10 host and Ubuntu 20.04 on WSL2. Please submit a PR if you find necessary adaptations on your environment. | ||
|
||
Personally I use VSCode from the Windows host utilizing the "Remote - SSH" and "Remote - WSL" extensions. | ||
|
||
### Clone this repository | ||
``` | ||
git clone [email protected]:JPHutchins/open-energy-view.git | ||
cd open-energy-view | ||
docker-compose up | ||
``` | ||
### Install backend dependencies | ||
* **Install python requirements** | ||
|
||
Note: check your python3 version | ||
``` | ||
sudo apt install python3.8-venv build-essential python3-dev | ||
``` | ||
* **Create the virtual environment and install packages** | ||
``` | ||
python3 -m venv venv | ||
source venv/bin/activate | ||
pip3 install -r requirements.txt | ||
``` | ||
* **Install and configure rabbitmq** | ||
* Install erlang: | ||
``` | ||
sudo apt update | ||
sudo apt install software-properties-common apt-transport-https | ||
wget -O- https://packages.erlang-solutions.com/ubuntu/erlang_solutions.asc | sudo apt-key add - | ||
echo "deb https://packages.erlang-solutions.com/ubuntu focal contrib" | sudo tee /etc/apt/sources.list.d/rabbitmq.list | ||
sudo apt update | ||
sudo apt install erlang | ||
``` | ||
* Install rabbitmq | ||
``` | ||
curl -s https://packagecloud.io/install/repositories/rabbitmq/rabbitmq-server/script.deb.sh | sudo bash | ||
sudo apt install rabbitmq-server | ||
* Start rabbitmq-server | ||
``` | ||
sudo service rabbitmq-server start | ||
``` | ||
* Verify that rabbitmq-server is running | ||
``` | ||
sudo service rabbitmq-server status | ||
``` | ||
* Configure rabbitmq | ||
``` | ||
sudo rabbitmqctl add_user jp admin | ||
sudo rabbitmqctl set_user_tags jp administrator | ||
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 | ||
``` | ||
* **Install npm** | ||
``` | ||
nvm install 10.19.0 | ||
``` | ||
* **Install frontend packages** | ||
``` | ||
cd open_energy_view/frontend | ||
nvm use 10 | ||
npm install | ||
``` | ||
* **Build frontend** | ||
Assumes you are at path: `*/open-energy-view/open_energy_view/frontend` | ||
``` | ||
nvm use 10 | ||
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) | ||
|
||
On your host OS, open a Chrome or Firefox web browser and navigate to `http://localhost:5000` | ||
|
||
### 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. | ||
|
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:5000 --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.