|
|
@@ -12,17 +12,19 @@ WORKDIR /app
|
|
12
|
12
|
# Step 1: Copy the source code
|
|
13
|
13
|
COPY . .
|
|
14
|
14
|
|
|
|
15
|
+# use --mount=type=cache,target=/go/pkg/mod to cache the go mod
|
|
15
|
16
|
# Step 2: Download dependencies
|
|
16
|
|
-RUN go mod tidy && go mod download
|
|
|
17
|
+RUN --mount=type=cache,target=/go/pkg/mod \
|
|
|
18
|
+ go mod tidy && go mod download && go install github.com/swaggo/swag/cmd/swag@latest
|
|
17
|
19
|
|
|
18
|
|
-
|
|
19
|
|
-# Step 3: Install swag and Run the build script
|
|
20
|
|
-RUN go install github.com/swaggo/swag/cmd/swag@latest && \
|
|
|
20
|
+# Step 3: Run swag build script
|
|
|
21
|
+RUN --mount=type=cache,target=/go/pkg/mod \
|
|
21
|
22
|
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
|
+ swag init -g cmd/apimain.go --output docs/admin --instanceName admin --exclude http/controller/api
|
|
23
|
24
|
|
|
24
|
|
-# Build the Go application with CGO enabled and specified ldflags
|
|
25
|
|
-RUN CGO_ENABLED=1 GOOS=linux go build -a \
|
|
|
25
|
+# Step 4: Build the Go application with CGO enabled and specified ldflags
|
|
|
26
|
+RUN --mount=type=cache,target=/go/pkg/mod \
|
|
|
27
|
+ CGO_ENABLED=1 GOOS=linux go build -a \
|
|
26
|
28
|
-ldflags "-s -w --extldflags '-static -fpic'" \
|
|
27
|
29
|
-installsuffix cgo -o release/apimain cmd/apimain.go
|
|
28
|
30
|
|
|
|
@@ -43,8 +45,13 @@ RUN if [ "$COUNTRY" = "CN" ] ; then \
|
|
43
|
45
|
# Clone the frontend repository
|
|
44
|
46
|
RUN git clone https://github.com/lejianwen/rustdesk-api-web .
|
|
45
|
47
|
|
|
46
|
|
-# Install npm dependencies and build the frontend
|
|
47
|
|
-RUN npm install && npm run build
|
|
|
48
|
+# Install required tools without caching index to minimize image size
|
|
|
49
|
+RUN if [ "$COUNTRY" = "CN" ] ; then \
|
|
|
50
|
+ echo "It is in China, updating NPM_CONFIG_REGISTRY"; \
|
|
|
51
|
+ export NPM_CONFIG_REGISTRY="https://mirrors.huaweicloud.com/repository/npm/"; \
|
|
|
52
|
+ fi && \
|
|
|
53
|
+ npm install && npm run build
|
|
|
54
|
+
|
|
48
|
55
|
|
|
49
|
56
|
# Stage 2: Final Image
|
|
50
|
57
|
FROM alpine:latest
|