Giter Club home page Giter Club logo

flask's Introduction

Deploy Flask on Platform.sh

Contribute, request a feature, or check out our resources

Join our community       Documentation       Blog       Report a bug       Request a feature

Open issues    Open PRs    License   


Contents

About       Features       Getting started       Customizations       Local Development       Learn       Contribute      

About

This template demonstrates building the Flask framework for Platform.sh. It includes a minimalist application skeleton that demonstrates how to connect to a MariaDB server for data storage and Redis for caching. The application starts as a bare Python process with no separate runner. It is intended for you to use as a starting point and modify for your own needs.

Flask is a lightweight web microframework for Python.

Features

  • Python 3.7
  • Flask 2
  • MariaDB 10.4
  • Redis 5.0
  • Automatic TLS certificates
  • Pipfile-based build

Getting Started

Deploy

Quickstart

The quickest way to deploy this template on Platform.sh is by clicking the button below. This will automatically create a new project and initialize the repository for you.

Deploy on Platform.sh


Other deployment options

For all of the other options below, clone this repository first:

git clone https://github.com/platformsh-templates/flask

If you're trying to deploy from GitHub, you can generate a copy of this repository first in your own namespace by clicking the Use this template button at the top of this page.

Then you can clone a copy of it locally with git clone [email protected]:YOUR_NAMESPACE/flask.git.

Deploy directly to Platform.sh from the command line
  1. Create a free trial:

    Register for a 30 day free trial with Platform.sh. When you have completed signup, select the Create from scratch project option. Give you project a name, and select a region where you would like it to be deployed. As for the Production environment option, make sure to match it to this repository's settings, or to what you have updated the default branch to locally.

  2. Install the Platform.sh CLI

    Linux/OSX

    curl -sS https://platform.sh/cli/installer | php

    Windows

    curl -f https://platform.sh/cli/installer -o cli-installer.php
    php cli-installer.php

    You can verify the installation by logging in (platformsh login) and listing your projects (platform project:list).

  3. Set the project remote

    Find your PROJECT_ID by running the command platform project:list

    +---------------+------------------------------------+------------------+---------------------------------+
    | ID            | Title                              | Region           | Organization                    |
    +---------------+------------------------------------+------------------+---------------------------------+
    | PROJECT_ID    | Your Project Name                  | xx-5.platform.sh | your-username                   |
    +---------------+------------------------------------+------------------+---------------------------------+

    Then from within your local copy, run the command platform project:set-remote PROJECT_ID.

  4. Push

    git push platform DEFAULT_BRANCH
Integrate with a GitHub repo and deploy pull requests
  1. Create a free trial:

    Register for a 30 day free trial with Platform.sh. When you have completed signup, select the Create from scratch project option. Give you project a name, and select a region where you would like it to be deployed. As for the Production environment option, make sure to match it to whatever you have set at https://YOUR_NAMESPACE/flask.

  2. Install the Platform.sh CLI

    Linux/OSX

    curl -sS https://platform.sh/cli/installer | php

    Windows

    curl -f https://platform.sh/cli/installer -o cli-installer.php
    php cli-installer.php

    You can verify the installation by logging in (platformsh login) and listing your projects (platform project:list).

  3. Setup the integration:

    Consult the GitHub integration documentation to finish connecting your repository to a project on Platform.sh. You will need to create an Access token on GitHub to do so.

Integrate with a GitLab repo and deploy merge requests
  1. Create a free trial:

    Register for a 30 day free trial with Platform.sh. When you have completed signup, select the Create from scratch project option. Give you project a name, and select a region where you would like it to be deployed. As for the Production environment option, make sure to match it to this repository's settings, or to what you have updated the default branch to locally.

  2. Install the Platform.sh CLI

    Linux/OSX

    curl -sS https://platform.sh/cli/installer | php

    Windows

    curl -f https://platform.sh/cli/installer -o cli-installer.php
    php cli-installer.php

    You can verify the installation by logging in (platformsh login) and listing your projects (platform project:list).

  3. Create the repository

    Create a new repository on GitLab, set it as a new remote for your local copy, and push to the default branch.

  4. Setup the integration:

    Consult the GitLab integration documentation to finish connecting a repository to a project on Platform.sh. You will need to create an Access token on GitLab to do so.

Integrate with a Bitbucket repo and deploy pull requests
  1. Create a free trial:

    Register for a 30 day free trial with Platform.sh. When you have completed signup, select the Create from scratch project option. Give you project a name, and select a region where you would like it to be deployed. As for the Production environment option, make sure to match it to this repository's settings, or to what you have updated the default branch to locally.

  2. Install the Platform.sh CLI

    Linux/OSX

    curl -sS https://platform.sh/cli/installer | php

    Windows

    curl -f https://platform.sh/cli/installer -o cli-installer.php
    php cli-installer.php

    You can verify the installation by logging in (platformsh login) and listing your projects (platform project:list).

  3. Create the repository

    Create a new repository on Bitbucket, set it as a new remote for your local copy, and push to the default branch.

  4. Setup the integration:

    Consult the Bitbucket integration documentation to finish connecting a repository to a project on Platform.sh. You will need to create an Access token on Bitbucket to do so.

Next steps

With your application now deployed on Platform.sh, things get more interesting. Run the command platform environment:branch new-feature for your project, or open a trivial pull request off of your current branch.

The resulting environment is an exact copy of production. It contains identical infrastructure to what's been defined in your configuration files, and even includes data copied from your production environment in its services. On this isolated environment, you're free to make any changes to your application you need to, and really test how they will behave on production.

After that, here are a collection of additional resources you might find interesting as you continue with your migration to Platform.sh:

Customizations

The following files have been added to a basic Flask configuration. If using this project as a reference for your own existing project, replicate the changes below to your project.

  • The .platform.app.yaml, .platform/services.yaml, and .platform/routes.yaml files have been added. These provide Platform.sh-specific configuration and are present in all projects on Platform.sh. You may customize them as you see fit.
  • An additional Pip library, platformshconfig, has been added. It provides convenience wrappers for accessing the Platform.sh environment variables.
  • A rudimentary application is included in server.py for demonstration purposes. It shows the basic process of starting the server and connecting to the MariaDB database. Modify and replace it as desired.

Local Development

Platform.sh provides support for locally running a Flask application that has been deployed on Platform.sh including its services. This means that once you download the code of the Flask project you deployed on Platform.sh, you can make changes to the project without pushing to Platform.sh each time to test them. You can build your app locally using the Platform.sh CLI, even when its functionality depends on a number of services. You can run your Flaks application locally with all of it’s services by following these steps:

  • Download your deployed code by running the following command using the Platform.sh CLI:

    platform get <PROJECT_ID>
  • Create a new branch. Whenever you develop Platform.sh, you should develop in an isolated environment. This way you aren’t opening SSH tunnels to your production environment. By creating a branch from your default environment, you create a new environment with copies of all production code and data.

    Create an isolated environment named updates by running the following command:

    platform environment:branch updates
    
  • Expose a port for your application to run on by running the following command in your terminal:

    export PORT=8000
    
  • Install all the dependencies your application needs.

    pipenv --three install
    
  • Open a SSH tunnel to the environment’s database and services:

    platform tunnel:open
    
  • Add an environment variable that contains the service credentials:

    export PLATFORM_RELATIONSHIPS="$(platform tunnel:info --encode)"
  • Run the application server

    pipenv run python server.py
    

    Now your Flask app should be running locally with a connection to a remote database that’s separate from your production database.

Note:

For many of the steps above, you may need to include the CLI flags -p PROJECT_ID and -e ENVIRONMENT_ID if you are not in the project directory or if the environment is associated with an existing pull request.

Learn

Troubleshooting

Accessing logs

After the environment has finished its deployment, you can investigate issues that occured on startup, deploy and post_deploy hooks, and generally at runtime using the CLI. Run the command:

platform ssh

If you are running the command outside of a local copy of the project, you will need to include the -p (project) and/or -e (environment) flags as well. Once you have connected to the container, logs are available within /var/log/ for you to investigate.

Blackfire.io: creating a Continuous Observability Strategy

This template includes a starting .blackfire.yml file that can be used to enable Application Performance Monitoring, Profiling, Builds and Performance Testing on your project. Platform.sh comes with Blackfire pre-installed on application containers, and setting up requires minimal configuration.

Resources

Contact

This template is maintained by the Platform.sh Developer Relations team, and they will be notified of all issues and pull requests you open here.

  • Community: Share your question with the community, or see if it's already been asked on our Community site.
  • Slack: If you haven't done so already, you can join Platform.sh's public Slack channels and ping the @devrel_team with any questions.

About Platform.sh

This template has been specifically designed to deploy on Platform.sh.

What is Platform.sh?

Platform.sh is a unified, secure, enterprise-grade platform for building, running and scaling web applications. We’re the leader in Fleet Ops: Everything you need to manage your fleet of websites and apps is available from the start. Because infrastructure and workflows are handled from the start, apps just work, so teams can focus on what really matters: making faster changes, collaborating confidently, and scaling responsibly. Whether managing a fleet of ten or ten thousand sites and apps, Platform.sh is the Developer- preferred solution that scales right.

Our key features include:

To find out more, check out the demo below and go to our website.


The Platform.sh demo

Contribute

Help us keep top-notch templates!

Every one of our templates is open source, and they're important resources for users trying to deploy to Platform.sh for the first time or better understand the platform. They act as getting started guides, but also contain a number of helpful tips and best practices when working with certain languages and frameworks.

See something that's wrong with this template that needs to be fixed? Something in the documentation unclear or missing? Let us know!

How to contribute

Report a bug       Submit a feature request       Open a pull request      


Need help?

Ask the Platform.sh Community       Join us on Slack      


Thanks to all of our amazing contributors!


Made with contrib.rocks


flask's People

Contributors

chadwcarlson avatar crell avatar hacktivist123 avatar otaviojava avatar platformsh-devrel avatar rudyweber avatar

Watchers

 avatar  avatar  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.