From 48e1b9d681db2d9e2e6f33bbf2556bcb88751acc Mon Sep 17 00:00:00 2001 From: Alexander-Porter Date: Sat, 6 Jul 2024 15:39:01 +0800 Subject: [PATCH] chore: Set default DB host to "mysql", and add default DB user as "root" --- .github/workflow/pushToGhcr.yaml | 13 +++++++++++++ Dockerfile | 3 +-- app.py | 6 ++++-- readme.md | 10 ++++++++++ 4 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 .github/workflow/pushToGhcr.yaml diff --git a/.github/workflow/pushToGhcr.yaml b/.github/workflow/pushToGhcr.yaml new file mode 100644 index 0000000..6769ebd --- /dev/null +++ b/.github/workflow/pushToGhcr.yaml @@ -0,0 +1,13 @@ +name: Build and Push Container to GitHub Container Registry + +on: + pull: + branches: + - main + +jobs: + build_and_push: + runs-on: ubuntu-latest + steps: + - name: Build and Push Container to ghcr.io + uses: GlueOps/github-actions-build-push-containers@v0.3.7 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 3ad10f6..01045a0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,13 +2,12 @@ FROM python:3.10-slim ENV PYTHONDONTWRITEBYTECODE 1 ENV PYTHONUNBUFFERED 1 -ENV DB_BACKEND mysql # 设置工作目录 WORKDIR /app # 将当前目录内容复制到位于/app中的容器中docker build -t myapp . COPY . /app # 安装requirements.txt中的所有依赖,gunicorn -RUN pip install --no-cache-dir -r requirements.txt gunicorn -i https://pypi.tuna.tsinghua.edu.cn/simple +RUN pip install --no-cache-dir -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple # 使端口10080可供此容器外的环境使用 EXPOSE 8080 # 使用gunicorn运行app.py,假设您的FastAPI应用实例名为app diff --git a/app.py b/app.py index 2d3df2c..ba05b73 100644 --- a/app.py +++ b/app.py @@ -15,9 +15,11 @@ db_name = os.getenv("DB_NAME") db_host = os.getenv("DB_HOST") if db_host==None: - db_host="localhost" + db_host="mysql" +if db_user==None: + db_user="root" -app.config['SQLALCHEMY_DATABASE_URI'] = f"mysql+mysqlconnector://root:{db_password}@mysql/{db_name}" +app.config['SQLALCHEMY_DATABASE_URI'] = f"mysql+mysqlconnector://{db_user}:{db_password}@{db_host}/{db_name}" logger = logging.getLogger(__name__) # Add this line to define the logger object diff --git a/readme.md b/readme.md index e69de29..cba2082 100644 --- a/readme.md +++ b/readme.md @@ -0,0 +1,10 @@ +# QSyncBackend +QSyncBackend is a simple backend written in Python for syncing files between two directories. It is designed to be used with QSyncUi. + +## Run from source +1. Clone the repository +2. Install the requirements using `pip install -r requirements.txt` +3. Create a `.env` file in the root directory of the repository with .env.example as a template +4. Run the backend using `gunicorn -w 4 -b 127.0.0.1:8080 app:app` + +## Run from Docker