diff --git a/.github/workflows/build_and_publish.yml b/.github/workflows/build_and_publish.yml index 2d860fab..ccfcc3b3 100644 --- a/.github/workflows/build_and_publish.yml +++ b/.github/workflows/build_and_publish.yml @@ -43,6 +43,7 @@ jobs: - name: Build and push Docker image uses: docker/build-push-action@v4 with: + file: build/Dockerfile context: . push: true tags: ${{ steps.meta.outputs.tags }} @@ -66,17 +67,6 @@ jobs: - name: Pull new version run: docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:test - - name: Migrate DB - run: | - docker run \ - --rm \ - --network=web \ - --env DB_DSN=${{ secrets.DB_DSN }} \ - --name ${{ env.CONTAINER_NAME }}_migration \ - --workdir="/" \ - ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:test \ - alembic upgrade head - - name: Run new version id: run_test run: | @@ -158,19 +148,8 @@ jobs: - name: Pull new version run: docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest - - name: Migrate DB - run: | - docker run \ - --rm \ - --network=web \ - --env DB_DSN=${{ secrets.DB_DSN }} \ - --name ${{ env.CONTAINER_NAME }}_migration \ - --workdir="/" \ - ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest \ - alembic upgrade head - - name: Run new version - id: run_test + id: run_prod run: | docker stop ${{ env.CONTAINER_NAME }} || true && docker rm ${{ env.CONTAINER_NAME }} || true docker run \ diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 0631c741..00000000 --- a/Dockerfile +++ /dev/null @@ -1,15 +0,0 @@ -FROM tiangolo/uvicorn-gunicorn-fastapi:python3.11 -ARG APP_VERSION=dev -ENV APP_VERSION=${APP_VERSION} -ENV APP_NAME=auth_backend -ENV APP_MODULE=${APP_NAME}.routes.base:app - -COPY ./requirements.txt /app/ -RUN pip install -U -r /app/requirements.txt - -COPY ./alembic.ini /alembic.ini -COPY ./logging_prod.conf /app/ -COPY ./logging_test.conf /app/ -COPY ./migrations /migrations/ - -COPY ./${APP_NAME} /app/${APP_NAME} diff --git a/Makefile b/Makefile index e754ba75..8c5d661f 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ SHELL := /bin/bash run: - source ./venv/bin/activate && uvicorn --reload --log-config logging_dev.conf auth_backend.routes.base:app + source ./venv/bin/activate && uvicorn --reload --log-config deploy/logging_dev.conf auth_backend.routes.base:app configure: venv source ./venv/bin/activate && pip install -r requirements.dev.txt -r requirements.txt @@ -23,6 +23,9 @@ format: db: docker run -d -p 5432:5432 -e POSTGRES_HOST_AUTH_METHOD=trust --name db-auth_api postgres:15 +db-cleanup: + alembic downgrade head-"$(alembic heads | wc -l | sed 's/ //g')" + alembic upgrade head migrate: source ./venv/bin/activate && alembic upgrade head diff --git a/auth_backend/__init__.py b/auth_backend/__init__.py index fa9c0989..06cf35fc 100644 --- a/auth_backend/__init__.py +++ b/auth_backend/__init__.py @@ -1,4 +1,4 @@ import os -__version__ = os.getenv('APP_VERSION', 'dev') +__version__ = os.getenv('APP_VERSION', 'v0.0.0-dev') diff --git a/cleanupdb.sh b/cleanupdb.sh deleted file mode 100644 index e32d109c..00000000 --- a/cleanupdb.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -alembic downgrade head-"$(alembic heads | wc -l | sed 's/ //g')" -alembic upgrade head \ No newline at end of file diff --git a/deploy/Dockerfile b/deploy/Dockerfile new file mode 100644 index 00000000..c620e421 --- /dev/null +++ b/deploy/Dockerfile @@ -0,0 +1,15 @@ +FROM tiangolo/uvicorn-gunicorn-fastapi:python3.11 +ARG APP_VERSION=v0.0.0-dev +ENV APP_VERSION=${APP_VERSION} +ENV APP_NAME=auth_backend +ENV APP_MODULE=${APP_NAME}.routes.base:app + +# Копируем файлы зависимостей и устанавливаем их +COPY ./requirements.txt /app/ +RUN pip install -U -r /app/requirements.txt + +# Копируем сопуствующие файлы +COPY ./deploy/prestart.sh ./deploy/logging_dev.conf ./deploy/logging_test.conf ./deploy/logging_prod.conf ./migrations ./alembic.ini /app/ + +# Копируем сам проект +COPY ./${APP_NAME} /app/${APP_NAME} diff --git a/logging_dev.conf b/deploy/logging_dev.conf similarity index 100% rename from logging_dev.conf rename to deploy/logging_dev.conf diff --git a/logging_prod.conf b/deploy/logging_prod.conf similarity index 100% rename from logging_prod.conf rename to deploy/logging_prod.conf diff --git a/logging_test.conf b/deploy/logging_test.conf similarity index 100% rename from logging_test.conf rename to deploy/logging_test.conf diff --git a/deploy/prestart.sh b/deploy/prestart.sh new file mode 100644 index 00000000..16bf80a5 --- /dev/null +++ b/deploy/prestart.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +alembic upgrade head diff --git a/pyproject.toml b/pyproject.toml index 2368eb97..536e6198 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,39 @@ +[project] +name = "auth_backend" +description = "REST API backend for auth" +readme = "README.md" +requires-python = ">=3.11" +keywords = [] +license = {text = "Proprientary"} +classifiers = [ + "Development Status :: 4 - Beta", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.11", +] +dynamic = ["dependencies", "optional-dependencies", "version"] + +[project.urls] +Homepage = "https://git.dyakov.space/stories" +Documentation = "https://git.dyakov.space/stories/.gitea/wiki" +Repository = "https://git.dyakov.space/stories/backend" +Issues = "https://git.dyakov.space/stories/backend/issues" +Changelog = "https://git.dyakov.space/stories/backend/releases" + +[build-system] +requires = ["setuptools", "setuptools-scm"] +build-backend = "setuptools.build_meta" + +[tool.setuptools.dynamic] +dependencies = {file = ["requirements.txt"]} +optional-dependencies = {dev = { file = ["requirements.dev.txt"] }} +version = {attr = "auth_backend.__version__"} + +[tool.setuptools] +packages = ["auth_backend"] + [tool.black] line-length = 120 -target-version = ['py310'] +target-version = ['py311'] skip-string-normalization = true [tool.isort]