Skip to content

Commit 59acfeb

Browse files
committed
Refactor Dockerfile; update docker-compose command formatting
1 parent 6068df8 commit 59acfeb

File tree

3 files changed

+45
-29
lines changed

3 files changed

+45
-29
lines changed

backend/Dockerfile

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,64 @@
1+
ARG SERVICE_TYPE=fastapi_server
2+
3+
# ===== Build Stage =====
14
FROM python:3.10-slim AS builder
25
COPY --from=ghcr.io/astral-sh/uv:0.6.2 /uv /uvx /bin/
36

4-
RUN sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list.d/debian.sources && \
5-
apt-get update \
6-
&& apt-get install -y --no-install-recommends gcc python3-dev\
7+
# Install dependencies for building Python packages
8+
RUN sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list.d/debian.sources \
9+
&& apt-get update \
10+
&& apt-get install -y --no-install-recommends gcc python3-dev \
711
&& rm -rf /var/lib/apt/lists/*
812

9-
ENV UV_COMPILE_BYTECODE=1
10-
ENV UV_NO_CACHE=1
11-
ENV UV_LINK_MODE=copy
12-
ENV UV_PROJECT_ENVIRONMENT=/usr/local
13+
# Configure uv environment
14+
ENV UV_COMPILE_BYTECODE=1 \
15+
UV_NO_CACHE=1 \
16+
UV_LINK_MODE=copy \
17+
UV_PROJECT_ENVIRONMENT=/usr/local
18+
19+
# COPY backend/plugin/casbin/requirements.txt plugin_casbin_requirements.txt
1320

14-
# Install dependencies
21+
# Install dependencies using uv (with cache optimization)
1522
RUN --mount=type=cache,target=/root/.cache/uv \
1623
--mount=type=bind,source=backend/uv.lock,target=uv.lock \
1724
--mount=type=bind,source=backend/pyproject.toml,target=pyproject.toml \
18-
uv sync --frozen --no-install-project --no-default-groups --group server
25+
uv sync --frozen --no-install-project --no-default-groups --group server \
26+
# && uv pip install --system -r plugin_casbin_requirements.txt
1927

2028

21-
FROM python:3.10-slim
22-
29+
# ===== Runtime Base Image =====
30+
FROM python:3.10-slim AS runtime
2331
SHELL ["/bin/bash", "-c"]
24-
2532
ENV TZ="Asia/Shanghai"
2633

27-
WORKDIR /fba
28-
29-
RUN sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list.d/debian.sources && \
30-
apt-get update \
34+
# Install runtime dependencies
35+
RUN sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list.d/debian.sources \
36+
&& apt-get update \
3137
&& apt-get install -y --no-install-recommends supervisor procps iproute2 \
32-
&& rm -rf /var/lib/apt/lists/* \
33-
&& mkdir -p /var/log/fastapi_server \
34-
&& mkdir -p /var/log/celery
38+
&& rm -rf /var/lib/apt/lists/*
3539

36-
COPY . .
37-
RUN chmod +x backend/*.sh
40+
# Copy application and Python packages
41+
COPY . /fba
3842
COPY --from=builder /usr/local /usr/local
39-
COPY deploy/backend/supervisord.conf /etc/supervisor/supervisord.conf
40-
ARG SERVICE_TYPE=fastapi_server
41-
COPY deploy/backend/${SERVICE_TYPE}.conf /etc/supervisor/conf.d/
4243

44+
# ===== FastAPI Server Image =====
45+
FROM runtime AS fastapi_server
46+
WORKDIR /fba/backend
47+
RUN mkdir -p /var/log/fastapi_server
48+
COPY deploy/backend/supervisord.conf /etc/supervisor/supervisord.conf
49+
COPY deploy/backend/fastapi_server.conf /etc/supervisor/conf.d/
4350
EXPOSE 8001
51+
ENV PYTHONPATH=/fba
52+
CMD ["uvicorn", "backend.main:app", "--host", "0.0.0.0", "--port","8000"]
53+
54+
# ===== Celery Worker Image =====
55+
FROM runtime AS celery
56+
WORKDIR /fba/backend
57+
RUN mkdir -p /var/log/celery && chmod +x /fba/backend/*.sh
58+
COPY deploy/backend/supervisord.conf /etc/supervisor/supervisord.conf
59+
COPY deploy/backend/celery.conf /etc/supervisor/conf.d/
4460
EXPOSE 8555
61+
CMD ["./celery-start.sh"]
4562

46-
CMD ["backend/${SERVICE_TYPE}-start.sh"]
63+
# Select the image type based on SERVICE_TYPE build arg
64+
FROM ${SERVICE_TYPE}

backend/fastapi_server-start.sh

Lines changed: 0 additions & 3 deletions
This file was deleted.

deploy/backend/docker-compose/docker-compose.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ services:
3636
- fba_mysql:/var/lib/mysql
3737
networks:
3838
- fba_network
39-
command: --default-authentication-plugin=mysql_native_password
39+
command: |
40+
--default-authentication-plugin=mysql_native_password
4041
--character-set-server=utf8mb4
4142
--collation-server=utf8mb4_general_ci
4243
--lower_case_table_names=1

0 commit comments

Comments
 (0)