-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Dockerfile.dev
63 lines (47 loc) · 1.84 KB
/
Dockerfile.dev
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Use build arguments for Go version and architecture
ARG GO_VERSION=1.22
ARG BUILDARCH=amd64
# Stage 1: Builder Stage
# FROM golang:${GO_VERSION}-alpine AS builder
FROM crazymax/xgo:${GO_VERSION} AS builder
# Set up working directory
WORKDIR /app
# Step 1: Copy the source code
COPY . .
# use --mount=type=cache,target=/go/pkg/mod to cache the go mod
# Step 2: Download dependencies
RUN --mount=type=cache,target=/go/pkg/mod \
go mod tidy && go mod download
# Step 3: Build the Go application with CGO enabled and specified ldflags
RUN --mount=type=cache,target=/go/pkg/mod \
CGO_ENABLED=1 GOOS=linux go build -a \
-ldflags "-s -w --extldflags '-static -fpic'" \
-installsuffix cgo -o dashboard cmd/dashboard/main.go
# Stage 2: Create the final image
FROM alpine:latest
ARG COUNTRY
# Install required tools without caching index to minimize image size
RUN if [ "$COUNTRY" = "CN" ] ; then \
echo "It is in China, updating the repositories"; \
sed -i 's#https\?://dl-cdn.alpinelinux.org/alpine#https://mirrors.tuna.tsinghua.edu.cn/alpine#g' /etc/apk/repositories; \
fi && \
apk update && apk add --no-cache tzdata && \
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
echo 'Asia/Shanghai' >/etc/timezone && \
rm -rf /var/cache/apk/* && \
mkdir -p /dashboard/data
# Copy the entrypoint script and ensure it is executable
COPY ./script/entrypoint.sh /entrypoint.sh
# Set up the entrypoint script
RUN chmod +x /entrypoint.sh
WORKDIR /dashboard
# Copy the statically linked binary from the builder stage
COPY --from=builder /app/dashboard ./app
# Copy the configuration file and the resource directory
COPY ./script/config.yaml ./data/config.yaml
COPY ./resource ./resource
# Set up volume and expose ports
VOLUME ["/dashboard/data"]
EXPOSE 80 5555 443
# Define the entrypoint
ENTRYPOINT ["/entrypoint.sh"]