# Copy whole project's contents(not entire folder) into .(/goapp/) and build Golang
FROM golang:1.17 as serverbuilder
ENV GO111MODULE=on \
    CGO_ENABLED=0 \
    GOOS=linux \
    GOPROXY=https://goproxy.cn,direct \
    GOARCH=amd64

WORKDIR /goapp

# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
COPY go.mod go.sum ./
RUN go mod download

# Build
COPY . ./
RUN go build -o ./bin/cicd-sample ./*.go

# Set the image's default run command
CMD ["/goapp/bin/cicd-sample"]
