Skip to content

Commit

Permalink
chore: Set default DB host to "mysql", and add default DB user as "root"
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Porter committed Jul 6, 2024
1 parent 60ff6a0 commit 48e1b9d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
13 changes: 13 additions & 0 deletions .github/workflow/pushToGhcr.yaml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
10 changes: 10 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 48e1b9d

Please sign in to comment.