Skip to content

Instantly share code, notes, and snippets.

@chadwcarlson
Created August 30, 2023 20:08
Show Gist options
  • Save chadwcarlson/f4697706dda4cf4db34b384da84b2987 to your computer and use it in GitHub Desktop.
Save chadwcarlson/f4697706dda4cf4db34b384da84b2987 to your computer and use it in GitHub Desktop.
Flask (cookiecutter-flask) local on Platform.sh
#!/usr/bin/env bash
# Cleanup
rm -rf env
rm -rf migrations
rm -rf Platformify_Cookies/static
rm -rf node_modules
platform tunnel:close -y
# Setup a virtual environment
python3 -m venv env
source env/bin/activate
# Install dependencies
pip install --upgrade pip
pip install -r requirements.txt
npm install
# setup local
platform tunnel:open -y
export PLATFORM_RELATIONSHIPS="$(platform tunnel:info --encode)"
# Mock vars
export PORT=8888
export PLATFORM_PROJECT_ENTROPY=oooososupersecretshhh
export PLATFORM_ENVIRONMENT_TYPE=production
source .environment
# static files
npm run build
# Migrations
flask db init
flask db migrate
flask db upgrade
# run the server
# (DEV)
# flask run -p $PORT
# (PROD)
gunicorn -w 4 'app:app'
@chadwcarlson
Copy link
Author

  • Using a dev server
web:
  commands:
    start: flask run -p $PORT
  locations:
    "/":
      passthru: true
  • Using gunicorn + PORT
web:
  commands:
    start: gunicorn -w 4 'app:app'
  locations:
    "/":
      passthru: true
  • Using gunicorn + SOCKET (requires unix)

    • source env/bin/activate
    • pip install unix
    • pip freeze
web:
  commands:
    start: gunicorn -w 4 -b unix:$SOCKET 'app:app'
  upstream:
    socket_family: unix
  locations:
    "/":
      passthru: true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment