Skip to content

Commit 4d3d6c2

Browse files
committed
Release v1.0.6
1 parent e7e94e9 commit 4d3d6c2

File tree

12 files changed

+109
-84
lines changed

12 files changed

+109
-84
lines changed

.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
DEBUG=True
22

33
FLASK_APP=run.py
4-
FLASK_ENV=development
4+
FLASK_DEBUG=1
55

66
ASSETS_ROOT=/static/assets
77

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
# Change Log
22

3+
## [1.0.6] 2023-10-08
4+
### Changes
5+
6+
- Update Dependencies
7+
- Silent fallback to SQLite
8+
- CI/CD for Render
9+
310
## [1.0.5] 2022-06-11
4-
### Improvements
11+
### Changes
512

613
- Built with [Light Bootstrap Generator](https://appseed.us/generator/light-bootstrap-dashboard/)
714
- Timestamp: `2022-06-11 12:19`

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM python:3.9
1+
FROM python:3.10
22

33
# set environment variables
44
ENV PYTHONDONTWRITEBYTECODE 1

apps/__init__.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
Copyright (c) 2019 - present AppSeed.us
44
"""
55

6+
import os
7+
68
from flask import Flask
79
from flask_login import LoginManager
810
from flask_sqlalchemy import SQLAlchemy
@@ -28,7 +30,18 @@ def configure_database(app):
2830

2931
@app.before_first_request
3032
def initialize_database():
31-
db.create_all()
33+
try:
34+
db.create_all()
35+
except Exception as e:
36+
37+
print('> Error: DBMS Exception: ' + str(e) )
38+
39+
# fallback to SQLite
40+
basedir = os.path.abspath(os.path.dirname(__file__))
41+
app.config['SQLALCHEMY_DATABASE_URI'] = SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'db.sqlite3')
42+
43+
print('> Fallback to SQLite ')
44+
db.create_all()
3245

3346
@app.teardown_request
3447
def shutdown_session(exception=None):

apps/config.py

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,57 @@
33
Copyright (c) 2019 - present AppSeed.us
44
"""
55

6-
import os
6+
import os, random, string
77

88
class Config(object):
99

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

12+
# Assets Management
13+
ASSETS_ROOT = os.getenv('ASSETS_ROOT', '/static/assets')
14+
1215
# Set up the App SECRET_KEY
13-
# SECRET_KEY = config('SECRET_KEY' , default='S#perS3crEt_007')
14-
SECRET_KEY = os.getenv('SECRET_KEY', 'S#perS3crEt_007')
16+
SECRET_KEY = os.getenv('SECRET_KEY', None)
17+
if not SECRET_KEY:
18+
SECRET_KEY = ''.join(random.choice( string.ascii_lowercase ) for i in range( 32 ))
1519

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

20-
# Assets Management
21-
ASSETS_ROOT = os.getenv('ASSETS_ROOT', '/static/assets')
22+
DB_ENGINE = os.getenv('DB_ENGINE' , None)
23+
DB_USERNAME = os.getenv('DB_USERNAME' , None)
24+
DB_PASS = os.getenv('DB_PASS' , None)
25+
DB_HOST = os.getenv('DB_HOST' , None)
26+
DB_PORT = os.getenv('DB_PORT' , None)
27+
DB_NAME = os.getenv('DB_NAME' , None)
28+
29+
USE_SQLITE = True
30+
31+
# try to set up a Relational DBMS
32+
if DB_ENGINE and DB_NAME and DB_USERNAME:
33+
34+
try:
35+
36+
# Relational DBMS: PSQL, MySql
37+
SQLALCHEMY_DATABASE_URI = '{}://{}:{}@{}:{}/{}'.format(
38+
DB_ENGINE,
39+
DB_USERNAME,
40+
DB_PASS,
41+
DB_HOST,
42+
DB_PORT,
43+
DB_NAME
44+
)
45+
46+
USE_SQLITE = False
47+
48+
except Exception as e:
49+
50+
print('> Error: DBMS Exception: ' + str(e) )
51+
print('> Fallback to SQLite ')
52+
53+
if USE_SQLITE:
54+
55+
# This will create a file in <app> FOLDER
56+
SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'db.sqlite3')
2257

2358
class ProductionConfig(Config):
2459
DEBUG = False
@@ -28,15 +63,6 @@ class ProductionConfig(Config):
2863
REMEMBER_COOKIE_HTTPONLY = True
2964
REMEMBER_COOKIE_DURATION = 3600
3065

31-
# PostgreSQL database
32-
SQLALCHEMY_DATABASE_URI = '{}://{}:{}@{}:{}/{}'.format(
33-
os.getenv('DB_ENGINE' , 'mysql'),
34-
os.getenv('DB_USERNAME' , 'appseed_db_usr'),
35-
os.getenv('DB_PASS' , 'pass'),
36-
os.getenv('DB_HOST' , 'localhost'),
37-
os.getenv('DB_PORT' , 3306),
38-
os.getenv('DB_NAME' , 'appseed_db')
39-
)
4066

4167
class DebugConfig(Config):
4268
DEBUG = True

build.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
# exit on error
3+
set -o errexit
4+
5+
python -m pip install --upgrade pip
6+
7+
pip install -r requirements.txt

env.sample

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ DEBUG=True
33

44
# Flask ENV
55
FLASK_APP=run.py
6-
FLASK_ENV=development
6+
FLASK_DEBUG=1
77
SECRET_KEY=YOUR_SUPER_KEY
88

99
# If DEBUG=False (production mode)
10-
DB_ENGINE=mysql
11-
DB_NAME=appseed_db
12-
DB_HOST=localhost
13-
DB_PORT=3306
14-
DB_USERNAME=appseed_db_usr
15-
DB_PASS=<STRONG_PASS>
10+
# DB_ENGINE=mysql
11+
# DB_NAME=appseed_db
12+
# DB_HOST=localhost
13+
# DB_PORT=3306
14+
# DB_USERNAME=appseed_db_usr
15+
# DB_PASS=<STRONG_PASS>

log.json

Lines changed: 0 additions & 23 deletions
This file was deleted.

package.json

Lines changed: 0 additions & 20 deletions
This file was deleted.

render.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
services:
2+
- type: web
3+
name: flask-light-bootstrap
4+
plan: starter
5+
env: python
6+
region: frankfurt # region should be same as your database region.
7+
buildCommand: "./build.sh"
8+
startCommand: "gunicorn run:app"
9+
envVars:
10+
- key: SECRET_KEY
11+
generateValue: true
12+
- key: WEB_CONCURRENCY
13+
value: 4

0 commit comments

Comments
 (0)