This repository has been archived by the owner on Jan 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Dockerfile
64 lines (47 loc) · 2.28 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Use the official Golang image to create a build artifact.
# This is based on Debian and sets the GOPATH to /go.
# https://hub.docker.com/_/golang
FROM golang:1.18.5-alpine3.16 as builder-base
WORKDIR /go/src/github.com/keptn-contrib/helm-service
# Force the go compiler to use modules
ENV GO111MODULE=on
ENV BUILDFLAGS=""
ENV GOPROXY=https://proxy.golang.org
RUN apk add --no-cache gcc libc-dev git
# Copy `go.mod` for definitions and `go.sum` to invalidate the next layer
# in case of a change in the dependencies
COPY go.mod go.sum ./
# Download dependencies
RUN go mod download
# Copy local code to the container image.
COPY . .
FROM builder-base as builder-test
ENV GOTESTSUM_FORMAT=testname
RUN go install gotest.tools/gotestsum@v1.7.0
CMD gotestsum --no-color=false -- -race -coverprofile=coverage.txt -covermode=atomic -v ./... && mv ./coverage.txt /shared/coverage.txt
FROM builder-base as builder
# `skaffold debug` sets SKAFFOLD_GO_GCFLAGS to disable compiler optimizations
ARG SKAFFOLD_GO_GCFLAGS
# Build the command inside the container.
# (You may fetch or manage dependencies here, either manually or with a tool like "godep".)
RUN GOOS=linux go build -ldflags '-linkmode=external' -gcflags="${SKAFFOLD_GO_GCFLAGS}" -v -o helm-service
# Use a Docker multi-stage build to create a lean production image.
# https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds
FROM alpine:3.16 as production
ARG version=develop
LABEL org.opencontainers.image.source="https://github.com/keptn/keptn" \
org.opencontainers.image.url="https://keptn.sh" \
org.opencontainers.image.title="Keptn Helm Service" \
org.opencontainers.image.vendor="Keptn" \
org.opencontainers.image.documentation="https://keptn.sh/docs/" \
org.opencontainers.image.licenses="Apache-2.0" \
org.opencontainers.image.version="${version}"
# we need to install ca-certificates and libc6-compat for go programs to work properly
RUN apk add --no-cache ca-certificates libc6-compat
# Copy the binary to the production image from the builder stage.
COPY --from=builder /go/src/github.com/keptn-contrib/helm-service/helm-service /helm-service
EXPOSE 8080
# required for external tools to detect this as a go binary
ENV GOTRACEBACK=all
# Run the web service on container startup.
CMD ["/helm-service"]