├── .gitignore ├── gunicorn_config.py ├── Procfile ├── .do ├── app.yaml └── deploy.template.yaml ├── requirements.txt ├── app.py ├── LICENSE ├── .github └── dependabot.yaml ├── README.md └── templates └── index.html /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | __pycache__/* 3 | -------------------------------------------------------------------------------- /gunicorn_config.py: -------------------------------------------------------------------------------- 1 | bind = "0.0.0.0:8080" 2 | workers = 2 3 | -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | web: gunicorn --worker-tmp-dir /dev/shm --config gunicorn_config.py app:app 2 | -------------------------------------------------------------------------------- /.do/app.yaml: -------------------------------------------------------------------------------- 1 | name: sample-flask 2 | services: 3 | - name: web 4 | github: 5 | repo: digitalocean/sample-flask 6 | branch: main -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | click==8.1.7 2 | Flask==3.0.3 3 | gunicorn==23.0.0 4 | itsdangerous==2.2.0 5 | Jinja2==3.1.4 6 | MarkupSafe==2.1.5 7 | Werkzeug==3.0.4 8 | -------------------------------------------------------------------------------- /.do/deploy.template.yaml: -------------------------------------------------------------------------------- 1 | spec: 2 | name: sample-flask 3 | services: 4 | - name: web 5 | git: 6 | branch: main 7 | repo_clone_url: https://github.com/0ndrec/sample-flask.git -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | from flask import Flask 2 | from flask import render_template 3 | 4 | app = Flask(__name__) 5 | 6 | 7 | @app.route("/") 8 | def hello_world(): 9 | return render_template("index.html") 10 | 11 | @app.route("/page") 12 | def page(): 13 | return render_template("index.html") 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 "0ndrec" 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.github/dependabot.yaml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 5 | # borrowed from https://github.com/dependabot/dependabot-core/blob/main/.github/dependabot.yml 6 | 7 | version: 2 8 | updates: 9 | - package-ecosystem: "bundler" 10 | directory: "/" 11 | schedule: 12 | interval: "daily" 13 | groups: 14 | dev-dependencies: 15 | dependency-type: "development" 16 | update-types: 17 | - "minor" 18 | - "patch" 19 | - package-ecosystem: "composer" 20 | directory: "/" 21 | schedule: 22 | interval: "daily" 23 | groups: 24 | dev-dependencies: 25 | dependency-type: "development" 26 | update-types: 27 | - "minor" 28 | - "patch" 29 | - package-ecosystem: "docker" 30 | directory: "/" 31 | schedule: 32 | interval: "daily" 33 | - package-ecosystem: "github-actions" 34 | directory: "/" 35 | schedule: 36 | interval: "daily" 37 | - package-ecosystem: "gomod" 38 | directory: "/" 39 | schedule: 40 | interval: "daily" 41 | - package-ecosystem: "mix" 42 | directory: "/" 43 | schedule: 44 | interval: "daily" 45 | - package-ecosystem: "npm" 46 | directory: "/" 47 | schedule: 48 | interval: "daily" 49 | groups: 50 | dev-dependencies: 51 | dependency-type: "development" 52 | update-types: 53 | - "minor" 54 | - "patch" 55 | ignore: 56 | - dependency-name: "npm" 57 | update-types: ["version-update:semver-major"] 58 | - package-ecosystem: "pip" 59 | directory: "/" 60 | schedule: 61 | interval: "daily" 62 | - package-ecosystem: "pub" 63 | directory: "/" 64 | schedule: 65 | interval: "daily" 66 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Get Started 2 | 3 | This guide describes how to use DigitalOcean App Platform to run a sample Flask application. 4 | 5 | **Note**: Following these steps may result in charges for the use of DigitalOcean services. 6 | 7 | ### Requirements 8 | 9 | * You need a DigitalOcean account. If you do not already have one, first [sign up](https://cloud.digitalocean.com/registrations/new). 10 | 11 | ## Deploy the App 12 | 13 | Click the following button to deploy the app to App Platform. If you are not currently logged in with your DigitalOcean account, this button prompts you to to log in. 14 | 15 | [![Deploy to DigitalOcean](https://www.deploytodo.com/do-btn-blue.svg)](https://cloud.digitalocean.com/apps/new?repo=https://github.com/digitalocean/sample-flask/tree/main) 16 | 17 | Note that, for the purposes of this tutorial, this button deploys the app directly from DigitalOcean's GitHub repository, which disables automatic redeployment since you cannot change our template. If you want automatic redeployment or you want to change the sample app's code to your own, we instead recommend you fork [our repository](https://github.com/digitalocean/sample-flask/tree/main). 18 | 19 | To fork our repository, click the **Fork** button in the top-right of [its page on GitHub](https://github.com/digitalocean/sample-flask/tree/main), then follow the on-screen instructions. To learn more about forking repos, see the [GitHub documentation](https://docs.github.com/en/github/getting-started-with-github/fork-a-repo). 20 | 21 | After forking the repo, you can view the same README in your own GitHub org; for example, in `https://github.com//sample-flask`. To deploy the new repo, visit the [control panel](https://cloud.digitalocean.com/apps) and click the **Create App** button. This takes you to the app creation page. Under **Service Provider**, select **GitHub**. Then, under **Repository**, select your newly-forked repo. Ensure that your branch is set to **main** and **Autodeploy** is checked on. Finally, click **Next**. 22 | 23 | After clicking the **Deploy to DigitalOcean** button or completing the instructions above to fork the repo, follow these steps: 24 | 25 | 1. Configure the app, such as by specifying HTTP routes, declaring environment variables, or adding a database. For the purposes of this tutorial, this step is optional. 26 | 1. Provide a name for your app and select the region to deploy your app to, then click **Next**. By default, App Platform selects the region closest to you. Unless your app needs to interface with external services, your chosen region does not affect the app's performance, since to all App Platform apps are routed through a global CDN. 27 | 1. On the following screen, leave all the fields as they are and click **Next**. 28 | 1. Confirm your plan settings and how many containers you want to launch and click **Launch Basic/Pro App**. 29 | 30 | After, you should see a "Building..." progress indicator. You can click **View Logs** to see more details of the build. It can take a few minutes for the build to finish, but you can follow the progress in the **Deployments** tab. 31 | 32 | Once the build completes successfully, click the **Live App** link in the header and you should see your running application in a new tab, displaying the home page. 33 | 34 | 35 | ## Make Changes to Your App 36 | 37 | If you forked our repo, you can now make changes to your copy of the sample app. Pushing a new change to the forked repo automatically redeploys the app to App Platform with zero downtime. 38 | 39 | Here's an example code change you can make for this app: 40 | 41 | 1. Edit `templates/index.html` and replace "Welcome to your new Flask App!" with a different greeting 42 | 1. Commit the change to the `main` branch. Normally it's a better practice to create a new branch for your change and then merge that branch to `main` after review, but for this demo you can commit to the `main` branch directly. 43 | 1. Visit the [control panel](https://cloud.digitalocean.com/apps) and navigate to your sample app. 44 | 1. You should see a "Building..." progress indicator, just like when you first created the app. 45 | 1. Once the build completes successfully, click the **Live App** link in the header and you should see your updated application running. You may need to force refresh the page in your browser (e.g. using **Shift** + **Reload**). 46 | 47 | ## Learn More 48 | 49 | To learn more about App Platform and how to manage and update your application, see [our App Platform documentation](https://www.digitalocean.com/docs/app-platform/). 50 | 51 | ## Delete the App 52 | 53 | When you no longer need this sample application running live, you can delete it by following these steps: 54 | 1. Visit the [Apps control panel](https://cloud.digitalocean.com/apps). 55 | 2. Navigate to the sample app. 56 | 3. In the **Settings** tab, click **Destroy**. 57 | 58 | **Note**: If you do not delete your app, charges for using DigitalOcean services will continue to accrue. 59 | -------------------------------------------------------------------------------- /templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Your New Flask App 8 | 9 | 11 | 12 | 13 | 14 |
15 |
16 | DigitalOcean Logo 17 |

Welcome to your new Flask App!

18 | 19 |

20 | This application is an example of how to deploy a Flask Application to DigitalOcean's App 21 | Platform. Check out their documentation to 22 | learn more about flask. 23 |

24 | 25 |
26 | 27 | 43 |
44 | 45 |
46 | 47 | 48 | 49 | 50 | 51 |
52 | 53 | 258 | 259 | 260 | 261 | --------------------------------------------------------------------------------