diff --git a/.dev.Dockerfile b/.dev.Dockerfile index 91bff49..e72ec17 100644 --- a/.dev.Dockerfile +++ b/.dev.Dockerfile @@ -1,11 +1,10 @@ FROM python:3 -WORKDIR /app +WORKDIR /backend ENV POSTGRES_HOST=together-postgres ENV POSTGRES_USER=together ENV POSTGRES_PASSWORD=togetherno.1 COPY ./requirements.txt . RUN pip install --no-cache-dir --upgrade -r /app/requirements.txt -i https://mirrors.aliyun.com/pypi/simple -RUN alembic COPY . . EXPOSE 8000 -CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "8000", "--env-file", "./.dev.env"] \ No newline at end of file +CMD ["sh", "-c", "alembic upgrade head && uvicorn src.main:app --host 0.0.0.0 --port 8000 --env-file ./.dev.env"] \ No newline at end of file diff --git a/.prod.Dockerfile b/.prod.Dockerfile index 1f274b7..331e419 100644 --- a/.prod.Dockerfile +++ b/.prod.Dockerfile @@ -1,8 +1,10 @@ FROM python:3 -WORKDIR /app +WORKDIR /backend +ENV POSTGRES_HOST=together-postgres +ENV POSTGRES_USER=together +ENV POSTGRES_PASSWORD=togetherno.1 COPY ./requirements.txt . RUN pip install --no-cache-dir --upgrade -r /app/requirements.txt -i https://mirrors.aliyun.com/pypi/simple -RUN alembic COPY . . EXPOSE 8000 -CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "8000", "--env-file", "./.prod.env"] \ No newline at end of file +CMD ["sh", "-c", "alembic upgrade head && uvicorn src.main:app --host 0.0.0.0 --port 8000 --env-file ./.prod.env"] \ No newline at end of file diff --git a/README.md b/README.md index b810f41..f2f4309 100644 --- a/README.md +++ b/README.md @@ -68,5 +68,21 @@ alembe upgrade +1 alembic downgrade -1 ``` +# Run Container + +Create a volume for persisting data: + +```shell +docker volumn create together-backend +``` + +Run a container and mount the volume: + +```shell +docker run --name together-backend \ +-v together-backend:/backend/static \ +-itd 120.77.202.88/together-backend-dev:v1.0 +``` + diff --git a/migrations/env.py b/migrations/env.py index f8750b1..a9d296c 100755 --- a/migrations/env.py +++ b/migrations/env.py @@ -28,6 +28,13 @@ target_metadata = Base.metadata # my_important_option = config.get_main_option("my_important_option") # ... etc. +host = os.getenv("POSTGRES_HOST", "localhost") +user = os.getenv("POSTGRES_USER") +password = os.getenv("POSTGRES_PASSWORD") + +url = f"postgresql+asyncpg://{user}:{password}@{host}/{user}" +config.set_main_option("sqlalchemy.url", url) + def run_migrations_offline() -> None: """Run migrations in 'offline' mode. @@ -41,10 +48,9 @@ def run_migrations_offline() -> None: script output. """ - host = os.getenv('POSTGRES_HOST', 'localhost') - user = os.getenv('POSTGRES_USER') - passwd = os.getenv('POSTGRES_PASSWORD') - url = f'postgresql+asyncpg://{user}:{passwd}@{host}/{user}' + + + # url = config.get_main_option("sqlalchemy.url") context.configure( url=url, diff --git a/src/utils/email_code.py b/src/utils/email_code.py index 5b53384..59373ed 100755 --- a/src/utils/email_code.py +++ b/src/utils/email_code.py @@ -6,7 +6,7 @@ from src.database.redis_api import redis_server host = "smtp.163.com" username = "together_app@163.com" -password = "ZHHLUQSTDTQSBEQZ" +password = "AIAMTGHKFWKHXSUY" smtp = SMTP(host=host) smtp.ehlo()