github.com/tuingking/flamingo@v0.0.0-20220403134817-2796ae0e84ca/Dockerfile (about)

     1  # Use the official Golang image to create a build artifact.
     2  # This is based on Debian and sets the GOPATH to /go.
     3  # https://hub.docker.com/_/golang
     4  FROM golang:1.17.8 as builder
     5  
     6  # Create and change to the app directory.
     7  WORKDIR /app
     8  
     9  # Retrieve application dependencies using go modules.
    10  # Allows container builds to reuse downloaded dependencies.
    11  COPY go.* ./
    12  RUN go mod download
    13  
    14  # Copy local code to the container image.
    15  COPY . ./
    16  
    17  # Compile the binary
    18  # -mod=readonly ensures immutable go.mod and go.sum in container builds.
    19  RUN go get -v golang.org/x/tools/cmd/goimports
    20  RUN go mod download golang.org/x/net
    21  RUN go mod tidy
    22  RUN CGO_ENABLED=0 GOOS=linux go build -mod=readonly -v -o flamingo ./cmd/rest/main.go
    23  
    24  # Use the official Alpine image for a lean production container.
    25  # https://hub.docker.com/_/alpine
    26  # https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds
    27  FROM alpine:3
    28  RUN apk add --no-cache ca-certificates
    29  
    30  # Copy the binary to the production image from the builder stage.
    31  COPY --from=builder /app/flamingo /flamingo
    32  
    33  # Copy all necessary config files
    34  COPY --from=builder /app/config/config-docker.yaml /config/config.yaml
    35  
    36  # If using local database uncomment below
    37  # COPY --from=builder /app/config/config-sample.yaml /config/config-sample.yaml
    38  # RUN sed 's/host: "localhost"/host: "host.docker.internal"/g' /config/config-sample.yaml > /config/config.yaml
    39  
    40  # Copy web related files
    41  COPY --from=builder /app/web /web
    42  
    43  # Run the web service on container startup.
    44  CMD ["/flamingo"]