local.dockerfile 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. FROM golang:1.23-alpine as builder
  2. ARG VERSION=unknown
  3. # copy project
  4. COPY . /app
  5. # set working directory
  6. WORKDIR /app
  7. # using goproxy if you have network issues
  8. # ENV GOPROXY=https://goproxy.cn,direct
  9. # build
  10. RUN go build \
  11. -ldflags "\
  12. -X 'github.com/langgenius/dify-plugin-daemon/internal/manifest.VersionX=${VERSION}' \
  13. -X 'github.com/langgenius/dify-plugin-daemon/internal/manifest.BuildTimeX=$(date -u +%Y-%m-%dT%H:%M:%S%z)'" \
  14. -o /app/main cmd/server/main.go
  15. # copy entrypoint.sh
  16. COPY entrypoint.sh /app/entrypoint.sh
  17. RUN chmod +x /app/entrypoint.sh
  18. FROM ubuntu:24.04
  19. COPY --from=builder /app/main /app/main
  20. COPY --from=builder /app/entrypoint.sh /app/entrypoint.sh
  21. WORKDIR /app
  22. # check build args
  23. ARG PLATFORM=local
  24. # Install python3.12 if PLATFORM is local
  25. RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y curl python3.12 python3.12-venv python3.12-dev python3-pip ffmpeg build-essential \
  26. && apt-get clean \
  27. && rm -rf /var/lib/apt/lists/* \
  28. && update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 1;
  29. # preload tiktoken
  30. ENV TIKTOKEN_CACHE_DIR=/app/.tiktoken
  31. # Install dify_plugin to speedup the environment setup, test uv and preload tiktoken
  32. RUN mv /usr/lib/python3.12/EXTERNALLY-MANAGED /usr/lib/python3.12/EXTERNALLY-MANAGED.bk \
  33. && python3 -m pip install uv \
  34. && uv pip install --system dify_plugin \
  35. && python3 -c "from uv._find_uv import find_uv_bin;print(find_uv_bin());" \
  36. && python3 -c "import tiktoken; encodings = ['o200k_base', 'cl100k_base', 'p50k_base', 'r50k_base', 'p50k_edit', 'gpt2']; [tiktoken.get_encoding(encoding).special_tokens_set for encoding in encodings]"
  37. ENV PLATFORM=$PLATFORM
  38. ENV GIN_MODE=release
  39. # run the server, using sh as the entrypoint to avoid process being the root process
  40. # and using bash to recycle resources
  41. CMD ["/bin/bash", "-c", "/app/entrypoint.sh"]