Tao Chen 1 год назад
Родитель
Сommit
461b100b6c
3 измененных файлов с 60 добавлено и 21 удалено
  1. 25 3
      .dockerignore
  2. 30 16
      Dockerfile.dev
  3. 5 2
      docker-compose.yaml

+ 25 - 3
.dockerignore

@@ -1,4 +1,26 @@
1
+# Ignore Docker Compose configuration files
1
 docker-compose.yaml
2
 docker-compose.yaml
2
-Dcokerfile
3
-Dcokerfile.dev
4
-data
3
+
4
+# Ignore development Dockerfile
5
+Dockerfile.dev
6
+
7
+# Ignore the data directory
8
+data/
9
+
10
+# Ignore version control system directories
11
+.git/
12
+
13
+# Ignore log and temporary files
14
+*.log
15
+*.tmp
16
+*.swp
17
+
18
+# Ignore editor/IDE configuration files
19
+.vscode/
20
+.idea/
21
+
22
+# Ignore binaries and build cache
23
+release/
24
+bin/
25
+*.exe
26
+*.out

+ 30 - 16
Dockerfile.dev

@@ -1,36 +1,50 @@
1
 # Use build arguments for Go version and architecture
1
 # Use build arguments for Go version and architecture
2
-ARG GO_VERSION=1.23.2
3
-ARG BUILDARCH
2
+ARG GO_VERSION=1.22
3
+ARG BUILDARCH=amd64
4
 
4
 
5
-# Stage 1: Build the Go application with swag
6
-FROM golang:${GO_VERSION} AS builder
5
+# Stage 1: Builder Stage
6
+# FROM golang:${GO_VERSION}-alpine AS builder
7
+FROM crazymax/xgo:${GO_VERSION} AS builder
7
 
8
 
8
 # Set up working directory
9
 # Set up working directory
9
 WORKDIR /app
10
 WORKDIR /app
10
 
11
 
11
-# Install dependencies and copy the source code
12
-COPY go.mod ./
13
-RUN go install github.com/swaggo/swag/cmd/swag@latest
14
-RUN go mod download
12
+# Step 1: Copy the source code
15
 COPY . .
13
 COPY . .
16
 
14
 
17
-#run the build script
18
-RUN chmod +x build.sh && ./build.sh
15
+# Step 2: Download dependencies
16
+RUN go mod tidy && go mod download
19
 
17
 
20
-# Stage 2: Prepare the final image
18
+
19
+# Step 3: Install swag and  Run the build script
20
+RUN go install github.com/swaggo/swag/cmd/swag@latest && \
21
+    swag init -g cmd/apimain.go --output docs/api --instanceName api --exclude http/controller/admin && \
22
+    swag init -g cmd/apimain.go --output docs/admin --instanceName admin --exclude http/controller/api
23
+
24
+# Build the Go application with CGO enabled and specified ldflags
25
+RUN CGO_ENABLED=1 GOOS=linux go build -a \
26
+    -ldflags "-s -w --extldflags '-static -fpic'" \
27
+    -installsuffix cgo -o release/apimain cmd/apimain.go
28
+
29
+
30
+# Stage 2: Final Image
21
 FROM alpine:latest
31
 FROM alpine:latest
22
 
32
 
23
 # Set up working directory
33
 # Set up working directory
24
 WORKDIR /app
34
 WORKDIR /app
25
 
35
 
26
-# Install necessary dependencies
36
+# Install necessary runtime dependencies
27
 RUN apk add --no-cache tzdata file
37
 RUN apk add --no-cache tzdata file
28
 
38
 
29
-# Copy the built application from the builder stage
39
+# Copy the built application and resources from the builder stage
30
 COPY --from=builder /app/release /app/
40
 COPY --from=builder /app/release /app/
41
+COPY --from=builder /app/conf /app/conf/
42
+COPY --from=builder /app/resources /app/resources/
31
 
43
 
32
-# Ensure the binary is correctly built
33
-RUN file /app/apimain
44
+# Ensure the binary is correctly built and linked
45
+RUN file /app/apimain && \
46
+    mkdir -p /app/data && \
47
+    mkdir -p /app/runtime
34
 
48
 
35
 # Set up a volume for persistent data
49
 # Set up a volume for persistent data
36
 VOLUME /app/data
50
 VOLUME /app/data
@@ -39,4 +53,4 @@ VOLUME /app/data
39
 EXPOSE 21114
53
 EXPOSE 21114
40
 
54
 
41
 # Define the command to run the application
55
 # Define the command to run the application
42
-CMD ["app/apimain"]
56
+CMD ["./apimain"]

+ 5 - 2
docker-compose.yaml

@@ -3,17 +3,20 @@ services:
3
     build: 
3
     build: 
4
       context: .
4
       context: .
5
       dockerfile: Dockerfile.dev
5
       dockerfile: Dockerfile.dev
6
+      args:
7
+        - DOCS=""
6
     image: lejianwen/rustdesk-api
8
     image: lejianwen/rustdesk-api
7
     container_name: rustdesk-api
9
     container_name: rustdesk-api
8
     environment:
10
     environment:
9
       - TZ=Asia/Shanghai
11
       - TZ=Asia/Shanghai
10
       - RUSTDESK_API_RUSTDESK_ID_SERVER=192.168.1.66:21116
12
       - RUSTDESK_API_RUSTDESK_ID_SERVER=192.168.1.66:21116
11
       - RUSTDESK_API_RUSTDESK_RELAY_SERVER=192.168.1.66:21117
13
       - RUSTDESK_API_RUSTDESK_RELAY_SERVER=192.168.1.66:21117
12
-      - RUSTDESK_API_RUSTDESK_API_SERVER=http://192.168.1.66:21114
14
+      - RUSTDESK_API_RUSTDESK_API_SERVER=http://localhost:21114
13
       - RUSTDESK_API_RUSTDESK_KEY=123456789
15
       - RUSTDESK_API_RUSTDESK_KEY=123456789
14
     ports:
16
     ports:
15
       - 21114:21114
17
       - 21114:21114
16
     volumes:
18
     volumes:
17
       - ./data/rustdesk/api:/app/data #将数据库挂载出来方便备份
19
       - ./data/rustdesk/api:/app/data #将数据库挂载出来方便备份
20
+      # - ./conf:/app/conf # config
18
     restart: unless-stopped
21
     restart: unless-stopped
19
-    command: sleep infnite
22
+    # command: sleep infnite