Giter Site home page Giter Site logo

callmefredcom / railwaydeploy Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 10 KB

Boilerplate of a Flask Web App ready to be deployed on Railway.app

Home Page: https://youtu.be/QM4dhbCqres

Procfile 0.24% Python 34.05% HTML 29.29% JavaScript 35.25% CSS 1.18%
flask mysql mysql-database railway-app

railwaydeploy's Introduction

The files you need in your app configuration to deploy it to Railway

Watch the full video tutorial: How to Deploy a Flask App to Railway

.gitignore

Procfile

requirements.txt

.gitignore

This is where you’ll declare the files you don’t want to commit to your GitHub repo (e.g. .env file). Remember that you'll need a .env local file to store your environment variables for local testing.

Procfile (to start the deployment)

web: gunicorn **main**:app

generate requirements.txt

This will list all the packages you’ll need to install on your server.

pip install pipreqs

pipreqs .
pipreqs . --force to regenerate the requirements.txt file
pipreqs . --ignore .venv to ignore a specific directory

Make sure you’re using those packages (sometimes pipreqs can suggest the wrong ones)

mysql-connector-python==8.0.33
gunicorn==21.1.0

MySQL DB Connection logic. Quick boilerplate to get you started.

from flask import **g**
import mysql.connector
from dotenv import load_dotenv
import os

load_dotenv()
# get sql pw from .env
db_password = os.environ.get('MYSQLPASSWORD')

# MySQL configuration
DATABASE_URL = f"mysql -hroundhouse.proxy.rlwy.net -uroot -p{db_password} --port 50259 --protocol=TCP railway"

DATABASE_CONFIG = {
            'user': 'root',
            'password': os.environ.get('MYSQLPASSWORD'),
            'host': 'roundhouse.proxy.rlwy.net',
            'port': '50259',
            'database': 'railway'
        }

def get_db():
    if hasattr(g, 'db_conn') and g.db_conn.is_connected():
        return g.db_conn
    else:
        g.db_conn = mysql.connector.connect(**DATABASE_CONFIG)
        return g.db_conn

@app.teardown_appcontext
def close_db_connection(exception):
    db = getattr(g, 'db_conn', None)
    if db is not None:
        db.close()

railwaydeploy's People

Contributors

callmefredcom avatar

Stargazers

Yann-Aël Le Borgne avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.