Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Production rotate.macrostrat.org #12

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions conf/nginx.certbot.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ proxy_cache_path /var/cache/nginx/corelle_api


server {
listen 443 ssl proxy_protocol;
server_name rotate.macrostrat.org;
ssl_certificate /etc/letsencrypt/live/rotate.macrostrat.org/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/rotate.macrostrat.org/privkey.pem;
listen 80;

client_max_body_size 20M;
proxy_cache_background_update on;
Expand Down
1 change: 1 addition & 0 deletions conf/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ http {
proxy_cache corelle_api;
proxy_pass http://backend;
proxy_http_version 1.1;
default_type application/json;
}

location / {
Expand Down
8 changes: 5 additions & 3 deletions corelle/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
get_plate_rotations,
get_rotation_series,
rotate_point,
rotate_point_for_api,
)

app = Flask(__name__)
Expand Down Expand Up @@ -192,10 +193,11 @@ def get(self):
for p in points:
[lon, lat] = p.split(",")
pt = [float(lon), float(lat)]
res = rotate_point(pt, args["model"], args["time"])
res = rotate_point_for_api(pt, args["model"], args["time"])
if res is not None:
res = dict(type="Feature", geometry=dict(type="Point", coordinates=res))
out_points.append(res)
out_points.append(dict(type="Feature",
geometry=dict(type="Point", coordinates=res['coordinates']),
properties=dict(plate_id=res['plate_id'])))
else:
if args["include_failures"]:
out_points.append(None)
Expand Down
19 changes: 19 additions & 0 deletions corelle/rotate/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,30 @@ def rotate_point(point, model, time):
if plate_id is None:
return None
q = get_rotation(model, plate_id, time)
if q is None:
return None
v0 = sph2cart(*point)
v1 = Q.rotate_vectors(q, v0)
return cart2sph(v1)


def rotate_point_for_api(point, model, time):
if time == 0:
return point
sql = get_sql("plate-for-point")
plate_id = conn.execute(
sql, lon=point[0], lat=point[1], model_name=model, time=time
).scalar()
if plate_id is None:
return None
q = get_rotation(model, plate_id, time)
if q is None:
return None
v0 = sph2cart(*point)
v1 = Q.rotate_vectors(q, v0)
return dict(coordinates=cart2sph(v1), plate_id=plate_id)


__tstep_rotation_pairs = get_sql("rotation-pairs-for-time")
__model_rotation_pairs = get_sql("rotation-pairs-for-model")
__active_plates_sql = get_sql("active-plates-at-time")
Expand Down
9 changes: 1 addition & 8 deletions docker-compose.production.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,12 @@ version: "3"
services:
gateway:
restart: unless-stopped
image: jonasal/nginx-certbot
depends_on:
- api
ports:
- "${CORELLE_HTTP_PORT}:80"
- "${CORELLE_HTTPS_PORT}:443"
environment:
- CERTBOT_EMAIL
# Substitute in value for SPARROW_DOMAIN
# - CORELLE_DOMAIN
volumes:
# Swap out nginx conf for a certbot version
- ./conf/nginx.certbot.conf:/etc/nginx/user_conf.d/site.conf:ro
- ./conf/nginx.conf:/etc/nginx/nginx.conf:ro
api:
restart: unless-stopped
database:
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ Flask
Flask-Restful
simplejson
fiona
SQLAlchemy==1.4
werkzeug==2.0.0