Compare commits
2 Commits
dev-fronte
...
main
Author | SHA1 | Date |
---|---|---|
Elizabeth Hunt | 6f223d2462 | |
Elizabeth Hunt | 9cdb7a145e |
|
@ -0,0 +1,55 @@
|
||||||
|
---
|
||||||
|
kind: pipeline
|
||||||
|
type: docker
|
||||||
|
name: build
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: run tests
|
||||||
|
image: python:3.12
|
||||||
|
commands:
|
||||||
|
- pip install poetry
|
||||||
|
- poetry install --with main,dev
|
||||||
|
- poetry run pytest
|
||||||
|
|
||||||
|
trigger:
|
||||||
|
event:
|
||||||
|
- pull_request
|
||||||
|
|
||||||
|
---
|
||||||
|
kind: pipeline
|
||||||
|
type: docker
|
||||||
|
name: deploy
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: run tests
|
||||||
|
image: python:3.12
|
||||||
|
commands:
|
||||||
|
- pip install poetry
|
||||||
|
- poetry install --with main,dev
|
||||||
|
- poetry run pytest
|
||||||
|
- name: docker
|
||||||
|
image: plugins/docker
|
||||||
|
settings:
|
||||||
|
username:
|
||||||
|
from_secret: gitea_packpub_username
|
||||||
|
password:
|
||||||
|
from_secret: gitea_packpub_password
|
||||||
|
registry: git.hatecomputers.club
|
||||||
|
repo: git.hatecomputers.club/hatecomputers/kennel
|
||||||
|
- name: ssh
|
||||||
|
image: appleboy/drone-ssh
|
||||||
|
settings:
|
||||||
|
host: hatecomputers.club
|
||||||
|
username: root
|
||||||
|
key:
|
||||||
|
from_secret: cd_ssh_key
|
||||||
|
port: 22
|
||||||
|
command_timeout: 2m
|
||||||
|
script:
|
||||||
|
- systemctl restart docker-compose@kennel
|
||||||
|
|
||||||
|
trigger:
|
||||||
|
branch:
|
||||||
|
- main
|
||||||
|
event:
|
||||||
|
- push
|
12
Dockerfile
12
Dockerfile
|
@ -5,8 +5,10 @@ COPY ./pyproject.toml ./poetry.lock* /tmp/
|
||||||
RUN poetry export -f requirements.txt --output requirements.txt --without-hashes
|
RUN poetry export -f requirements.txt --output requirements.txt --without-hashes
|
||||||
|
|
||||||
FROM python:3.12
|
FROM python:3.12
|
||||||
WORKDIR /code
|
WORKDIR /app
|
||||||
COPY --from=requirements-stage /tmp/requirements.txt /code/requirements.txt
|
COPY --from=requirements-stage /tmp/requirements.txt /app/requirements.txt
|
||||||
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
RUN pip install --no-cache-dir --upgrade -r /app/requirements.txt
|
||||||
COPY kennel /code/src
|
COPY kennel /app/kennel
|
||||||
CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "80"]
|
COPY static /app/static
|
||||||
|
COPY templates /app/templates
|
||||||
|
CMD ["uvicorn", "kennel.main:app", "--host", "0.0.0.0", "--port", "8000", "--proxy-headers", "--forwarded-allow-ips", "*"]
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
*.sqlite
|
||||||
|
*.db
|
|
@ -0,0 +1,17 @@
|
||||||
|
version: "3"
|
||||||
|
|
||||||
|
services:
|
||||||
|
kennel:
|
||||||
|
restart: always
|
||||||
|
build: .
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "wget", "--spider", "http://localhost:8000/healthcheck"]
|
||||||
|
interval: 5s
|
||||||
|
timeout: 10s
|
||||||
|
retries: 5
|
||||||
|
env_file: .env
|
||||||
|
volumes:
|
||||||
|
- ./data:/app/data
|
||||||
|
ports:
|
||||||
|
- "127.0.0.1:60613:8000"
|
||||||
|
|
|
@ -5,7 +5,11 @@ from fastapi import FastAPI, Request, Response
|
||||||
from fastapi.staticfiles import StaticFiles
|
from fastapi.staticfiles import StaticFiles
|
||||||
from fastapi.templating import Jinja2Templates
|
from fastapi.templating import Jinja2Templates
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI(
|
||||||
|
servers = [
|
||||||
|
{"url": "https://kennel.hatecomputers.club", "description": "prod"}
|
||||||
|
]
|
||||||
|
)
|
||||||
logger = structlog.get_logger()
|
logger = structlog.get_logger()
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,7 +44,7 @@ templates = Jinja2Templates(directory="templates")
|
||||||
|
|
||||||
@app.get("/healthcheck")
|
@app.get("/healthcheck")
|
||||||
async def healthcheck():
|
async def healthcheck():
|
||||||
return Response()
|
return Response("hello")
|
||||||
|
|
||||||
|
|
||||||
@app.get("/")
|
@app.get("/")
|
||||||
|
|
|
@ -36,7 +36,7 @@ select = [
|
||||||
]
|
]
|
||||||
|
|
||||||
# Note: Ruff supports a top-level `src` option in lieu of isort's `src_paths` setting.
|
# Note: Ruff supports a top-level `src` option in lieu of isort's `src_paths` setting.
|
||||||
src = ["fastapi_poetry_starter", "tests"]
|
src = ["kennel", "tests"]
|
||||||
|
|
||||||
ignore = []
|
ignore = []
|
||||||
|
|
||||||
|
|
|
@ -10,13 +10,9 @@ client = TestClient(app)
|
||||||
def test_healthcheck():
|
def test_healthcheck():
|
||||||
response = client.get("/healthcheck")
|
response = client.get("/healthcheck")
|
||||||
assert response.status_code == HTTPStatus.OK
|
assert response.status_code == HTTPStatus.OK
|
||||||
assert response.text == ""
|
assert response.text == "hello"
|
||||||
|
|
||||||
|
def test_main():
|
||||||
def test_read_main():
|
|
||||||
# Example of testing logging using a context manager
|
|
||||||
with capture_logs() as cap_logs:
|
|
||||||
response = client.get("/")
|
response = client.get("/")
|
||||||
assert {"event": "In root path", "log_level": "info"} in cap_logs
|
|
||||||
assert response.status_code == HTTPStatus.OK
|
assert response.status_code == HTTPStatus.OK
|
||||||
assert response.json() == {"msg": "Hello World"}
|
assert response.text.startswith("<!DOCTYPE html>")
|
||||||
|
|
Loading…
Reference in New Issue