Skip to content

Commit 55b49de

Browse files
authored
Merge pull request #327 from DefangLabs/linda-nextjs-cv
Add Nextjs CV (from market.dev) sample
0 parents  commit 55b49de

File tree

6 files changed

+179
-0
lines changed

6 files changed

+179
-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: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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 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+
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+
9+
## Prerequisites
10+
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/)
14+
15+
## Development
16+
17+
To run the application locally, you can use the following command:
18+
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+
```
44+
45+
### BYOC (AWS)
46+
47+
If you want to deploy to your own cloud account, you can use Defang BYOC:
48+
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+
```
54+
55+
---
56+
57+
Title: Flask
58+
59+
Short Description: A basic Flask to-do app.
60+
61+
Tags: Flask, Python
62+
63+
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)