ソースを参照

refactor: docker build

Yeuoly 6 ヶ月 前
コミット
e39b35d7d9

+ 1 - 1
.github/workflows/build-push.yml

@@ -68,7 +68,7 @@ jobs:
             type=raw,value=${{ github.ref_name }},enable=${{ startsWith(github.ref, 'refs/tags/') }}
 
       - name: Run Build Docker Image
-        run: docker build -t dify-plugin-daemon -f ./docker/${{ matrix.scope }}/Dockerfile .
+        run: docker build --build-arg PLATFORM=${{ matrix.scope }} -t dify-plugin-daemon -f ./Dockerfile .
 
       - name: Tag Docker Images
         run:

+ 12 - 5
docker/local/Dockerfile

@@ -1,5 +1,7 @@
 FROM golang:1.22-alpine as builder
 
+ARG VERSION=unknown
+
 # copy project
 COPY . /app
 
@@ -10,7 +12,7 @@ WORKDIR /app
 # ENV GOPROXY=https://goproxy.cn,direct
 
 # build
-RUN go build -o /app/main cmd/server/main.go
+RUN go build -ldflags "-X 'internal.manifest.VersionX=${VERSION}' -X 'internal.manifest.BuildTimeX=$(date -u +%Y-%m-%dT%H:%M:%S%z)'" -o /app/main cmd/server/main.go
 
 FROM ubuntu:24.04
 
@@ -18,13 +20,18 @@ COPY --from=builder /app/main /app/main
 
 WORKDIR /app
 
-# Install python3.12
-RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y python3.12 python3.12-venv python3.12-dev \
+# check build args
+ARG PLATFORM=local
+
+# Install python3.12 if PLATFORM is local
+RUN if [ "$PLATFORM" = "local" ]; then \
+    apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y python3.12 python3.12-venv python3.12-dev \
     && apt-get clean \
     && rm -rf /var/lib/apt/lists/* \
-    && update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 1
+    && update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 1; \
+    fi
 
-ENV PLATFORM=local
+ENV PLATFORM=$PLATFORM
 ENV GIN_MODE=release
 
 CMD ["/app/main"]

+ 0 - 24
docker/serverless/Dockerfile

@@ -1,24 +0,0 @@
-FROM golang:1.22-alpine as builder
-
-# copy project
-COPY . /app
-
-# set working directory
-WORKDIR /app
-
-# using goproxy if you have network issues
-# ENV GOPROXY=https://goproxy.cn,direct
-
-# build
-RUN CGO_ENABLED=0 GOOS=linux go build -o /app/main cmd/server/main.go
-
-FROM alpine:latest
-
-COPY --from=builder /app/main /app/main
-
-WORKDIR /app
-
-ENV PLATFORM=aws_lambda
-ENV GIN_MODE=release
-
-CMD ["./main"]

+ 4 - 0
internal/manifest/manifest.go

@@ -0,0 +1,4 @@
+package manifest
+
+var VersionX string
+var BuildTimeX string

+ 12 - 3
internal/server/controllers/health_check.go

@@ -2,10 +2,19 @@ package controllers
 
 import (
 	"github.com/gin-gonic/gin"
+	"github.com/langgenius/dify-plugin-daemon/internal/manifest"
+	"github.com/langgenius/dify-plugin-daemon/internal/types/app"
 	"github.com/langgenius/dify-plugin-daemon/internal/utils/routine"
 )
 
-func HealthCheck(c *gin.Context) {
-	routine.InitPool(10)
-	c.JSON(200, gin.H{"status": "ok", "pool_status": routine.FetchRoutineStatus()})
+func HealthCheck(app *app.Config) gin.HandlerFunc {
+	return func(c *gin.Context) {
+		c.JSON(200, gin.H{
+			"status":      "ok",
+			"pool_status": routine.FetchRoutineStatus(),
+			"version":     manifest.VersionX,
+			"build_time":  manifest.BuildTimeX,
+			"platform":    app.Platform,
+		})
+	}
 }

+ 1 - 1
internal/server/http_server.go

@@ -20,7 +20,7 @@ import (
 // server starts a http server and returns a function to stop it
 func (app *App) server(config *app.Config) func() {
 	engine := gin.Default()
-	engine.GET("/health/check", controllers.HealthCheck)
+	engine.GET("/health/check", controllers.HealthCheck(config))
 
 	endpointGroup := engine.Group("/e")
 	awsLambdaTransactionGroup := engine.Group("/backwards-invocation")