1 回答

TA貢獻1863條經驗 獲得超2個贊
您的依賴項可能存儲在中GOPATH/src/<import-path>
,您可以使用go get
工具管理它們。
考慮供應商?和工具,如dep或模塊
因此,您的依賴項將包含在源代碼管理中,并且項目將更加可移植。
您還可以改進創建圖像的方式Docker
。
當前的實現使用一個包含整個GO
工具鏈的容器。代碼被復制到該容器內部,容器編譯并托管代碼。只有稍后才需要生產。
更好的選擇是使用 2 個容器:
Go 編譯工具
僅托管二進制文件的輕量級容器
# Debian image with the latest version of Go installed
# and a workspace (GOPATH) configured at /go.
FROM golang:1.11 as builder
WORKDIR /go/src/github.com/space/project/
# Copy the local package files to the container's workspace.
ADD . /go/src/github.com/space/project/
# Build the service inside the container.
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .
FROM centurylink/ca-certs
EXPOSE 8080
# Copy app
COPY --from=builder /go/src/github.com/space/project/app? ?/
ENTRYPOINT ["/app"]
- 1 回答
- 0 關注
- 172 瀏覽
添加回答
舉報