AlphaWong / go-test-multi-stage-build

Go multi stage build practice
Mozilla Public License 2.0
11 stars 2 forks source link

PI version #1

Open AlphaWong opened 6 years ago

AlphaWong commented 6 years ago
# Start by building the application.
FROM golang:1.9 as build

# RUN apk add --no-cache git build-base && \
#    echo "http://dl-cdn.alpinelinux.org/alpine/edge/main" >> /etc/apk/repositories && \
#    echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories && \
#    echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories && \
#    apk add --no-cache upx

# RUN apt-get update && apt-get install -y --no-install-recommends \
#        upx

WORKDIR /go/src/git.easygroup.co/api-training-tools

COPY . .

RUN go get -u github.com/golang/dep/cmd/dep && dep ensure -v -vendor-only

RUN  CGO_ENABLE=0 GOOS=linux go build \
 -tags netgo \
 -installsuffix netgo,cgo \
 -v -a \
 -ldflags '-s -w -extldflags "-static"' \
 -o app

# RUN upx --best -qq app && upx -t app

# FROM gcr.io/distroless/base

FROM arm32v7/golang

WORKDIR /go/src/git.easygroup.co/api-training-tools

COPY --from=build /go/src/git.easygroup.co/api-training-tools .

ENTRYPOINT ["./app"]
EXPOSE 8080
AlphaWong commented 6 years ago
# Start by building the application.
FROM golang:alpine as build

RUN apk add --no-cache git build-base && \
    echo "http://dl-cdn.alpinelinux.org/alpine/edge/main" >> /etc/apk/repositories && \
    echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories && \
    echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories && \
    apk add --no-cache upx

# RUN apt-get update && apt-get install -y --no-install-recommends \
#        upx

WORKDIR /go/src/git.easygroup.co/api-training-tools

COPY . .

RUN go get -u github.com/golang/dep/cmd/dep && dep ensure -v -vendor-only

RUN  CGO_ENABLE=0 GOOS=linux go build \
 -tags netgo \
 -installsuffix netgo,cgo \
 -v -a \
 -ldflags '-s -w -extldflags "-static"' \
 -o app

# RUN upx --best -qq app && upx -t app

# FROM gcr.io/distroless/base

FROM golang:alpine

WORKDIR /go/src/git.easygroup.co/api-training-tools

COPY --from=build /go/src/git.easygroup.co/api-training-tools .

ENTRYPOINT ["./app"]
EXPOSE 8080
AlphaWong commented 6 years ago
# Start by building the application.
FROM golang:1 as build

RUN apt-get update && apt-get install -y --no-install-recommends upx

WORKDIR /go/src/git.easygroup.co/api-training-tools

COPY . .

RUN go get -u github.com/golang/dep/cmd/dep && dep ensure -v -vendor-only

RUN  CGO_ENABLE=0 GOOS=linux go build \
 -tags netgo \
 -installsuffix netgo,cgo \
 -v -a \
 -ldflags '-s -w -extldflags "-static"' \
 -o app

# RUN upx --best -qq app && upx -t app

# FROM gcr.io/distroless/base

FROM golang:alpine

WORKDIR /go/src/git.easygroup.co/api-training-tools

COPY --from=build /go/src/git.easygroup.co/api-training-tools .

ENTRYPOINT ["./app"]
EXPOSE 8080