From dc12ac1a456507656d8cc51d61e2eb810ea5f31a Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Wed, 7 Aug 2024 21:09:11 -0700 Subject: [PATCH] add ci/cd --- .drone.yml | 55 ++++++++++++++++++++++++++++++++++++++++ Dockerfile | 12 +++++---- data/.gitkeep | 0 data/database/.gitignore | 2 ++ data/database/.gitkeep | 0 docker-compose.yml | 17 +++++++++++++ kennel/main.py | 2 +- pyproject.toml | 2 +- tests/test_main.py | 12 +++------ 9 files changed, 87 insertions(+), 15 deletions(-) create mode 100644 .drone.yml create mode 100644 data/.gitkeep create mode 100644 data/database/.gitignore create mode 100644 data/database/.gitkeep create mode 100644 docker-compose.yml diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..d05cb97 --- /dev/null +++ b/.drone.yml @@ -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 diff --git a/Dockerfile b/Dockerfile index d9d599d..0101625 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,8 +5,10 @@ COPY ./pyproject.toml ./poetry.lock* /tmp/ RUN poetry export -f requirements.txt --output requirements.txt --without-hashes FROM python:3.12 -WORKDIR /code -COPY --from=requirements-stage /tmp/requirements.txt /code/requirements.txt -RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt -COPY kennel /code/src -CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "80"] +WORKDIR /app +COPY --from=requirements-stage /tmp/requirements.txt /app/requirements.txt +RUN pip install --no-cache-dir --upgrade -r /app/requirements.txt +COPY kennel /app/kennel +COPY static /app/static +COPY templates /app/templates +CMD ["uvicorn", "kennel.main:app", "--host", "0.0.0.0", "--port", "8000"] diff --git a/data/.gitkeep b/data/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/data/database/.gitignore b/data/database/.gitignore new file mode 100644 index 0000000..2621632 --- /dev/null +++ b/data/database/.gitignore @@ -0,0 +1,2 @@ +*.sqlite +*.db diff --git a/data/database/.gitkeep b/data/database/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..f20fa83 --- /dev/null +++ b/docker-compose.yml @@ -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" + diff --git a/kennel/main.py b/kennel/main.py index 3cca2c0..4ec9fca 100644 --- a/kennel/main.py +++ b/kennel/main.py @@ -40,7 +40,7 @@ templates = Jinja2Templates(directory="templates") @app.get("/healthcheck") async def healthcheck(): - return Response() + return Response("hello") @app.get("/") diff --git a/pyproject.toml b/pyproject.toml index 84eb4e3..369a432 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -36,7 +36,7 @@ select = [ ] # 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 = [] diff --git a/tests/test_main.py b/tests/test_main.py index cbab286..3927dd4 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -12,11 +12,7 @@ def test_healthcheck(): assert response.status_code == HTTPStatus.OK assert response.text == "" - -def test_read_main(): - # Example of testing logging using a context manager - with capture_logs() as cap_logs: - response = client.get("/") - assert {"event": "In root path", "log_level": "info"} in cap_logs - assert response.status_code == HTTPStatus.OK - assert response.json() == {"msg": "Hello World"} +def test_main(): + response = client.get("/") + assert response.status_code == HTTPStatus.OK + assert response.text.startswith("")