commit 646f36716db9cc597d93cd591c252cab6de30301 Author: Galyaviev Ruslan Date: Mon Sep 1 10:54:35 2025 +0300 Initial Flask demo diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/flask-demo.iml b/.idea/flask-demo.iml new file mode 100644 index 0000000..2c80e12 --- /dev/null +++ b/.idea/flask-demo.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..57f7e66 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..11995fe --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.woodpecker.yml b/.woodpecker.yml new file mode 100644 index 0000000..ae780f5 --- /dev/null +++ b/.woodpecker.yml @@ -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 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d3f985d --- /dev/null +++ b/Dockerfile @@ -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"] diff --git a/app.py b/app.py new file mode 100644 index 0000000..9b1933a --- /dev/null +++ b/app.py @@ -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 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..bb1cebd --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,8 @@ +version: "3.8" +services: + web: + image: flask-demo:latest + container_name: flask-demo + ports: + - "8888:8000" + restart: unless-stopped diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..6b05e82 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +Flask==3.0.3 +gunicorn==21.2.0 +pytest==8.3.2 diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..7b3ac1f --- /dev/null +++ b/templates/index.html @@ -0,0 +1,8 @@ + + + {{ title }} + +

{{ title }}

+

Если вы это видите — пайплайн сработал 🎉

+ + diff --git a/tests/test_app.py b/tests/test_app.py new file mode 100644 index 0000000..754e4c5 --- /dev/null +++ b/tests/test_app.py @@ -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