Skip to content

Commit 6cba37b

Browse files
authored
Merge pull request #262 from DefangLabs/linda-curl-consistency
Make curl use eval consistently
0 parents  commit 6cba37b

File tree

6 files changed

+154
-0
lines changed

6 files changed

+154
-0
lines changed

.github/workflows/deploy.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Deploy
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
deploy:
10+
environment: playground
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
id-token: write
15+
16+
steps:
17+
- name: Checkout Repo
18+
uses: actions/checkout@v4
19+
20+
- name: Deploy
21+
uses: DefangLabs/[email protected]

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Flask
2+
3+
[![1-click-deploy](https://defang.io/deploy-with-defang.png)](https://portal.defang.dev/redirect?url=https%3A%2F%2Fgithub.com%2Fnew%3Ftemplate_name%3Dsample-flask-template%26template_owner%3DDefangSamples)
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.
6+
7+
### NOTE:
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.
10+
11+
## Essential Setup Files
12+
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.
16+
17+
## Prerequisite
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)
21+
22+
## A Step-by-Step Guide
23+
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!
27+
28+
## One click deployment
29+
30+
---
31+
32+
Title: Flask
33+
34+
Short Description: A basic Flask to do app.
35+
36+
Tags: Flask, Python
37+
38+
Languages: python

compose.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
services:
2+
flask:
3+
restart: unless-stopped
4+
build:
5+
context: ./flask
6+
dockerfile: Dockerfile
7+
deploy:
8+
resources:
9+
reservations:
10+
cpus: "1.0"
11+
memory: 512M
12+
ports:
13+
- mode: ingress
14+
target: 5000
15+
published: 5000
16+
healthcheck:
17+
test: ["CMD", "python3", "-c", "import sys, urllib.request; urllib.request.urlopen(sys.argv[1]).read()", "http://localhost:5000/"]

flask/Dockerfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Use an official Python runtime as a base image
2+
FROM python:3.11-slim
3+
4+
# Set the working directory to /app
5+
WORKDIR /app
6+
7+
# Install required packages
8+
RUN apt-get update -qq \
9+
&& apt-get install -y --no-install-recommends \
10+
build-essential \
11+
python3-dev \
12+
&& apt-get clean \
13+
&& rm -rf /var/lib/apt/lists/*
14+
15+
# Copy the current directory contents into the container at /app
16+
COPY . /app
17+
18+
# Install any needed packages specified in requirements.txt
19+
COPY requirements.txt /app/
20+
RUN pip install --no-cache-dir -r requirements.txt
21+
22+
# Make port 5000 available to the world outside this container
23+
EXPOSE 5000
24+
25+
# Run app.py when the container launches
26+
CMD ["python", "app.py"]

flask/app.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from flask import Flask, jsonify, request, render_template_string
2+
3+
app = Flask(__name__)
4+
5+
# A simple in-memory structure to store tasks
6+
tasks = []
7+
8+
@app.route('/', methods=['GET'])
9+
def home():
10+
# Display existing tasks and a form to add a new task
11+
html = '''
12+
<!DOCTYPE html>
13+
<html>
14+
<head>
15+
<title>Todo List</title>
16+
</head>
17+
<body>
18+
<h1>Todo List</h1>
19+
<form action="/add" method="POST">
20+
<input type="text" name="task" placeholder="Enter a new task">
21+
<input type="submit" value="Add Task">
22+
</form>
23+
<ul>
24+
{% for task in tasks %}
25+
<li>{{ task }} <a href="/delete/{{ loop.index0 }}">x</a></li>
26+
{% endfor %}
27+
</ul>
28+
</body>
29+
</html>
30+
'''
31+
return render_template_string(html, tasks=tasks)
32+
33+
@app.route('/add', methods=['POST'])
34+
def add_task():
35+
# Add a new task from the form data
36+
task = request.form.get('task')
37+
if task:
38+
tasks.append(task)
39+
return home()
40+
41+
@app.route('/delete/<int:index>', methods=['GET'])
42+
def delete_task(index):
43+
# Delete a task based on its index
44+
if index < len(tasks):
45+
tasks.pop(index)
46+
return home()
47+
48+
if __name__ == '__main__':
49+
app.run(debug=True, host='0.0.0.0')

flask/requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Flask==2.2.5
2+
Werkzeug==2.2.2
3+
MarkupSafe==2.1.1

0 commit comments

Comments
 (0)