Skip to content

Commit dfce060

Browse files
fix invalid restart value
0 parents  commit dfce060

7 files changed

Lines changed: 262 additions & 0 deletions

File tree

.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/defang-github-action@v1.3.2

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Python & Flask & HTTP
2+
3+
[![1-click-deploy](https://raw.githubusercontent.com/DefangLabs/defang-assets/main/Logos/Buttons/SVG/deploy-with-defang.svg)](https://portal.defang.dev/redirect?url=https%3A%2F%2Fgithub.com%2Fnew%3Ftemplate_name%3Dsample-python-minimal-template%26template_owner%3DDefangSamples)
4+
5+
This Flask application is designed to inspect and return detailed information about HTTP requests. It supports both GET and POST methods, providing insights into the request path, method, headers, query parameters, and body. Note that alognside your .py file, include a requirements.txt so that the Dockerfile can install the necessary packages with pip.
6+
7+
## Features
8+
9+
1. Support both GET and POST HTTP methods
10+
2. Detailed information about the request, including path, method, headers, query parameters, and body.
11+
12+
## Essential Setup Files
13+
14+
1. A [Dockerfile](https://docs.docker.com/develop/develop-images/dockerfile_best-practices/).
15+
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). (compose.yaml file)
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+
---
29+
30+
Title: Python & Flask & HTTP
31+
32+
Short Description: A Flask application that inspects and returns detailed information about HTTP requests.
33+
34+
Tags: Flask, HTTP, Python
35+
36+
Languages: python

app/.gitignore

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
2+
# --- Python ---
3+
# Byte-compiled / optimized / DLL files
4+
__pycache__/
5+
*.py[cod]
6+
*$py.class
7+
8+
# C extensions
9+
*.so
10+
11+
# Distribution / packaging
12+
.Python
13+
build/
14+
develop-eggs/
15+
dist/
16+
downloads/
17+
eggs/
18+
.eggs/
19+
lib/
20+
lib64/
21+
parts/
22+
sdist/
23+
var/
24+
wheels/
25+
share/python-wheels/
26+
*.egg-info/
27+
.installed.cfg
28+
*.egg
29+
MANIFEST
30+
31+
# PyInstaller
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.nox/
43+
.coverage
44+
.coverage.*
45+
.cache
46+
nosetests.xml
47+
coverage.xml
48+
*.cover
49+
*.py,cover
50+
.hypothesis/
51+
.pytest_cache/
52+
cover/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
.pybuilder/
76+
target/
77+
78+
# Jupyter Notebook
79+
.ipynb_checkpoints
80+
81+
# IPython
82+
profile_default/
83+
ipython_config.py
84+
85+
# pdm
86+
.pdm.toml
87+
.pdm-python
88+
.pdm-build/
89+
90+
# PEP 582
91+
__pypackages__/
92+
93+
# Celery stuff
94+
celerybeat-schedule
95+
celerybeat.pid
96+
97+
# SageMath parsed files
98+
*.sage.py
99+
100+
# Environments
101+
.env
102+
.venv
103+
env/
104+
venv/
105+
ENV/
106+
env.bak/
107+
venv.bak/
108+
109+
# Spyder project settings
110+
.spyderproject
111+
.spyproject
112+
113+
# Rope project settings
114+
.ropeproject
115+
116+
# mkdocs documentation
117+
/site
118+
119+
# mypy
120+
.mypy_cache/
121+
.dmypy.json
122+
dmypy.json
123+
124+
# Pyre type checker
125+
.pyre/
126+
127+
# pytype static type analyzer
128+
.pytype/
129+
130+
# Cython debug symbols
131+
cython_debug/
132+
133+
# PyCharm
134+
.idea/

app/Dockerfile

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

app/main.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from flask import Flask
2+
from flask import request
3+
4+
5+
app = Flask(__name__)
6+
7+
8+
@app.route("/", methods=['GET', 'POST'])
9+
def index():
10+
return {
11+
"path" : request.path,
12+
"method" : request.method,
13+
"headers" : dict(request.headers),
14+
"args" : dict(request.args),
15+
"body" : request.data.decode('utf-8')
16+
}
17+
18+
19+
if __name__ == '__main__':
20+
app.run(debug=True, host='0.0.0.0')

app/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
uwsgi
2+
flask

compose.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: python-minimal
2+
services:
3+
app:
4+
restart: unless-stopped
5+
build:
6+
context: ./app
7+
dockerfile: Dockerfile
8+
ports:
9+
- mode: ingress
10+
target: 5000
11+
deploy:
12+
resources:
13+
reservations:
14+
memory: 256M
15+
healthcheck:
16+
test:
17+
- CMD
18+
- curl
19+
- -f
20+
- http://localhost:5000/

0 commit comments

Comments
 (0)