go plugins 容器构建

前边有简单介绍过go plugin 的开发,以下是关于容器集成的说明

参考代码

https://github.com/rongfengliang/go-plugin-basic-learning

参考Dockerfile

FROM golang:1.15-alpine AS build-env-plugin
WORKDIR /go/src/app
ENV  GO111MODULE=on
ENV  GOPROXY=https://goproxy.cn
COPY . .
RUN set -x \
    && /bin/sed -i 's,http://dl-cdn.alpinelinux.org,https://mirrors.aliyun.com,g' /etc/apk/repositories \
    && apk update && apk add  build-base \
    && go build -buildmode=plugin -o demoapp.so app.go
FROM golang:1.15-alpine AS build-env
WORKDIR /go/src/app
ENV  GO111MODULE=on
ENV  GOPROXY=https://goproxy.cn
COPY . .
RUN set -x \
    && /bin/sed -i 's,http://dl-cdn.alpinelinux.org,https://mirrors.aliyun.com,g' /etc/apk/repositories \
    && apk update && apk add   build-base\
    && go build
FROM alpine:latest
RUN set -x \
    && /bin/sed -i 's,http://dl-cdn.alpinelinux.org,https://mirrors.aliyun.com,g' /etc/apk/repositories \
    && apk update && apk add ca-certificates && rm -rf /var/cache/apk/*
COPY --from=build-env-plugin /go/src/app/demoapp.so .
COPY --from=build-env /go/src/app/demoapp .
ENTRYPOINT [ "./demoapp" ]

构建

docker build -t dalongrong/go-plugin-demo .

运行效果

 

 

说明

以上需要使用gcc,同时使用了alpine 作为容器镜像,所以直接安装 build-base 就可以,同时使用了多阶段构建
同时需要注意golang 版本的一直

参考资料

https://github.com/rongfengliang/go-plugin-basic-learning

posted on 2020-12-28 20:48  荣锋亮  阅读(189)  评论(0编辑  收藏  举报

导航