|
2 | 2 |
|
3 | 3 | [](https://portal.defang.dev/redirect?url=https%3A%2F%2Fgithub.com%2Fnew%3Ftemplate_name%3Dsample-flask-template%26template_owner%3DDefangSamples) |
4 | 4 |
|
5 | | -This is a sample of a basic Flask TODO app. The items are stored in memory and are lost when the server is restarted, but it should give you a basic idea of how to get started with Flask on Defang. Note that alognside your .py file, include a requirements.txt so that the Dockerfile can install the necessary packages with pip. |
| 5 | +This is a basic Flask to-do app that can be deployed with Defang. Note that alongside your `.py` file, include a `requirements.txt` so that the Dockerfile can install the necessary packages with pip. |
6 | 6 |
|
7 | | -### NOTE: |
| 7 | +This project is intended to provide a basic understanding of how to get started with Flask on Defang. The items are stored in memory and are lost when the server is restarted. **It is not intended for production use**. If you need something production ready, you should use a managed database like Postgres or MySQL. |
8 | 8 |
|
9 | | -This sample is a simple Flask app that demonstrates how to create a TODO app using Flask. The items are stored in memory and are lost when the server is restarted. This sample is intended to provide a basic understanding of how to get started with Flask on Defang. **it is not intended for production use**. If you need something production ready, you should use a managed database like Postgres or MySQL. |
| 9 | +## Prerequisites |
10 | 10 |
|
11 | | -## Essential Setup Files |
| 11 | +1. Download [Defang CLI](https://github.com/DefangLabs/defang) |
| 12 | +2. (Optional) If you are using [Defang BYOC](https://docs.defang.io/docs/concepts/defang-byoc) authenticate with your cloud provider account |
| 13 | +3. (Optional for local development) [Docker CLI](https://docs.docker.com/engine/install/) |
12 | 14 |
|
13 | | -1. A [Dockerfile](https://docs.docker.com/develop/develop-images/dockerfile_best-practices/). |
14 | | -2. A [compose file](https://docs.defang.io/docs/concepts/compose) to define and run multi-container Docker applications (this is how Defang identifies services to be deployed). |
15 | | -3. A [.dockerignore](https://docs.docker.com/build/building/context/#dockerignore-files) to ignore files that are not needed in the Docker image or will be generated during the build process. |
| 15 | +## Development |
16 | 16 |
|
17 | | -## Prerequisite |
| 17 | +To run the application locally, you can use the following command: |
18 | 18 |
|
19 | | -1. Download [Defang CLI](https://github.com/DefangLabs/defang) |
20 | | -2. If you are using [Defang BYOC](https://docs.defang.io/docs/concepts/defang-byoc), make sure you have properly [authenticated your AWS account (optional)](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html) |
| 19 | +```bash |
| 20 | +docker compose up --build |
| 21 | +``` |
| 22 | + |
| 23 | +## Configuration |
| 24 | + |
| 25 | +For this sample, you will not need to provide [configuration](https://docs.defang.io/docs/concepts/configuration). |
| 26 | + |
| 27 | +If you wish to provide configuration, see below for an example of setting a configuration for a value named `API_KEY`. |
| 28 | + |
| 29 | +```bash |
| 30 | +defang config set API_KEY |
| 31 | +``` |
| 32 | + |
| 33 | +## Deployment |
| 34 | + |
| 35 | +> [!NOTE] |
| 36 | +> Download [Defang CLI](https://github.com/DefangLabs/defang) |
| 37 | +
|
| 38 | +### Defang Playground |
| 39 | + |
| 40 | +Deploy your application to the Defang Playground by opening up your terminal and typing: |
| 41 | +```bash |
| 42 | +defang compose up |
| 43 | +``` |
21 | 44 |
|
22 | | -## A Step-by-Step Guide |
| 45 | +### BYOC (AWS) |
23 | 46 |
|
24 | | -1. Open the terminal and type `defang login` |
25 | | -2. Type `defang compose up` in the CLI |
26 | | -3. Your app should be up and running with Defang in minutes! |
| 47 | +If you want to deploy to your own cloud account, you can use Defang BYOC: |
27 | 48 |
|
28 | | -## One click deployment |
| 49 | +1. [Authenticate your AWS account](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html), and check that you have properly set your environment variables like `AWS_PROFILE`, `AWS_REGION`, `AWS_ACCESS_KEY_ID`, and `AWS_SECRET_ACCESS_KEY`. |
| 50 | +2. Run in a terminal that has access to your AWS environment variables: |
| 51 | + ```bash |
| 52 | + defang --provider=aws compose up |
| 53 | + ``` |
29 | 54 |
|
30 | 55 | --- |
31 | 56 |
|
32 | 57 | Title: Flask |
33 | 58 |
|
34 | | -Short Description: A basic Flask to do app. |
| 59 | +Short Description: A basic Flask to-do app. |
35 | 60 |
|
36 | 61 | Tags: Flask, Python |
37 | 62 |
|
|
0 commit comments