Skip to content

Commit

Permalink
full update to latest versions
Browse files Browse the repository at this point in the history
flask 2 and all new js stuff
needed to drop selenium tests as i don't know how to make them work
also moving from yarn to npm
  • Loading branch information
w00kie authored Aug 18, 2023
1 parent 12784d1 commit d2b6689
Show file tree
Hide file tree
Showing 16 changed files with 2,017 additions and 2,278 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.8-alpine as base
FROM python:3.9-alpine as base

FROM base as builder

Expand Down
11 changes: 4 additions & 7 deletions Dockerfile.test
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM joyzoursky/python-chromedriver:3.8-alpine3.10-selenium as base
FROM joyzoursky/python-chromedriver:3.9-selenium as base

FROM base as builder

Expand All @@ -7,11 +7,6 @@ WORKDIR /install

COPY requirements/test.txt /install/requirements.txt

RUN apk add --update \
g++ \
libxml2 \
libxml2-dev &&\
apk add libxslt-dev
RUN pip install --prefix=/install -r /install/requirements.txt

FROM base
Expand All @@ -23,6 +18,7 @@ WORKDIR ${INSTALL_PATH}
ARG GIT_COMMIT_SHA1_BUILD
ENV GIT_COMMIT_SHA1=${GIT_COMMIT_SHA1_BUILD}

ENV FLASK_APP=app
ENV FLASK_RUN_PORT=8000
EXPOSE ${FLASK_RUN_PORT}

Expand All @@ -32,4 +28,5 @@ COPY --from=builder /install /usr/local

COPY . .

ENTRYPOINT [ "flask", "run", "--cert=localhost.pem", "--key=localhost-key.pem", "--host=0.0.0.0" ]
CMD [ "flask", "run", "--host=0.0.0.0" ]
# ENTRYPOINT [ "flask", "run", "--cert=localhost.pem", "--key=localhost-key.pem", "--host=0.0.0.0" ]
11 changes: 5 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@ clean:
rm -rf screenshots

build-test:
docker-compose -f docker-compose.test.yml -p test build
docker compose -f docker-compose.test.yml build web

up:
docker-compose -f docker-compose.test.yml -p test up
docker compose -f docker-compose.test.yml up

down:
docker-compose -f docker-compose.test.yml -p test down
docker compose -f docker-compose.test.yml down

test: clean
docker-compose -f docker-compose.test.yml -p test \
run --rm --entrypoint green \
web -vvv --run-coverage
docker compose -f docker-compose.test.yml \
run web python -m coverage run -m pytest

build-cloudrun:
docker build --build-arg GIT_COMMIT_SHA1_BUILD \
Expand Down
98 changes: 42 additions & 56 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,111 +1,97 @@
import sys
import os
import json
from envparse import env
from urllib.parse import urlparse, urlunparse

import sentry_sdk
from sentry_sdk.integrations.flask import FlaskIntegration

from flask_cdn import CDN

import sunazymuth

from flask import Flask
from flask import request
from flask import render_template
from flask import redirect

import sunazymuth


###
# APP ENVIRONMENT SETUP
###

# Serve static files from web root
app = Flask(__name__, static_url_path='')
app = Flask(__name__, static_url_path="")

# Set static files location to CDN domain.
# Activates only when STATIC_DOMAIN env variable is set (only in Production)
app.config['CDN_DOMAIN'] = env('STATIC_DOMAIN', None)
app.config['CDN_HTTPS'] = True
app.config["CDN_DOMAIN"] = env("STATIC_DOMAIN", None)
app.config["CDN_HTTPS"] = True
CDN(app)

# Check if we are on local development machine (default is prod)
FLASK_ENV = env('FLASK_ENV', default='production')
FLASK_ENV = env("FLASK_ENV", default="production")

sha = env('GIT_COMMIT_SHA1', default='')
sha = env("GIT_COMMIT_SHA1", default="")

SENTRY_DSN = env('SENTRY_DSN', default='')
SENTRY_DSN = env("SENTRY_DSN", default="")
sentry_sdk.init(
dsn=SENTRY_DSN,
environment=FLASK_ENV,
release=sha,
integrations=[FlaskIntegration()]
dsn=SENTRY_DSN,
environment=FLASK_ENV,
release=sha,
integrations=[FlaskIntegration()],
)


###
# APP WEB REQUEST HANDLERS
###


# Route for INDEX
@app.route('/')
@app.route("/")
def index():
return render_template(
'index.html',
ANALYTICS=env('ANALYTICS', default='UA-XXXXXX-1'),
MAPS_API=env('MAPS_API', default='123456789')
)
return render_template(
"index.html",
ANALYTICS=env("ANALYTICS", default="UA-XXXXXX-1"),
MAPS_API=env("MAPS_API", default="123456789"),
)


# Output a list of sunset and sunrise azymuth for the whole year
# NOT USED NOW
@app.route('/getEphemerides', methods=['POST'])
@app.route("/getEphemerides", methods=["POST"])
def getEphemerides():
lat = float(request.form['lat'])
return json.dumps(sunazymuth.GetEphemerides(lat))
lat = request.json["lat"]
return sunazymuth.GetEphemerides(lat)


# Find 2 days matching the given azymuth
# Returns in JSON:
# - suntype = either "sunrise" or "sunset"
# - matches = array of 2 matching days, nothing if azymuth is out of bounds
@app.route('/findMatch', methods=['POST'])
# - suntype = either "sunrise" or "sunset"
# - matches = array of 2 matching days, nothing if azymuth is out of bounds
@app.route("/findMatch", methods=["POST"])
def findMatch():
data = request.get_json() or request.form
lat = data['lat']
az = float(data['az'])

fullyear = sunazymuth.GetEphemerides(float(lat))
data = request.json or request.form
lat = data["lat"]
az = float(data["az"])

return json.dumps(sunazymuth.GetMatchingDay(fullyear, az))
fullyear = sunazymuth.GetEphemerides(float(lat))

return sunazymuth.GetMatchingDay(fullyear, az)

###
# Boiler-plate stuff from github/flask_heroku
###
'''
@app.route('/<file_name>.txt')
def send_text_file(file_name):
"""Send your static text file. robots.txt etc."""
file_dot_text = file_name + '.txt'
return app.send_static_file(file_dot_text)
'''

@app.after_request
def add_header(response):
# Add header to track Sentry release
response.headers['X-Sentry-Release'] = sha
"""
Add headers to both force latest IE rendering engine or Chrome Frame,
and also to cache the rendered page for 10 minutes.
"""
response.headers['X-UA-Compatible'] = 'IE=Edge,chrome=1'
response.headers['Cache-Control'] = 'public, max-age=600'
return response
"""
Add headers to:
- Track Sentry release
- Force latest IE rendering engine or Chrome Frame,
- Cache the rendered page for 10 minutes.
"""
response.headers["X-Sentry-Release"] = sha
response.headers["X-UA-Compatible"] = "IE=Edge,chrome=1"
response.headers["Cache-Control"] = "public, max-age=600"
return response


@app.errorhandler(404)
def page_not_found(error):
"""Custom 404 page."""
return render_template('404.html'), 404
"""Custom 404 page."""
return render_template("404.html", ERROR=error), 404
Loading

0 comments on commit d2b6689

Please sign in to comment.