Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Skyler84 committed Feb 26, 2024
0 parents commit e04e8aa
Show file tree
Hide file tree
Showing 16 changed files with 574 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
docker/
.github/
22 changes: 22 additions & 0 deletions .github/workflows/checks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Python checks

on: [push]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.11
uses: actions/setup-python@v2
with:
python-version: 3.11
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install
- name: ruff check
run: poetry run ruff check
- name: mypy check
run: poetry run mypy challenge
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.vscode/
.ruff_cache/
.mypy_cache/
**/__pycache__/
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# SUCSS Challenge Template

This template repository contains all the required files to start a simple challenge.

## Setup

Ensure you have python poetry installed - this is used to install a virtualenv and manage dependencies

```
pip install --upgrade pip
pip3 install -u poetry
poetry install --no-root
```

## Running in development

Flask comes with a development server built in. To use it, run
```
poetry run flask -A challenge run
```

## Running in production

```
poetry run gunicorn 'challenge:app'
```

## Running with docker

```
docker-compose -p "<project name>" -f "docker/compose.yaml" up --build
```
5 changes: 5 additions & 0 deletions challenge/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from flask import Flask

app = Flask(__name__)
# app.config.from_object('config')

44 changes: 44 additions & 0 deletions challenge/static/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
body {
margin: 0;
font-family: sans-serif;
}

h1 {
width: 100%;
background-color: #000000;
color: #ffffff;
margin: 0;
padding: 5px 20px;
}

.container {
width: 800px;
margin: 20px auto;
background-color: rgba(0,0,0,0.1);
padding: 15px;
}

h2 {
text-align: center;
}

form {
width: 100%;
}

input {
width: 100%;
}

button {
margin-top: 10px;
display: block;
margin-left: auto;
margin-right: auto;
}

.invalid-feedback {
color: #ff0000;
text-align: center;
margin-top: 10px;
}
6 changes: 6 additions & 0 deletions challenge/templates/challenge2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% extends 'layout.html' %}

{% block content %}
<h1>Challenge 2</h1>
<p>This is an example using a flask View to render a template</p>
{% endblock %}
13 changes: 13 additions & 0 deletions challenge/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% extends 'layout.html' %}

{% block content %}
<h1>Home</h1>
<p>Welcome to the home page</p>
<div id="challenges">
<h2>Challenges</h2>
<ul>
<li><a href="/1/">Example Challenge 1</a></li>
<li><a href="/2/">Example Challenge 2</a></li>
</ul>
</div>
{% endblock %}
12 changes: 12 additions & 0 deletions challenge/templates/layout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>{%if title%}{{title}}{%else%}SUCSS Challenge{%endif%}</title>
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}" />
</head>
<body>
<div id="content">
{% block content %}{% endblock content %}
</div>
</body>
</html>
13 changes: 13 additions & 0 deletions challenge/views/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from flask import render_template

from challenge import app

from . import (
challenge_1, # noqa: F401
challenge_2, # noqa: F401
)


@app.route("/", methods=["GET"])
def index() -> str:
return render_template("index.html")
14 changes: 14 additions & 0 deletions challenge/views/challenge_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from flask import views

from challenge import app


class Challenge1View(views.MethodView):
def get(self) -> str:
return "Challenge 1 GET"

def post(self) -> str:
return "Challenge 1 POST"


app.add_url_rule("/1/", view_func=Challenge1View.as_view("challenge1"))
13 changes: 13 additions & 0 deletions challenge/views/challenge_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from flask import render_template, views

from challenge import app


class Challenge2View(views.View):
template_name = "challenge2.html"

def dispatch_request(self) -> str:
return render_template(self.template_name)


app.add_url_rule("/2/", view_func=Challenge2View.as_view("challenge2"))
14 changes: 14 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM python:3.10

RUN pip install poetry

COPY pyproject.toml /app/pyproject.toml
COPY poetry.lock /app/poetry.lock

WORKDIR /app

RUN poetry install --no-dev

COPY . /app

CMD ["poetry", "run", "gunicorn", "-b", "0.0.0.0", "challenge:app"]
8 changes: 8 additions & 0 deletions docker/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: '3'
services:
app:
build:
context: ../
dockerfile: docker/Dockerfile
ports:
- "8000:8000"
Loading

0 comments on commit e04e8aa

Please sign in to comment.