首页 > 其他分享 >Dockerfile - build zgrpc-go-professionals:client

Dockerfile - build zgrpc-go-professionals:client

时间:2024-05-13 11:52:41浏览次数:13  
标签:professionals PROTOC zgrpc protoc -- client go src

 

FROM --platform=$BUILDPLATFORM alpine as protoc
ARG BUILDPLATFORM=linux/amd64 TARGETOS=linux TARGETARCH=amd64

# download the protoc binary from github
# We unzip the file into /usr/local. Notice that we are extracting both the protoc
# binary (/bin/protoc) and the /include folder because the first one is the compiler that we are
# going to use and the second one is all the files needed to include Well-Known Types.
RUN export PROTOC_VERSION=26.1 \
    && export PROTOC_ARCH=$(uname -m | sed s/aarch64/aarch_64/) \
    && export PROTOC_OS=$(echo $TARGETOS | sed s/darwin/linux/) \
    && export PROTOC_ZIP=protoc-$PROTOC_VERSION-$PROTOC_OS-$PROTOC_ARCH.zip \
    && echo "downloading: " https://github.com/protocolbuffers/protobuf/releases/download/v$PROTOC_VERSION/$PROTOC_ZIP \
    && wget https://github.com/protocolbuffers/protobuf/releases/download/v$PROTOC_VERSION/$PROTOC_ZIP \
    && unzip -o $PROTOC_ZIP -d /usr/local bin/protoc 'include/*' \
    && rm -f $PROTOC_ZIP

FROM --platform=$BUILDPLATFORM golang:1.22-alpine as build
ARG BUILDPLATFORM=linux/amd64 TARGETOS=linux TARGETARCH=amd64

# copy the protoc binary and the protobuf includes
COPY --from=protoc /usr/local/bin/protoc /usr/local/bin/protoc
COPY --from=protoc /usr/local/include/google /usr/local/include/google

# download protoc plugins
RUN go env -w GOPROXY=https://goproxy.io,direct
RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
RUN go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
RUN go install github.com/envoyproxy/protoc-gen-validate@latest

# copy proto files into /go/src/proto
WORKDIR /go/src/proto
COPY ./proto .

# generate code out of proto files
WORKDIR /go
ENV MODULE=zgrpc-go-professionals
RUN protoc --proto_path=src/proto \
           --go_out=src \
           --go_opt=module=$MODULE \
           --go-grpc_out=src \
           --go-grpc_opt=module=$MODULE \
           --validate_out="lang=go,module=$MODULE:src" \
           src/proto/todo/v2/*.proto

           # copy code into /go/src/client
WORKDIR /go/src/client
COPY ./client .

# copy go.mod into go/src
WORKDIR /go/src
COPY go.mod .

# download dependencies and build
RUN go mod tidy
WORKDIR /go/src/client
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -ldflags="-s -w" -o /go/bin/client

# here we use an alpine image because if we were using a scratch image (like in the server image)
# we would not be able to pass SERVER_ADDR_ENV variable as command line arg.
# this make the image a bit bigger.
FROM alpine:latest
ARG SERVER_ADDR="dns:///10.244.1.6:50051"

# copy certs into /certs
COPY ./certs/ca_cert.pem ./certs/ca_cert.pem

# copy the previously built binary into smaller image
COPY --from=build /go/bin/client /
# Below CMDs are NOT OK.
# CMD ["/client", $SERVER_ADDR]
# CMD ["/client", "$SERVER_ADDR"]
# CMD ["/client", $(SERVER_ADDR)]
# CMD /client $SERVER_ADDR
# Below CMDs are OK.
# CMD ["/client", "10.244.1.2:50051"]
# CMD ["/client", "dns:///10.244.1.3:50051"]
ENV SERVER_ADDR_ENV=$SERVER_ADDR
CMD /client $SERVER_ADDR_ENV

 

The image is built successfully.

It runs well too.

标签:professionals,PROTOC,zgrpc,protoc,--,client,go,src
From: https://www.cnblogs.com/zhangzhihui/p/18188946

相关文章

  • Dockerfile - build zgrpc-go-professionals:server
     FROM--platform=$BUILDPLATFORMalpineasprotocARGBUILDPLATFORM=linux/amd64TARGETOS=linuxTARGETARCH=amd64#downloadtheprotocbinaryfromgithub#Weunzipthefileinto/usr/local.Noticethatweareextractingboththeprotoc#binary(/bin/pr......
  • ROS服务通讯创建服务节点(service)与客户端节点(client)
    学习参考:ROS/Tutorials/WritingServiceClient(python)-ROSWiki  首先需要一个工作空间,进入工作空间下的src文件夹下再创建一个功能包,进入功能包后创建scripts放置.py源码文件  服务节点源码创建格式:老样子还是剖析源码 首先导入包这里的_future_包中的print_func......
  • ZGRPC - A Unit Test Failure
     functestUpdateTasksUnavailableDb(t*testing.T){//Arrangeconn,c:=newClient(t)deferconn.Close()newDb:=NewFakeDb(IsAvailable(false))*fakeDb=*newDb//ClearallthefieldsinfakeDb.d.tasksexceptId.requests......
  • 原始翎风CLIENT8位 (11) fsata的学习
    本单元提供系统中的所有对话框显示MAINIMAGEFILE='Data\Prguse.wil';MAINIMAGEFILE2='Data\Prguse2.wil';MAINIMAGEFILE3='Data\Prguse3.wil';CHRSELIMAGEFILE='Data\ChrSel.wil';MINMAPIMAGEFILE='Data\mmap.wil......
  • 原始翎风CLIENT8位 (12) playscn的学习
    绘图关键的数据地图客户区,以主角的地图坐标为中心左右各9格,上下9,8格一切以主角为中心进行计算,换算。Map.m_ClientRectLeft:=g_MySelf.m_nRx-9;Top:=g_MySelf.m_nRy-9;Right:=g_MySelf.m_nRx+9;Bottom:=g_MySelf.m_nRy+8; 地图地面绘图m_MapSurface的像素大小......
  • 原始翎风CLIENT8位 (10) tscenc的学习
    IntroScn.pas嗟夫DELPHI输入法相关知识凡是窗口类都有TImeMode这是个集合其中包含有:TImeMode=(imDisable,imClose,imOpen,imDontCare,imSAlpha,imAlpha,imHira,imSKata,imKata,imChinese,imSHanguel,imHanguel);指定imDisable的话IME变得无效。既无法作使......
  • 原始翎风CLIENT8位 (13) actor的学习
    functionGetOffset(appr:integer):integer偏移大于1000退出nrace:=apprdiv10nrace0-90npos:=apprmod10npos0-9这个找的是怪物图片在文件中图片索引偏移量分为很多种,有偏移280,280是一个怪物的一组图片,例如MON1有偏移230,例如MON2有偏移360的,例如MON3appr应该......
  • 原始翎风CLIENT8位 (14) mapunit的学习
    8.MaxInt格式:constMaxInt=High(integer);说明:MaxInt常量代表Integer类型的最大可能值.MaxInt的真正的值会随着Delphi的版本不同而改变,目前它的值是21474836472g?地图好像是分块?40*40个地图坐标分为一个广场块一次读取是当前块的-1X/Y+2合计4*4块合计160*160个......
  • 原始翎风CLIENT8位 (8) CLUNIT的学习
    这个里面是绘图,有汇编,那个绘画效果的汇编看明白了,实际是先建立了一个颜色的转换索引表,颜色对应下标,数据是转换后的颜色在绘画效果中用函数功能找到混合表面的的指针,锁定它用汇编语言,将混合表面的每一个像素查找转换索引表,转换过去。因为用了MM0寄存器,这是个MMX的指令里面的,它是64......
  • 原始翎风CLIENT8位 (9) magieff的学习
    定义类型这里的魔法效果,是扔出去的魔法效果,魔法释放后的效果在施咒的动作的,如火球术的施咒效果图样是在自身的,却不在这里,由Actor单元里面实现有个m_nCurEffFrame,但是奇怪的是空间移动,是图样是在于自身这些效果,又是由本单元里面实现的。 TMagicType枚举开头mtmtReady准备?mt......