Initial Flask demo
This commit is contained in:
3
.idea/.gitignore
generated
vendored
Normal file
3
.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
10
.idea/flask-demo.iml
generated
Normal file
10
.idea/flask-demo.iml
generated
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="PYTHON_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
6
.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
6
.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<settings>
|
||||||
|
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||||
|
<version value="1.0" />
|
||||||
|
</settings>
|
||||||
|
</component>
|
||||||
7
.idea/misc.xml
generated
Normal file
7
.idea/misc.xml
generated
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Black">
|
||||||
|
<option name="sdkName" value="Python 3.10 (flask-demo)" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (flask-demo)" project-jdk-type="Python SDK" />
|
||||||
|
</project>
|
||||||
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/flask-demo.iml" filepath="$PROJECT_DIR$/.idea/flask-demo.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
33
.woodpecker.yml
Normal file
33
.woodpecker.yml
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
variables:
|
||||||
|
IMAGE: flask-demo:latest
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
- name: dockersock
|
||||||
|
host:
|
||||||
|
path: /var/run/docker.sock
|
||||||
|
|
||||||
|
pipeline:
|
||||||
|
test:
|
||||||
|
image: python:3.11
|
||||||
|
commands:
|
||||||
|
- pip install -r requirements.txt
|
||||||
|
- pytest -q
|
||||||
|
|
||||||
|
build:
|
||||||
|
image: docker:27-cli
|
||||||
|
volumes:
|
||||||
|
- name: dockersock
|
||||||
|
path: /var/run/docker.sock
|
||||||
|
commands:
|
||||||
|
- docker build -t ${IMAGE} .
|
||||||
|
|
||||||
|
deploy:
|
||||||
|
image: docker:27-cli
|
||||||
|
volumes:
|
||||||
|
- name: dockersock
|
||||||
|
path: /var/run/docker.sock
|
||||||
|
commands:
|
||||||
|
- docker compose up -d
|
||||||
|
when:
|
||||||
|
event: push
|
||||||
|
branch: main
|
||||||
12
Dockerfile
Normal file
12
Dockerfile
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
FROM python:3.11-slim
|
||||||
|
|
||||||
|
ENV PYTHONDONTWRITEBYTECODE=1 \
|
||||||
|
PYTHONUNBUFFERED=1
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
COPY requirements.txt .
|
||||||
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
EXPOSE 8000
|
||||||
|
CMD ["gunicorn", "-w", "2", "-b", "0.0.0.0:8000", "app:app"]
|
||||||
10
app.py
Normal file
10
app.py
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
from flask import Flask, render_template
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
@app.get("/")
|
||||||
|
def home():
|
||||||
|
return render_template("index.html", title="Flask CI/CD demo")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
app.run(host="0.0.0.0", port=8000) # внутри контейнера слушаем 8000
|
||||||
8
docker-compose.yml
Normal file
8
docker-compose.yml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
version: "3.8"
|
||||||
|
services:
|
||||||
|
web:
|
||||||
|
image: flask-demo:latest
|
||||||
|
container_name: flask-demo
|
||||||
|
ports:
|
||||||
|
- "8888:8000"
|
||||||
|
restart: unless-stopped
|
||||||
3
requirements.txt
Normal file
3
requirements.txt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
Flask==3.0.3
|
||||||
|
gunicorn==21.2.0
|
||||||
|
pytest==8.3.2
|
||||||
8
templates/index.html
Normal file
8
templates/index.html
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="ru">
|
||||||
|
<head><meta charset="utf-8"><title>{{ title }}</title></head>
|
||||||
|
<body>
|
||||||
|
<h1>{{ title }}</h1>
|
||||||
|
<p>Если вы это видите — пайплайн сработал 🎉</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
11
tests/test_app.py
Normal file
11
tests/test_app.py
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
from app import app
|
||||||
|
|
||||||
|
def test_home_status():
|
||||||
|
client = app.test_client()
|
||||||
|
r = client.get("/")
|
||||||
|
assert r.status_code == 200
|
||||||
|
|
||||||
|
def test_home_text():
|
||||||
|
client = app.test_client()
|
||||||
|
r = client.get("/")
|
||||||
|
assert b"Flask CI/CD demo" in r.data
|
||||||
Reference in New Issue
Block a user