Dockerfile 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # FROM golang:1.21.3-alpine3.18 as builder
  2. # ENV GOPROXY https://goproxy.cn/
  3. # WORKDIR /go/release
  4. # COPY go.mod ./go.mod
  5. # RUN go mod tidy
  6. # COPY . .
  7. # RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-w -s" -a -installsuffix cgo -o observe .
  8. FROM reg.cestong.com.cn/cecf/golang:1.23.1-alpine3.20 AS builder
  9. WORKDIR /src
  10. COPY . .
  11. ENV GOPROXY=https://goproxy.cn/
  12. RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories && \
  13. apk add --no-cache make && \
  14. apk add --no-cache git
  15. # RUN --mount=type=cache,target=/go/pkg/mod/ make build
  16. RUN --mount=type=cache,target=/go/pkg/mod/ make build
  17. FROM reg.cestong.com.cn/cecf/alpine:3.20
  18. # RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
  19. # RUN apk add --no-cache tzdata
  20. # ENV TZ=Asia/Shanghai
  21. COPY --from=builder /src/bin/observe /app/observe
  22. COPY --from=builder /src/config/settings.yml /app/settings.yml
  23. COPY --from=builder /src/version /app/version
  24. # COPY bin/observe /app/observe
  25. # COPY ./config/settings.yml /app/settings.yml
  26. # COPY ./version /app/version
  27. EXPOSE 8000
  28. # RUN chmod +x /app/observe # 这条命令会将镜像大小翻倍,copy过来时就是可执行的,不需要多此一举
  29. CMD ["/app/observe","server","-c", "/app/settings.yml"]
  30. # FROM golang:1.19.3
  31. # ENV GOPROXY https://goproxy.cn/
  32. # RUN apt install apt-transport-https ca-certificates
  33. # RUN apt-get update && apt-get install -yq tzdata vim iputils-ping net-tools telnet iotop
  34. # ENV TZ="Asia/Shanghai"
  35. # RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ >/etc/timezone
  36. # RUN dpkg-reconfigure -f noninteractive tzdata
  37. # RUN mkdir -p /app
  38. # COPY bin/observe /app/observe
  39. # COPY ./config /app/config
  40. # COPY ./version /app/version
  41. # EXPOSE 8000
  42. # RUN chmod +x /app/observe
  43. # CMD ["/app/observe","server","-c", "/app/settings.yml"]