update alembic to use environment to get postgresql username, password and host
parent
65d1a6233e
commit
166d71272d
|
@ -1,11 +1,10 @@
|
||||||
FROM python:3
|
FROM python:3
|
||||||
WORKDIR /app
|
WORKDIR /backend
|
||||||
ENV POSTGRES_HOST=together-postgres
|
ENV POSTGRES_HOST=together-postgres
|
||||||
ENV POSTGRES_USER=together
|
ENV POSTGRES_USER=together
|
||||||
ENV POSTGRES_PASSWORD=togetherno.1
|
ENV POSTGRES_PASSWORD=togetherno.1
|
||||||
COPY ./requirements.txt .
|
COPY ./requirements.txt .
|
||||||
RUN pip install --no-cache-dir --upgrade -r /app/requirements.txt -i https://mirrors.aliyun.com/pypi/simple
|
RUN pip install --no-cache-dir --upgrade -r /app/requirements.txt -i https://mirrors.aliyun.com/pypi/simple
|
||||||
RUN alembic
|
|
||||||
COPY . .
|
COPY . .
|
||||||
EXPOSE 8000
|
EXPOSE 8000
|
||||||
CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "8000", "--env-file", "./.dev.env"]
|
CMD ["sh", "-c", "alembic upgrade head && uvicorn src.main:app --host 0.0.0.0 --port 8000 --env-file ./.dev.env"]
|
|
@ -1,8 +1,10 @@
|
||||||
FROM python:3
|
FROM python:3
|
||||||
WORKDIR /app
|
WORKDIR /backend
|
||||||
|
ENV POSTGRES_HOST=together-postgres
|
||||||
|
ENV POSTGRES_USER=together
|
||||||
|
ENV POSTGRES_PASSWORD=togetherno.1
|
||||||
COPY ./requirements.txt .
|
COPY ./requirements.txt .
|
||||||
RUN pip install --no-cache-dir --upgrade -r /app/requirements.txt -i https://mirrors.aliyun.com/pypi/simple
|
RUN pip install --no-cache-dir --upgrade -r /app/requirements.txt -i https://mirrors.aliyun.com/pypi/simple
|
||||||
RUN alembic
|
|
||||||
COPY . .
|
COPY . .
|
||||||
EXPOSE 8000
|
EXPOSE 8000
|
||||||
CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "8000", "--env-file", "./.prod.env"]
|
CMD ["sh", "-c", "alembic upgrade head && uvicorn src.main:app --host 0.0.0.0 --port 8000 --env-file ./.prod.env"]
|
16
README.md
16
README.md
|
@ -68,5 +68,21 @@ alembe upgrade +1
|
||||||
alembic downgrade -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
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,13 @@ target_metadata = Base.metadata
|
||||||
# my_important_option = config.get_main_option("my_important_option")
|
# my_important_option = config.get_main_option("my_important_option")
|
||||||
# ... etc.
|
# ... 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:
|
def run_migrations_offline() -> None:
|
||||||
"""Run migrations in 'offline' mode.
|
"""Run migrations in 'offline' mode.
|
||||||
|
@ -41,10 +48,9 @@ def run_migrations_offline() -> None:
|
||||||
script output.
|
script output.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
host = os.getenv('POSTGRES_HOST', 'localhost')
|
|
||||||
user = os.getenv('POSTGRES_USER')
|
|
||||||
passwd = os.getenv('POSTGRES_PASSWORD')
|
# url = config.get_main_option("sqlalchemy.url")
|
||||||
url = f'postgresql+asyncpg://{user}:{passwd}@{host}/{user}'
|
|
||||||
|
|
||||||
context.configure(
|
context.configure(
|
||||||
url=url,
|
url=url,
|
||||||
|
|
|
@ -6,7 +6,7 @@ from src.database.redis_api import redis_server
|
||||||
|
|
||||||
host = "smtp.163.com"
|
host = "smtp.163.com"
|
||||||
username = "together_app@163.com"
|
username = "together_app@163.com"
|
||||||
password = "ZHHLUQSTDTQSBEQZ"
|
password = "AIAMTGHKFWKHXSUY"
|
||||||
|
|
||||||
smtp = SMTP(host=host)
|
smtp = SMTP(host=host)
|
||||||
smtp.ehlo()
|
smtp.ehlo()
|
||||||
|
|
Loading…
Reference in New Issue