Skip to content

Commit

Permalink
refactor: docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
Yeuoly committed Jan 6, 2025
1 parent 8796eda commit e39b35d
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
17 changes: 12 additions & 5 deletions docker/local/Dockerfile → Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
FROM golang:1.22-alpine as builder

ARG VERSION=unknown

# copy project
COPY . /app

Expand All @@ -10,21 +12,26 @@ 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

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"]
24 changes: 0 additions & 24 deletions docker/serverless/Dockerfile

This file was deleted.

4 changes: 4 additions & 0 deletions internal/manifest/manifest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package manifest

var VersionX string
var BuildTimeX string
15 changes: 12 additions & 3 deletions internal/server/controllers/health_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}
}
2 changes: 1 addition & 1 deletion internal/server/http_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit e39b35d

Please sign in to comment.