Parcourir la source

feat: dockerfile

Yeuoly il y a 1 an
Parent
commit
f209ce488a

+ 2 - 1
build/build.sh

@@ -1,3 +1,4 @@
 rm -rf /tmp/sandbox-python
 rm -rf internal/core/runner/python/python.so
-go build -o internal/core/runner/python/python.so -buildmode=c-shared -ldflags="-s -w" cmd/lib/python/main.go
+go build -o internal/core/runner/python/python.so -buildmode=c-shared -ldflags="-s -w" cmd/lib/python/main.go
+go build -o main -ldflags="-s -w" cmd/server/main.go

+ 3 - 2
conf/config.yaml

@@ -2,6 +2,7 @@ app:
   port: 8194
   debug: True
   key: dify-sandbox
-max_workers: 3
-max_requests: 100
+max_workers: 4
+max_requests: 50
 worker_timeout: 5
+python_path: /usr/local/bin/python3

+ 12 - 0
dockerfile

@@ -0,0 +1,12 @@
+FROM python:3.10-slim
+
+# copy main binary to /main
+COPY main /main
+COPY conf/config.yaml /conf/config.yaml
+
+RUN apt-get update && apt-get install -y \
+    pkg-config libseccomp-dev \
+    && rm -rf /var/lib/apt/lists/* \
+    && chmod +x /main
+
+ENTRYPOINT ["/main"]

+ 1 - 1
internal/core/runner/python/python.go

@@ -69,7 +69,7 @@ func (p *PythonRunner) Run(code string, timeout time.Duration, stdin []byte) (ch
 		// create a new process
 		ctx, cancel := context.WithTimeout(context.Background(), timeout)
 		cmd := exec.CommandContext(ctx,
-			"/usr/bin/python3",
+			static.GetDifySandboxGlobalConfigurations().PythonPath,
 			"-c",
 			string(python_sandbox_fs),
 			temp_code_path,

+ 9 - 0
internal/static/config.go

@@ -53,6 +53,15 @@ func InitConfig(path string) error {
 		difySandboxGlobalConfigurations.App.Key = api_key
 	}
 
+	python_path := os.Getenv("PYTHON_PATH")
+	if python_path != "" {
+		difySandboxGlobalConfigurations.PythonPath = python_path
+	}
+
+	if difySandboxGlobalConfigurations.PythonPath == "" {
+		difySandboxGlobalConfigurations.PythonPath = "/usr/local/bin/python3"
+	}
+
 	return nil
 }
 

+ 4 - 3
internal/types/config.go

@@ -6,7 +6,8 @@ type DifySandboxGlobalConfigurations struct {
 		Debug bool   `yaml:"debug"`
 		Key   string `yaml:"key"`
 	} `yaml:"app"`
-	MaxWorkers    int `yaml:"max_workers"`
-	MaxRequests   int `yaml:"max_requests"`
-	WorkerTimeout int `yaml:"worker_timeout"`
+	MaxWorkers    int    `yaml:"max_workers"`
+	MaxRequests   int    `yaml:"max_requests"`
+	WorkerTimeout int    `yaml:"worker_timeout"`
+	PythonPath    string `yaml:"python_path"`
 }