Update Dockerfile and docker-compose for /opt/moto_site structure and reliable Docker deployment
This commit is contained in:
@@ -94,21 +94,22 @@ def create_app(config_name=None):
|
||||
os.makedirs(os.path.join(upload_dir, 'gpx'), exist_ok=True)
|
||||
|
||||
# --- Initial Admin Creation from .env ---
|
||||
from app.models import User
|
||||
with app.app_context():
|
||||
admin_email = os.environ.get('ADMIN_EMAIL')
|
||||
admin_nickname = os.environ.get('ADMIN_NICKNAME')
|
||||
admin_password = os.environ.get('ADMIN_PASSWORD')
|
||||
if admin_email and admin_nickname and admin_password:
|
||||
if not User.query.filter_by(email=admin_email).first():
|
||||
user = User(nickname=admin_nickname, email=admin_email, is_admin=True, is_active=True)
|
||||
user.set_password(admin_password)
|
||||
db.session.add(user)
|
||||
db.session.commit()
|
||||
print(f"[INFO] Admin user {admin_nickname} <{admin_email}> created from .env.")
|
||||
else:
|
||||
print(f"[INFO] Admin with email {admin_email} already exists.")
|
||||
else:
|
||||
print("[INFO] ADMIN_EMAIL, ADMIN_NICKNAME, or ADMIN_PASSWORD not set in .env. Skipping admin creation.")
|
||||
# Temporarily disabled for migration setup
|
||||
# from app.models import User
|
||||
# with app.app_context():
|
||||
# admin_email = os.environ.get('ADMIN_EMAIL')
|
||||
# admin_nickname = os.environ.get('ADMIN_NICKNAME')
|
||||
# admin_password = os.environ.get('ADMIN_PASSWORD')
|
||||
# if admin_email and admin_nickname and admin_password:
|
||||
# if not User.query.filter_by(email=admin_email).first():
|
||||
# user = User(nickname=admin_nickname, email=admin_email, is_admin=True, is_active=True)
|
||||
# user.set_password(admin_password)
|
||||
# db.session.add(user)
|
||||
# db.session.commit()
|
||||
# print(f"[INFO] Admin user {admin_nickname} <{admin_email}> created from .env.")
|
||||
# else:
|
||||
# print(f"[INFO] Admin with email {admin_email} already exists.")
|
||||
# else:
|
||||
# print("[INFO] ADMIN_EMAIL, ADMIN_NICKNAME, or ADMIN_PASSWORD not set in .env. Skipping admin creation.")
|
||||
|
||||
return app
|
||||
|
||||
Reference in New Issue
Block a user