Skip to content

Commit

Permalink
Merge branch 'refs/heads/deploy/dev' into feat/cleaning_ops_trace
Browse files Browse the repository at this point in the history
* refs/heads/deploy/dev: (273 commits)
  chore: host required
  fix: monitor copywrite
  feat: make show citations enable default
  chore: use singular style in middleware config class name (#5502)
  refactor: extract hosted service configs into dify config (#5504)
  fix: summary of duckduckgo_search (#5488)
  fix: zhipu tool calling, this PR fixes the bug described in issue #5496 (#5469)
  fix: tongyi json output (#5396)
  fix: firecrawl apikey not start with fc- (#5498)
  fix lock
  refactor: extract db configs and celery configs into dify config (#5491)
  refactor: extract storage provider configs into dify configs (#5443)
  chore: use singular style in config class name (#5489)
  chore: remove pip support for api service (#5453)
  Add Oracle23ai as a vector datasource (#5342)
  build: support Poetry for depencencies tool in api's Dockerfile (#5105)
  feat: add ops trace encrypt_config decrypt_config obfuscate_config
  feat: add remove tracing app
  fix: max_tokens of qwen-plus & qwen-plus-chat (#5480)
  feat: add support for Vertex AI claude-3-5-sonnet@20240620 (#5475)
  ...
  • Loading branch information
ZhouhaoJiang committed Jun 24, 2024
2 parents ad7fbc7 + 1a33d88 commit 871c8be
Show file tree
Hide file tree
Showing 110 changed files with 3,933 additions and 880 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/post_start_command.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

cd api && pip install -r requirements.txt
poetry install -C api
72 changes: 3 additions & 69 deletions .github/workflows/api-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,74 +14,6 @@ concurrency:

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version:
- "3.10"
- "3.11"

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
cache-dependency-path: |
./api/requirements.txt
./api/requirements-dev.txt
- name: Install dependencies
run: pip install -r ./api/requirements.txt -r ./api/requirements-dev.txt

- name: Run Unit tests
run: dev/pytest/pytest_unit_tests.sh

- name: Run ModelRuntime
run: dev/pytest/pytest_model_runtime.sh

- name: Run Tool
run: dev/pytest/pytest_tools.sh

- name: Set up Sandbox
uses: hoverkraft-tech/[email protected]
with:
compose-file: |
docker/docker-compose.middleware.yaml
services: |
sandbox
ssrf_proxy
- name: Run Workflow
run: dev/pytest/pytest_workflow.sh

- name: Set up Vector Stores (Weaviate, Qdrant, PGVector, Milvus, PgVecto-RS, Chroma)
uses: hoverkraft-tech/[email protected]
with:
compose-file: |
docker/docker-compose.middleware.yaml
docker/docker-compose.qdrant.yaml
docker/docker-compose.milvus.yaml
docker/docker-compose.pgvecto-rs.yaml
docker/docker-compose.pgvector.yaml
docker/docker-compose.chroma.yaml
services: |
weaviate
qdrant
etcd
minio
milvus-standalone
pgvecto-rs
pgvector
chroma
- name: Test Vector Stores
run: dev/pytest/pytest_vdb.sh

test-in-poetry:
name: API Tests
runs-on: ubuntu-latest
strategy:
Expand All @@ -108,7 +40,7 @@ jobs:
- name: Poetry check
run: |
poetry check -C api
poetry check -C api --lock
poetry show -C api
- name: Install dependencies
Expand Down Expand Up @@ -145,6 +77,7 @@ jobs:
docker/docker-compose.pgvecto-rs.yaml
docker/docker-compose.pgvector.yaml
docker/docker-compose.chroma.yaml
docker/docker-compose.oracle.yaml
services: |
weaviate
qdrant
Expand All @@ -154,6 +87,7 @@ jobs:
pgvecto-rs
pgvector
chroma
oracle
- name: Test Vector Stores
run: poetry run -C api bash dev/pytest/pytest_vdb.sh
113 changes: 95 additions & 18 deletions .github/workflows/build-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,46 @@ on:
release:
types: [published]

concurrency:
group: build-push-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

env:
DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
DIFY_WEB_IMAGE_NAME: ${{ vars.DIFY_WEB_IMAGE_NAME || 'langgenius/dify-web' }}
DIFY_API_IMAGE_NAME: ${{ vars.DIFY_API_IMAGE_NAME || 'langgenius/dify-api' }}

jobs:
build-and-push:
runs-on: ubuntu-latest
build:
runs-on: ${{ matrix.platform == 'linux/arm64' && 'arm64_runner' || 'ubuntu-latest' }}
if: github.repository == 'langgenius/dify'
strategy:
matrix:
include:
- service_name: "web"
image_name_env: "DIFY_WEB_IMAGE_NAME"
context: "web"
- service_name: "api"
- service_name: "build-api-amd64"
image_name_env: "DIFY_API_IMAGE_NAME"
context: "api"
platform: linux/amd64
- service_name: "build-api-arm64"
image_name_env: "DIFY_API_IMAGE_NAME"
context: "api"
platform: linux/arm64
- service_name: "build-web-amd64"
image_name_env: "DIFY_WEB_IMAGE_NAME"
context: "web"
platform: linux/amd64
- service_name: "build-web-arm64"
image_name_env: "DIFY_WEB_IMAGE_NAME"
context: "web"
platform: linux/arm64

steps:
- name: Prepare
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

Expand All @@ -40,7 +60,66 @@ jobs:
username: ${{ env.DOCKERHUB_USER }}
password: ${{ env.DOCKERHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env[matrix.image_name_env] }}

- name: Build Docker image
id: build
uses: docker/build-push-action@v6
with:
context: "{{defaultContext}}:${{ matrix.context }}"
platforms: ${{ matrix.platform }}
build-args: COMMIT_SHA=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }}
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=${{ env[matrix.image_name_env] }},push-by-digest=true,name-canonical=true,push=true
cache-from: type=gha,scope=${{ matrix.service_name }}
cache-to: type=gha,mode=max,scope=${{ matrix.service_name }}

- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ matrix.context }}-${{ env.PLATFORM_PAIR }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1

create-manifest:
needs: build
runs-on: ubuntu-latest
if: github.repository == 'langgenius/dify'
strategy:
matrix:
include:
- service_name: "merge-api-images"
image_name_env: "DIFY_API_IMAGE_NAME"
context: "api"
- service_name: "merge-web-images"
image_name_env: "DIFY_WEB_IMAGE_NAME"
context: "web"
steps:
- name: Download digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-${{ matrix.context }}-*
merge-multiple: true

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ env.DOCKERHUB_USER }}
password: ${{ env.DOCKERHUB_TOKEN }}

- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
Expand All @@ -51,14 +130,12 @@ jobs:
type=sha,enable=true,priority=100,prefix=,suffix=,format=long
type=raw,value=${{ github.ref_name }},enable=${{ startsWith(github.ref, 'refs/tags/') }}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: "{{defaultContext}}:${{ matrix.context }}"
platforms: ${{ startsWith(github.ref, 'refs/tags/') && 'linux/amd64,linux/arm64' || 'linux/amd64' }}
build-args: COMMIT_SHA=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env[matrix.image_name_env] }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env[matrix.image_name_env] }}:${{ steps.meta.outputs.version }}
5 changes: 3 additions & 2 deletions .github/workflows/style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ jobs:
**.sh
**.yaml
**.yml
Dockerfile
**Dockerfile
dev/**
- name: Super-linter
Expand All @@ -113,7 +113,8 @@ jobs:
IGNORE_GITIGNORED_FILES: true
VALIDATE_BASH: true
VALIDATE_BASH_EXEC: true
VALIDATE_GITHUB_ACTIONS: true
# FIXME: temporarily disabled until api-docker.yaml's run script is fixed for shellcheck
# VALIDATE_GITHUB_ACTIONS: true
VALIDATE_DOCKERFILE_HADOLINT: true
VALIDATE_XML: true
VALIDATE_YAML: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ web/.vscode/settings.json
!.idea/vcs.xml
!.idea/icon.png
.ideaDataSources/
*.iml

api/.env
api/storage/*
Expand Down
5 changes: 4 additions & 1 deletion api/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ logs
*.log*

# jetbrains
.idea
.idea

# venv
.venv
1 change: 1 addition & 0 deletions api/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,4 @@ WORKFLOW_CALL_MAX_DEPTH=5
# App configuration
APP_MAX_EXECUTION_TIME=1200


33 changes: 25 additions & 8 deletions api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
# base image
FROM python:3.10-slim-bookworm AS base
FROM python:3.10-slim-bookworm as base

LABEL maintainer="[email protected]"
WORKDIR /app/api

# Install Poetry
ENV POETRY_VERSION=1.8.3
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir --upgrade poetry==${POETRY_VERSION}

# Configure Poetry
ENV POETRY_CACHE_DIR=/tmp/poetry_cache
ENV POETRY_NO_INTERACTION=1
ENV POETRY_VIRTUALENVS_IN_PROJECT=true
ENV POETRY_VIRTUALENVS_CREATE=true

# install packages
FROM base as packages

RUN apt-get update \
&& apt-get install -y --no-install-recommends gcc g++ libc-dev libffi-dev libgmp-dev libmpfr-dev libmpc-dev

COPY requirements.txt /requirements.txt
# Install Python dependencies
COPY pyproject.toml poetry.lock ./
RUN poetry install --sync --no-cache --no-root

RUN --mount=type=cache,target=/root/.cache/pip \
pip install --prefix=/pkg -r requirements.txt

# production stage
FROM base AS production
Expand All @@ -37,13 +47,20 @@ RUN apt-get update \
&& apt-get autoremove \
&& rm -rf /var/lib/apt/lists/*

COPY --from=packages /pkg /usr/local
# Copy Python environment and packages
ENV VIRTUAL_ENV=/app/api/.venv
COPY --from=packages ${VIRTUAL_ENV} ${VIRTUAL_ENV}
ENV PATH="${VIRTUAL_ENV}/bin:${PATH}"

# Copy source code
COPY . /app/api/

# Copy entrypoint
COPY docker/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh


ARG COMMIT_SHA
ENV COMMIT_SHA ${COMMIT_SHA}

ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]
ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]
Loading

0 comments on commit 871c8be

Please sign in to comment.