Add Docker Compose deployment support

This commit is contained in:
youbin
2026-03-21 21:18:51 +08:00
parent 8d715a3a15
commit ddb1b46c13
5 changed files with 125 additions and 1 deletions

15
.dockerignore Normal file
View File

@@ -0,0 +1,15 @@
.env
.git
.gitignore
.DS_Store
__pycache__/
.pycache/
.pytest_cache/
.venv/
venv/
dist/
build/
logs/
reference-office365-tools/
tests/

21
Dockerfile Normal file
View File

@@ -0,0 +1,21 @@
FROM python:3.11-slim
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=1
WORKDIR /app
COPY requirements.txt /app/requirements.txt
RUN pip install --no-cache-dir -r /app/requirements.txt
COPY app.py /app/app.py
COPY office365_admin /app/office365_admin
COPY README.md /app/README.md
RUN mkdir -p /app/logs
EXPOSE 8000
CMD ["gunicorn", "-w", "2", "-b", "0.0.0.0:8000", "app:app"]

View File

@@ -74,6 +74,66 @@ python3 app.py
- [http://127.0.0.1:8000](http://127.0.0.1:8000)
## Docker Compose 部署
项目已经提供:
- [Dockerfile](/Users/youbin/Desktop/Office365UserManage/Dockerfile)
- [docker-compose.yml](/Users/youbin/Desktop/Office365UserManage/docker-compose.yml)
- [.dockerignore](/Users/youbin/Desktop/Office365UserManage/.dockerignore)
部署前提:
- 服务器或本机已安装 Docker Engine
- 已安装 Docker Compose 插件,确保 `docker compose version` 可以正常执行
部署步骤:
1. 先准备好本地 `.env`
```bash
cp .env.example .env
```
必填项至少包括:
- `CLIENT_ID`
- `TENANT_ID`
- `CLIENT_SECRET`
- `DEFAULT_PASSWORD`
2. 在项目根目录执行构建并启动
```bash
docker compose up -d --build
```
3. 查看容器状态
```bash
docker compose ps
```
4. 查看运行日志
```bash
docker compose logs -f office365manage
```
5. 停止服务
```bash
docker compose down
```
说明:
- Compose 会读取你本地的 `.env`,但 `.env` 不会被打包进镜像,也不会进入 Git。
- 容器内固定监听 `8000` 端口,并通过 `8000:8000` 映射到宿主机。
- 应用日志会落在宿主机的 `./logs` 目录,便于排查任务执行详情。
- 如果你要改宿主机端口,可以修改 [docker-compose.yml](/Users/youbin/Desktop/Office365UserManage/docker-compose.yml) 中 `ports` 左侧的端口值。
- 如果宿主机的 `8000` 端口已经被本地 `python3 app.py` 等进程占用,请先停止原有服务,或者修改映射端口后再启动 Compose。
## 批量导入格式
### 批量创建 CSV

28
docker-compose.yml Normal file
View File

@@ -0,0 +1,28 @@
services:
office365manage:
container_name: office365manage
build:
context: .
dockerfile: Dockerfile
env_file:
- .env
environment:
HOST: 0.0.0.0
PORT: 8000
ports:
- "8000:8000"
volumes:
- ./logs:/app/logs
restart: unless-stopped
healthcheck:
test:
[
"CMD",
"python",
"-c",
"import urllib.request; urllib.request.urlopen('http://127.0.0.1:8000/api/health', timeout=5)"
]
interval: 30s
timeout: 10s
retries: 3
start_period: 20s

View File

@@ -2,4 +2,4 @@ Flask>=3.0,<4
python-dotenv>=1.0,<2
requests>=2.31,<3
pytest>=8.0,<9
gunicorn>=21,<24