Explorar o código

refactor: docker build

Yeuoly hai 6 meses
pai
achega
17383467ee
Modificáronse 3 ficheiros con 39 adicións e 7 borrados
  1. 1 1
      .github/workflows/build-push.yml
  2. 4 6
      Dockerfile
  3. 34 0
      docker/serverless.dockerfile

+ 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 --build-arg PLATFORM=${{ matrix.scope }} --build-arg VERSION=${{ github.sha }} -t dify-plugin-daemon -f ./Dockerfile .
+        run: docker build --build-arg PLATFORM=${{ matrix.scope }} --build-arg VERSION=${{ github.sha }} -t dify-plugin-daemon -f ./docker/${{ matrix.scope }}.dockerfile .
 
       - name: Tag Docker Images
         run:

+ 4 - 6
Dockerfile

@@ -33,12 +33,10 @@ WORKDIR /app
 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; \
-    fi
+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;
 
 ENV PLATFORM=$PLATFORM
 ENV GIN_MODE=release

+ 34 - 0
docker/serverless.dockerfile

@@ -0,0 +1,34 @@
+FROM golang:1.22-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
+RUN CGO_ENABLED=0 go build \
+    -ldflags "\
+    -X 'github.com/langgenius/dify-plugin-daemon/internal/manifest.VersionX=${VERSION}' \
+    -X 'github.com/langgenius/dify-plugin-daemon/internal/manifest.BuildTimeX=$(date -u +%Y-%m-%dT%H:%M:%S%z)'" \
+    -o /app/main cmd/server/main.go
+
+FROM alpine:latest
+
+COPY --from=builder /app/main /app/main
+
+WORKDIR /app
+
+# check build args
+ARG PLATFORM=aws_lambda
+
+ENV PLATFORM=$PLATFORM
+ENV GIN_MODE=release
+
+# run the server
+CMD ["./main"]