1 回答

TA貢獻(xiàn)1863條經(jīng)驗(yàn) 獲得超2個(gè)贊
您的依賴項(xiàng)可能存儲(chǔ)在中GOPATH/src/<import-path>
,您可以使用go get
工具管理它們。
考慮供應(yīng)商?和工具,如dep或模塊
因此,您的依賴項(xiàng)將包含在源代碼管理中,并且項(xiàng)目將更加可移植。
您還可以改進(jìn)創(chuàng)建圖像的方式Docker
。
當(dāng)前的實(shí)現(xiàn)使用一個(gè)包含整個(gè)GO
工具鏈的容器。代碼被復(fù)制到該容器內(nèi)部,容器編譯并托管代碼。只有稍后才需要生產(chǎn)。
更好的選擇是使用 2 個(gè)容器:
Go 編譯工具
僅托管二進(jìn)制文件的輕量級(jí)容器
# 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 關(guān)注
- 171 瀏覽
添加回答
舉報(bào)