diff --git a/.woodpecker/publish.yml b/.woodpecker/publish.yml new file mode 100644 index 0000000..5af673c --- /dev/null +++ b/.woodpecker/publish.yml @@ -0,0 +1,18 @@ +--- + +when: + branch: main + event: push + +steps: + publish: + image: woodpeckerci/plugin-docker-buildx + settings: + dockerfile: Dockerfile + auto_tag: true + tag: latest + repo: akulovsergei/test-app + username: akulovsergei + password: + from_secret: docker_token + \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6dcec48 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +FROM python:3.9-slim + +WORKDIR /app +COPY . . + +RUN pip install --no-cache-dir -r requirements.txt + +CMD ["python", "run.py"] diff --git a/app/__init__.py b/app/__init__.py new file mode 100644 index 0000000..3f43a08 --- /dev/null +++ b/app/__init__.py @@ -0,0 +1,18 @@ +from flask import Flask +from flask_sqlalchemy import SQLAlchemy + +db = SQLAlchemy() + +def create_app(): + app = Flask(__name__) + app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///todo.db" + app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False + + db.init_app(app) + + # Импорт и регистрация маршрутов + with app.app_context(): + from . import routes + db.create_all() + + return app diff --git a/app/__pycache__/__init__.cpython-39.pyc b/app/__pycache__/__init__.cpython-39.pyc new file mode 100644 index 0000000..36f72a5 Binary files /dev/null and b/app/__pycache__/__init__.cpython-39.pyc differ diff --git a/app/__pycache__/models.cpython-39.pyc b/app/__pycache__/models.cpython-39.pyc new file mode 100644 index 0000000..5828484 Binary files /dev/null and b/app/__pycache__/models.cpython-39.pyc differ diff --git a/app/__pycache__/routes.cpython-39.pyc b/app/__pycache__/routes.cpython-39.pyc new file mode 100644 index 0000000..23f3dbc Binary files /dev/null and b/app/__pycache__/routes.cpython-39.pyc differ diff --git a/app/models.py b/app/models.py new file mode 100644 index 0000000..37f5656 --- /dev/null +++ b/app/models.py @@ -0,0 +1,6 @@ +from . import db + +class Task(db.Model): + id = db.Column(db.Integer, primary_key=True) + title = db.Column(db.String(120), nullable=False) + completed = db.Column(db.Boolean, default=False) diff --git a/app/routes.py b/app/routes.py new file mode 100644 index 0000000..3aa8b94 --- /dev/null +++ b/app/routes.py @@ -0,0 +1,34 @@ +from flask import Flask, render_template, request, redirect, url_for +from . import db +from .models import Task +from flask import current_app as app + + +@app.route("/") +def index(): + tasks = Task.query.all() + return render_template("index.html", tasks=tasks) + +@app.route("/add", methods=["POST"]) +def add_task(): + title = request.form.get("title") + if title: + new_task = Task(title=title) + db.session.add(new_task) + db.session.commit() + return redirect(url_for("index")) + +@app.route("/delete/") +def delete_task(task_id): + task = Task.query.get_or_404(task_id) + db.session.delete(task) + db.session.commit() + return redirect(url_for("index")) + +@app.route("/complete/") +def complete_task(task_id): + task = Task.query.get_or_404(task_id) + task.completed = not task.completed + db.session.commit() + return redirect(url_for("index")) + diff --git a/app/static/style.css b/app/static/style.css new file mode 100644 index 0000000..9edeb21 --- /dev/null +++ b/app/static/style.css @@ -0,0 +1,21 @@ +body { + font-family: Arial, sans-serif; + margin: 20px; +} + +h1 { + color: #333; +} + +ul { + list-style-type: none; + padding: 0; +} + +li { + margin: 5px 0; +} + +form { + margin-bottom: 20px; +} diff --git a/app/templates/base.html b/app/templates/base.html new file mode 100644 index 0000000..7b79284 --- /dev/null +++ b/app/templates/base.html @@ -0,0 +1,14 @@ + + + + + + To-Do List + + + +
+ {% block content %}{% endblock %} +
+ + diff --git a/app/templates/index.html b/app/templates/index.html new file mode 100644 index 0000000..72db36b --- /dev/null +++ b/app/templates/index.html @@ -0,0 +1,21 @@ +{% extends "base.html" %} + +{% block content %} +

To-Do List for DEVOPS

+
+ + +
+ +{% endblock %} diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..9bb3aad --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,10 @@ +--- +services: + web: + build: . + ports: + - "5000:5000" + volumes: + - .:/app + environment: + - FLASK_ENV=development diff --git a/instance/todo.db b/instance/todo.db new file mode 100644 index 0000000..94ac226 Binary files /dev/null and b/instance/todo.db differ diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..de8a130 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +flask +flask_sqlalchemy diff --git a/run.py b/run.py new file mode 100644 index 0000000..f61366d --- /dev/null +++ b/run.py @@ -0,0 +1,6 @@ +from app import create_app + +app = create_app() + +if __name__ == "__main__": + app.run(host="0.0.0.0", port=5000, debug=True)