作者 陈志颖

chore:优化镜像打包

<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Docker for Mac" type="docker-deploy" factoryName="dockerfile" server-name="Docker for Mac">
<configuration default="false" name="Docker for Mac" type="docker-deploy" factoryName="dockerfile" server-name="Docker">
<deployment type="dockerfile">
<settings>
<option name="imageTag" value="" />
<option name="imageTag" value="latest" />
<option name="containerName" value="allied-creation-cooperation" />
<option name="envVars">
<list>
<DockerEnvVarImpl>
<option name="name" value="POSTGRESQL_HOST" />
<option name="value" value="192.168.100.27" />
</DockerEnvVarImpl>
</list>
</option>
<option name="portBindings">
<list>
<DockerPortBindingImpl>
<option name="containerPort" value="8082" />
<option name="hostPort" value="8082" />
</DockerPortBindingImpl>
</list>
</option>
<option name="sourceFilePath" value="Dockerfile" />
</settings>
</deployment>
... ...
FROM golang:latest
#FROM golang:latest
#MAINTAINER 陈志颖 <steve.d.chan@qq.com>
#ENV APP_DIR $GOPATH/src/allied-creation-cooperation
#RUN mkdir -p $APP_DIR
#WORKDIR $APP_DIR/
#COPY ./pkg pkg
#COPY ./config config
#COPY ./go.mod go.mod
#COPY ./go.sum go.sum
#COPY ./main.go main.go
#RUN ["ln","-sf","/usr/share/zoneinfo/Asia/Shanghai","/etc/localtime"]
#ENV GO111MODULE on
#ENV GOPROXY https://goproxy.io
#RUN ["go","mod","tidy"]
#RUN ["ls"]
#RUN ["go","build"]
#ENTRYPOINT ["./allied-creation-cooperation"]
#############################
## STEP 1 build executable binary
#############################
FROM golang:latest AS builder
MAINTAINER 陈志颖 <steve.d.chan@qq.com>
ENV APP_DIR $GOPATH/src/allied-creation-cooperation
RUN mkdir -p $APP_DIR
WORKDIR $APP_DIR/
COPY ./pkg pkg
COPY ./config config
COPY ./go.mod go.mod
COPY ./go.sum go.sum
COPY ./main.go main.go
RUN mkdir /app
WORKDIR /app
COPY . /app
RUN ["ln","-sf","/usr/share/zoneinfo/Asia/Shanghai","/etc/localtime"]
ENV GO111MODULE on
ENV GOPROXY https://goproxy.io
RUN ["go","mod","tidy"]
RUN ["ls"]
RUN ["go","build"]
ENTRYPOINT ["./allied-creation-cooperation"]
\ No newline at end of file
RUN GO111MODULE="on" GOPROXY="https://goproxy.cn" CGO_ENABLED=0 GOOS=linux go build -o allied-creation-cooperation
#############################
## STEP 2 build a small image
############################
FROM scratch as final
COPY --from=builder /app/allied-creation-cooperation /app/allied-creation-cooperation
ENTRYPOINT ["./app/allied-creation-cooperation"]
\ No newline at end of file
... ...