1 回答
TA贡献2011条经验 获得超2个赞
对于将来可能遇到类似问题的任何人,以下是我为完成这项工作而采取的步骤。
我将生成的工件烘焙到基础 docker 映像中,例如:
FROM golang:1.13.4
COPY ./foo /go/src/foo/foo
COPY ./foo.mod /go/src/foo
这绕过了必须将.so文件提交到源代码控制,而不是简单地将 docker 映像推送到注册表。
任何需要此库的服务都是从该基础映像构建的:
FROM my-foo-base:latest
COPY ./vendor ./vendor
COPY ./go.mod ./
COPY ./go.sum ./
# Put foo in /vendor so it's discoverable, and put its libs where they
# can be discovered
RUN mv /go/src/foo ./vendor && \
mv ./vendor/foo/foo/libs/*.so /usr/lib/ && \
mv ./vendor/foo/foo/include/* /usr/include/
# Copy in app code
COPY ./my-app ./my-app
# Required so the app can find the _foo.so shared object
ENV LD_LIBRARY_PATH="/vendor/foo/foo:/usr/lib:${LD_LIBRARY_PATH}"
# Build into a single binary
RUN GOOS=linux \
GOARCH=amd64 \
CGO_ENABLED=1 \
GOFLAGS=-mod=vendor \
GO111MODULE=on \
go build \
-o service ./cmd/serve/main.go
这有效,并且该服务能够发现 CGO 包。
- 1 回答
- 0 关注
- 123 浏览
添加回答
举报