mirror of
https://github.com/langgenius/dify-plugin-daemon.git
synced 2026-07-22 01:35:24 -04:00
85 lines
2.3 KiB
Docker
85 lines
2.3 KiB
Docker
# syntax=docker/dockerfile:1
|
|
FROM golang:1.25.8-alpine AS builder
|
|
|
|
ARG VERSION=unknown
|
|
|
|
# copy project
|
|
COPY . /app
|
|
|
|
# set working directory
|
|
WORKDIR /app
|
|
|
|
# using goproxy if you have network issues
|
|
# ENV GOPROXY=https://goproxy.cn,direct
|
|
|
|
# build server
|
|
RUN go build \
|
|
-ldflags "\
|
|
-X 'github.com/langgenius/dify-plugin-daemon/pkg/manifest.VersionX=${VERSION}' \
|
|
-X 'github.com/langgenius/dify-plugin-daemon/pkg/manifest.BuildTimeX=$(date -u +%Y-%m-%dT%H:%M:%S%z)'" \
|
|
-o /app/main cmd/server/main.go
|
|
|
|
# build commandline (migrate)
|
|
RUN go build -ldflags "-X 'main.VersionX=${VERSION}'" -o /app/commandline ./cmd/commandline/
|
|
|
|
FROM ubuntu:24.04
|
|
|
|
WORKDIR /app
|
|
|
|
# check build args
|
|
ARG PLATFORM=local
|
|
|
|
# Install python3.12 if PLATFORM is local
|
|
RUN <<EOF bash
|
|
|
|
set -ex
|
|
set -o pipefail
|
|
trap 'echo "Exit status $? at line $LINENO from: $BASH_COMMAND"' ERR
|
|
|
|
apt-get update
|
|
|
|
DEBIAN_FRONTEND=noninteractive apt-get install -y curl python3.12 \
|
|
python3.12-venv python3.12-dev python3-pip ffmpeg \
|
|
build-essential git \
|
|
cmake pkg-config \
|
|
libcairo2-dev libjpeg-dev libgif-dev \
|
|
tini
|
|
|
|
apt-get clean
|
|
rm -rf /var/lib/apt/lists/*
|
|
update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 1;
|
|
EOF
|
|
|
|
# preload tiktoken
|
|
ENV TIKTOKEN_CACHE_DIR=/app/.tiktoken
|
|
|
|
# Install dify_plugin to speedup the environment setup, test uv and preload tiktoken
|
|
RUN <<EOF bash
|
|
|
|
set -ex
|
|
set -o pipefail
|
|
trap 'echo "Exit status $? at line $LINENO from: $BASH_COMMAND"' ERR
|
|
|
|
mv /usr/lib/python3.12/EXTERNALLY-MANAGED /usr/lib/python3.12/EXTERNALLY-MANAGED.bk
|
|
python3 -m pip install uv
|
|
uv pip install --system dify_plugin
|
|
|
|
python3 -c "from uv._find_uv import find_uv_bin;print(find_uv_bin());"
|
|
|
|
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]"
|
|
EOF
|
|
|
|
ENV UV_PATH=/usr/local/bin/uv
|
|
ENV PLATFORM=$PLATFORM
|
|
ENV GIN_MODE=release
|
|
|
|
COPY --from=builder /app/main /app/commandline /app/
|
|
|
|
# Use tini as PID 1 so that /app/main is NOT PID 1 inside the container.
|
|
# The Python plugin SDK self-destructs (os._exit(-1), exit 255) when its
|
|
# parent process is PID 1, because it treats that as an "orphaned" state.
|
|
ENTRYPOINT ["/usr/bin/tini", "-g", "--"]
|
|
|
|
# run migrate then start the server
|
|
CMD ["/bin/bash", "-c", "/app/commandline migrate && exec /app/main"]
|