Blame view

README.md 5.16 KB
a26a5bcb   hitier   Upgrade README
1
# Heliopropa Web
19268da3   Goutte   Initial commit.
2

5fb92534   hitier   More documentation
3
A website writen in flask for the visualisation of solarwind propagation simulations.
19268da3   Goutte   Initial commit.
4

a26a5bcb   hitier   Upgrade README
5
Builds and serves heliopropa's visualizations.
19268da3   Goutte   Initial commit.
6

e5a796dc   Goutte   Update the readme...
7
It's a `flask` webserver, serving `d3.js` plots.
5fb92534   hitier   More documentation
8

6b149919   Goutte   Add a Download bu...
9
It also gathers NetCDF data from AMDA, and serves it as CSV to the plotter.
19268da3   Goutte   Initial commit.
10

5fb92534   hitier   More documentation
11
## Quick Start
19268da3   Goutte   Initial commit.
12

5fb92534   hitier   More documentation
13
You can very quickly have a running app out of the box.
19268da3   Goutte   Initial commit.
14

5fb92534   hitier   More documentation
15
Just:
265af181   hitier   Set Docker compos...
16
17

    docker compose build
5fb92534   hitier   More documentation
18
19
20
21
22
    docker compose up -d

and point your browser to `http://127.0.0.1:8080/`

See later about configuring port  number
19268da3   Goutte   Initial commit.
23

5fb92534   hitier   More documentation
24
25
26
27
28
## Docker

Preferred way of running heliopropa app.

### Configuration
7f400160   hitier   Docker compose lo...
29
30
31

docker stack mainly consists in two files:

5fb92534   hitier   More documentation
32
33
- `Dockerfile` : for the container building
- `compose.yaml` : for the volumes configuration and links with nginx service and gunicorn
7f400160   hitier   Docker compose lo...
34

5fb92534   hitier   More documentation
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

And your can tweak port configuration thanks to `$PORT` environment variable.
(@see ports: section in `compose.yaml` )

Either by setting it in your shell
    
    PORT=8081 docker compose up -d

Or in a config file:
    
    cp compose.env-dist compose.env
    ${EDITOR} compose.env # set to your needs
    docker compose --env-file=compose.env up -d 

Or

    cp compose.env-dist .env
    ${EDITOR} .env # set to your needs
    docker compose up

### Volumes and `compose.override.yaml`
7f400160   hitier   Docker compose lo...
56
57
58

You may want to understand where data is stored:

5fb92534   hitier   More documentation
59
60
The web application saves `*.csv` files in the `./cache/` directory, which happens to be a docker volume
named `helio_cache`.
7f400160   hitier   Docker compose lo...
61

5fb92534   hitier   More documentation
62
63
The speasy library holds a cache dir located at `container:/root/.cache/speasy/Cache/` which is also mounted as a
volume: `speasy_cache`.
7f400160   hitier   Docker compose lo...
64
65
66

Two configuration files are also used:

5fb92534   hitier   More documentation
67
68
- `./config.yml` : for the web app.
- `${HOME}/.config/speasy/config.ini` : for the speasy library.
7f400160   hitier   Docker compose lo...
69

5fb92534   hitier   More documentation
70
71
You can use the `compose.override.yaml` file to make dynamic links between your local files or directories and the
container.
7f400160   hitier   Docker compose lo...
72

7f400160   hitier   Docker compose lo...
73
74
That way you can live edit the config files, and also use already loaded cache directories.

5fb92534   hitier   More documentation
75
76
To do so:

7f400160   hitier   Docker compose lo...
77
78
79
80
    cp compose.override.yaml-dist compose.override.yaml
    ${EDITOR} compose.override.yaml # make sure its ok, comment what you dont need
    docker compose up -d

5fb92534   hitier   More documentation
81
82
83
84
85
86
87
88
89
## Developer

### Files Overview

- `config.yml` : the main configuration file.
- `web/run.py` : the front controller, holding most of the code.
- `web/run.log` : you'll find more information about failures in the log.
- `web/view/home.html.jinja2` : the HTML template.
- `web/static/js/main.js` : most of the javascript client-side.
641893b9   hitier   Add solar-orbiter...
90

9ecb6089   hitier   Move config name ...
91
92
### Configuration

5fb92534   hitier   More documentation
93
94
95
96
    cp config.yml-dist config.yml
    $(EDITOR) config.yml # but defaults should be ok

Also take a look at the `./ressources/`  directory for more available configuration files.
9ecb6089   hitier   Move config name ...
97

29551a9f   hitier   Update prerequisites
98
99
### Python venv

5fb92534   hitier   More documentation
100
101
102
    python3 -m venv venv
    source venv/bin/activate
    pip install -r requirements.txt
19268da3   Goutte   Initial commit.
103

641893b9   hitier   Add solar-orbiter...
104
### Run locally
5fb92534   hitier   More documentation
105
106
107

    source venv/bin/activate
    DEBUG=true python web/run.py
19268da3   Goutte   Initial commit.
108
109

Then, browse [localhost:5000](http://localhost:5000).
5ef50583   Goutte   Clean up.
110

5fb92534   hitier   More documentation
111
### Admin task
8cfeb607   hitier   More install and ...
112

5fb92534   hitier   More documentation
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
A tool called `hp_cmd.py` is available to make so administrative task.

It allows you to nightly populate the csv cache so later visitors won't have to wait for data download.

Basic usage:
    
    # look at what it would do
    python web/hp_cmd.py --dry-run -clog csv_gen -a

    # do it
    python web/hp_cmd.py -clog csv_gen -a

    # see all usages
    python web/hp_cmd.py --help


Docker usage:

    docker compose exec web python web/hp_cmd.py --all


Http tasks:
8cfeb607   hitier   More install and ...
135

5fb92534   hitier   More documentation
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
    http://${HOSTNAME}/cache/clear
    http://${HOSTNAME}/cache/cleanup
    http://${HOSTNAME}/cache/warmup
    http://${HOSTNAME}/log
    http://${HOSTNAME}/log/clear

### Notebooks

If your want to dig into code usage take a look at our notebooks:

    pip install -r requirements-nb.txt
    jupyter notebook ./notebooks/

then browse to given url.

Each file name is self-explanatory, and each notebook contains explanations.


## Gunicorn and Nginx deployment

see [ Digital Ocean documentation ] (https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-gunicorn-and-nginx-on-ubuntu-20-04-fr)
8cfeb607   hitier   More install and ...
157

a26a5bcb   hitier   Upgrade README
158
### wep app service and Gunicorn
8cfeb607   hitier   More install and ...
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177

see ./resources/heliopropa.service

/etc/systemd/system/heliopropa.service

    [Unit]
    Description=Gunicorn instance to serve Heliopropa
    After=network.target

    [Service]
    User=debian
    Group=www-data
    WorkingDirectory= /home/debian/heliopropa/
    Environment="PATH=/home/debian/heliopropa/venv/bin/"
    ExecStart=/home/debian/heliopropa/venv/bin/gunicorn --workers 3 --bind unix:heliopropa.sock -m 007 web.run:app

    [Install]
    WantedBy=multi-user.target

a26a5bcb   hitier   Upgrade README
178
### Nginx
8cfeb607   hitier   More install and ...
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193

see ./resources/heliopropa.nginx

/etc/nginx/sites-available/heliopropa

	server {
		listen 80;
		server_name heliopropa heliopropa.co-libri.org;

		location / {
			include proxy_params;
			proxy_pass http://unix:/home/debian/heliopropa/heliopropa.sock;
		}
	}

a26a5bcb   hitier   Upgrade README
194
### Start and Allow at system reboot
8cfeb607   hitier   More install and ...
195
196
197
198
199

	sudo systemctl start nginx
	sudo systemctl start heliopropa 
	sudo systemctl enable heliopropa 

8cfeb607   hitier   More install and ...
200
201
202
203
## Git hook auto deploy

see ./resources/post-receive.git-hook

5fb92534   hitier   More documentation
204
Set bare repo with hook on vps
8cfeb607   hitier   More install and ...
205
206
207
208
209
210
211

    ssh user@vps
    git clone --bare path-to-heliopropa-repo heliopropa.git
    cd heliopropa.git/hooks
    vim post-receive
    chmod +x post-receive

8cfeb607   hitier   More install and ...
212
213
214
215
Push from dev computer

    git remote add helio-dev user@vps:heliopropa.git
    git push heliopropa HEAD:DEV