From 8f197c5a0ae73cf51adb0af002744f527dde15c0 Mon Sep 17 00:00:00 2001 From: Stephen Zhou Date: Wed, 20 May 2026 11:48:18 +0800 Subject: [PATCH] build: fix api docker build (#36423) --- .github/workflows/build-push.yml | 12 ++++++------ .github/workflows/docker-build.yml | 18 ++++++++++++------ api/Dockerfile | 12 +++++++----- api/Dockerfile.dockerignore | 25 +++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 17 deletions(-) create mode 100644 api/Dockerfile.dockerignore diff --git a/.github/workflows/build-push.yml b/.github/workflows/build-push.yml index 915ed6cfe8..d35a5ae178 100644 --- a/.github/workflows/build-push.yml +++ b/.github/workflows/build-push.yml @@ -35,15 +35,15 @@ jobs: - service_name: "build-api-amd64" image_name_env: "DIFY_API_IMAGE_NAME" artifact_context: "api" - build_context: "{{defaultContext}}:api" - file: "Dockerfile" + build_context: "{{defaultContext}}" + file: "api/Dockerfile" platform: linux/amd64 runs_on: depot-ubuntu-24.04-4 - service_name: "build-api-arm64" image_name_env: "DIFY_API_IMAGE_NAME" artifact_context: "api" - build_context: "{{defaultContext}}:api" - file: "Dockerfile" + build_context: "{{defaultContext}}" + file: "api/Dockerfile" platform: linux/arm64 runs_on: depot-ubuntu-24.04-4 - service_name: "build-web-amd64" @@ -117,8 +117,8 @@ jobs: matrix: include: - service_name: "validate-api-amd64" - build_context: "{{defaultContext}}:api" - file: "Dockerfile" + build_context: "{{defaultContext}}" + file: "api/Dockerfile" - service_name: "validate-web-amd64" build_context: "{{defaultContext}}" file: "web/Dockerfile" diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 5144510be5..987edc37ef 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -6,6 +6,12 @@ on: - "main" paths: - api/Dockerfile + - api/Dockerfile.dockerignore + - api/pyproject.toml + - api/uv.lock + - dify-agent/pyproject.toml + - dify-agent/README.md + - dify-agent/src/** - web/Dockerfile concurrency: @@ -25,13 +31,13 @@ jobs: - service_name: "api-amd64" platform: linux/amd64 runs_on: depot-ubuntu-24.04-4 - context: "{{defaultContext}}:api" - file: "Dockerfile" + context: "{{defaultContext}}" + file: "api/Dockerfile" - service_name: "api-arm64" platform: linux/arm64 runs_on: depot-ubuntu-24.04-4 - context: "{{defaultContext}}:api" - file: "Dockerfile" + context: "{{defaultContext}}" + file: "api/Dockerfile" - service_name: "web-amd64" platform: linux/amd64 runs_on: depot-ubuntu-24.04-4 @@ -64,8 +70,8 @@ jobs: matrix: include: - service_name: "api-amd64" - context: "{{defaultContext}}:api" - file: "Dockerfile" + context: "{{defaultContext}}" + file: "api/Dockerfile" - service_name: "web-amd64" context: "{{defaultContext}}" file: "web/Dockerfile" diff --git a/api/Dockerfile b/api/Dockerfile index 8425578953..81296ee076 100644 --- a/api/Dockerfile +++ b/api/Dockerfile @@ -22,9 +22,11 @@ RUN apt-get update \ libmpfr-dev libmpc-dev # Install Python dependencies (workspace members under providers/vdb/) -COPY pyproject.toml uv.lock ./ -COPY providers ./providers -# Trust the checked-in lock during image builds; dev-only path sources live outside the api/ context. +COPY api/pyproject.toml api/uv.lock ./ +COPY api/providers ./providers +COPY dify-agent/pyproject.toml dify-agent/README.md /app/dify-agent/ +COPY dify-agent/src /app/dify-agent/src +# Trust the checked-in lock during image builds; local path sources are copied from the repository context. RUN uv sync --frozen --no-dev # production stage @@ -108,10 +110,10 @@ RUN python -c "import tiktoken; tiktoken.encoding_for_model('gpt2')" \ && chown -R dify:dify ${TIKTOKEN_CACHE_DIR} # Copy source code -COPY --chown=dify:dify . /app/api/ +COPY --chown=dify:dify api /app/api/ # Prepare entrypoint script -COPY --chown=dify:dify --chmod=755 docker/entrypoint.sh /entrypoint.sh +COPY --chown=dify:dify --chmod=755 api/docker/entrypoint.sh /entrypoint.sh ARG COMMIT_SHA diff --git a/api/Dockerfile.dockerignore b/api/Dockerfile.dockerignore new file mode 100644 index 0000000000..8ec1323c3f --- /dev/null +++ b/api/Dockerfile.dockerignore @@ -0,0 +1,25 @@ +* + +!api/ +!api/** +!dify-agent/ +!dify-agent/pyproject.toml +!dify-agent/README.md +!dify-agent/src/ +!dify-agent/src/** + +api/.venv +api/.venv/** +api/.env +api/*.env.* +api/.idea +api/.mypy_cache +api/.ruff_cache +api/storage/generate_files/* +api/storage/privkeys/* +api/storage/tools/* +api/storage/upload_files/* +api/logs +api/*.log* +**/__pycache__ +**/*.pyc