Skip to content

Commit

Permalink
Release v1.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
app-generator committed Oct 8, 2023
1 parent e7e94e9 commit 4d3d6c2
Show file tree
Hide file tree
Showing 12 changed files with 109 additions and 84 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
DEBUG=True

FLASK_APP=run.py
FLASK_ENV=development
FLASK_DEBUG=1

ASSETS_ROOT=/static/assets

Expand Down
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
# Change Log

## [1.0.6] 2023-10-08
### Changes

- Update Dependencies
- Silent fallback to SQLite
- CI/CD for Render

## [1.0.5] 2022-06-11
### Improvements
### Changes

- Built with [Light Bootstrap Generator](https://appseed.us/generator/light-bootstrap-dashboard/)
- Timestamp: `2022-06-11 12:19`
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.9
FROM python:3.10

# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
Expand Down
15 changes: 14 additions & 1 deletion apps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Copyright (c) 2019 - present AppSeed.us
"""

import os

from flask import Flask
from flask_login import LoginManager
from flask_sqlalchemy import SQLAlchemy
Expand All @@ -28,7 +30,18 @@ def configure_database(app):

@app.before_first_request
def initialize_database():
db.create_all()
try:
db.create_all()
except Exception as e:

print('> Error: DBMS Exception: ' + str(e) )

# fallback to SQLite
basedir = os.path.abspath(os.path.dirname(__file__))
app.config['SQLALCHEMY_DATABASE_URI'] = SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'db.sqlite3')

print('> Fallback to SQLite ')
db.create_all()

@app.teardown_request
def shutdown_session(exception=None):
Expand Down
60 changes: 43 additions & 17 deletions apps/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,57 @@
Copyright (c) 2019 - present AppSeed.us
"""

import os
import os, random, string

class Config(object):

basedir = os.path.abspath(os.path.dirname(__file__))

# Assets Management
ASSETS_ROOT = os.getenv('ASSETS_ROOT', '/static/assets')

# Set up the App SECRET_KEY
# SECRET_KEY = config('SECRET_KEY' , default='S#perS3crEt_007')
SECRET_KEY = os.getenv('SECRET_KEY', 'S#perS3crEt_007')
SECRET_KEY = os.getenv('SECRET_KEY', None)
if not SECRET_KEY:
SECRET_KEY = ''.join(random.choice( string.ascii_lowercase ) for i in range( 32 ))

# This will create a file in <app> FOLDER
SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'db.sqlite3')
SQLALCHEMY_TRACK_MODIFICATIONS = False
SQLALCHEMY_TRACK_MODIFICATIONS = False

# Assets Management
ASSETS_ROOT = os.getenv('ASSETS_ROOT', '/static/assets')
DB_ENGINE = os.getenv('DB_ENGINE' , None)
DB_USERNAME = os.getenv('DB_USERNAME' , None)
DB_PASS = os.getenv('DB_PASS' , None)
DB_HOST = os.getenv('DB_HOST' , None)
DB_PORT = os.getenv('DB_PORT' , None)
DB_NAME = os.getenv('DB_NAME' , None)

USE_SQLITE = True

# try to set up a Relational DBMS
if DB_ENGINE and DB_NAME and DB_USERNAME:

try:

# Relational DBMS: PSQL, MySql
SQLALCHEMY_DATABASE_URI = '{}://{}:{}@{}:{}/{}'.format(
DB_ENGINE,
DB_USERNAME,
DB_PASS,
DB_HOST,
DB_PORT,
DB_NAME
)

USE_SQLITE = False

except Exception as e:

print('> Error: DBMS Exception: ' + str(e) )
print('> Fallback to SQLite ')

if USE_SQLITE:

# This will create a file in <app> FOLDER
SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'db.sqlite3')

class ProductionConfig(Config):
DEBUG = False
Expand All @@ -28,15 +63,6 @@ class ProductionConfig(Config):
REMEMBER_COOKIE_HTTPONLY = True
REMEMBER_COOKIE_DURATION = 3600

# PostgreSQL database
SQLALCHEMY_DATABASE_URI = '{}://{}:{}@{}:{}/{}'.format(
os.getenv('DB_ENGINE' , 'mysql'),
os.getenv('DB_USERNAME' , 'appseed_db_usr'),
os.getenv('DB_PASS' , 'pass'),
os.getenv('DB_HOST' , 'localhost'),
os.getenv('DB_PORT' , 3306),
os.getenv('DB_NAME' , 'appseed_db')
)

class DebugConfig(Config):
DEBUG = True
Expand Down
7 changes: 7 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
# exit on error
set -o errexit

python -m pip install --upgrade pip

pip install -r requirements.txt
14 changes: 7 additions & 7 deletions env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ DEBUG=True

# Flask ENV
FLASK_APP=run.py
FLASK_ENV=development
FLASK_DEBUG=1
SECRET_KEY=YOUR_SUPER_KEY

# If DEBUG=False (production mode)
DB_ENGINE=mysql
DB_NAME=appseed_db
DB_HOST=localhost
DB_PORT=3306
DB_USERNAME=appseed_db_usr
DB_PASS=<STRONG_PASS>
# DB_ENGINE=mysql
# DB_NAME=appseed_db
# DB_HOST=localhost
# DB_PORT=3306
# DB_USERNAME=appseed_db_usr
# DB_PASS=<STRONG_PASS>
23 changes: 0 additions & 23 deletions log.json

This file was deleted.

20 changes: 0 additions & 20 deletions package.json

This file was deleted.

13 changes: 13 additions & 0 deletions render.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
services:
- type: web
name: flask-light-bootstrap
plan: starter
env: python
region: frankfurt # region should be same as your database region.
buildCommand: "./build.sh"
startCommand: "gunicorn run:app"
envVars:
- key: SECRET_KEY
generateValue: true
- key: WEB_CONCURRENCY
value: 4
27 changes: 15 additions & 12 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
flask==2.0.2
Werkzeug==2.0.3
jinja2==3.0.2
flask_login==0.5.0
flask_migrate==3.1.0
WTForms==3.0.0
flask_wtf==1.0.0
flask_sqlalchemy==2.5.1
sqlalchemy==1.4.29
email_validator==1.1.3
gunicorn==20.1.0
flask-restx==0.5.1
flask==2.2.5
Werkzeug==2.3.7
jinja2==3.1.2
flask-login==0.6.2
flask_migrate==4.0.4
WTForms==3.0.1
flask_wtf==1.2.1
flask-sqlalchemy==3.0.5
sqlalchemy==2.0.21
email_validator==2.0.0
flask-restx==1.1.0

python-dotenv==0.19.2

gunicorn==20.1.0
Flask-Minify==0.37

# flask_mysqldb
# psycopg2-binary
1 change: 0 additions & 1 deletion run.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

if DEBUG:
app.logger.info('DEBUG = ' + str(DEBUG) )
app.logger.info('FLASK_ENV = ' + os.getenv('FLASK_ENV') )
app.logger.info('Page Compression = ' + 'FALSE' if DEBUG else 'TRUE' )
app.logger.info('DBMS = ' + app_config.SQLALCHEMY_DATABASE_URI)
app.logger.info('ASSETS_ROOT = ' + app_config.ASSETS_ROOT )
Expand Down

0 comments on commit 4d3d6c2

Please sign in to comment.