-
Notifications
You must be signed in to change notification settings - Fork 5
/
Dockerfile
61 lines (53 loc) · 2.11 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
#Copyright(C) 2023 Intel Corporation. All Rights Reserved.
ARG PACKAGES_TO_COVER="config\|keymanager\|transport\|service"
ARG VERSION=v0.0.0
FROM golang:1.22 AS builder
ARG VERSION
WORKDIR /app
COPY . .
RUN GITTAG=$(git describe --tags --abbrev=0 2>/dev/null); \
GITCOMMIT=$(git describe --always); \
VERSION=${VERSION:-v0.0.0}; \
BUILDDATE=$(TZ=UTC date +%Y-%m-%dT%H:%M:%S%z); \
cd cmd && env GOOS=linux CGO_CPPFLAGS="-D_FORTIFY_SOURCE=2" \
go build \
-buildmode=pie \
-ldflags "-linkmode=external -s -extldflags '-Wl,-z,relro,-z,now' -X intel/kbs/v1/version.BuildDate=${BUILDDATE} -X intel/kbs/v1/version.Version=${VERSION} -X intel/kbs/v1/version.GitHash=${GITCOMMIT}" \
-o kbs
FROM ubuntu:22.04 AS final
# Install ca-certificates package to get the system certificates
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates && \
rm -rf /var/lib/apt/lists/*
ARG USERNAME=kbs
ARG USER_UID=1000
ARG USER_GID=$USER_UID
RUN groupadd --gid $USER_GID $USERNAME \
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME
WORKDIR /
COPY --from=builder /app/cmd/kbs .
EXPOSE 9443
RUN chown $USER_UID:$USER_GID kbs
USER $USERNAME
ENTRYPOINT ["/kbs"]
CMD ["run"]
FROM builder AS tester
ARG VERSION
ARG GITCOMMIT
ARG PACKAGES_TO_COVER
WORKDIR /app
COPY . .
RUN --mount=type=cache,target=/root/.cache/go-build \
BUILDDATE=$(TZ=UTC date +%Y-%m-%dT%H:%M:%S%z); \
env CGO_CFLAGS_ALLOW="-f.*" GOEXPERIMENT=nocoverageredesign GOOS=linux GOSUMDB=off \
/usr/local/go/bin/go test ./... \
-coverpkg="${COVER_PACKAGES}" -coverprofile cover.out \
-ldflags "-X intel/kbs/cache/v1/version.BuildDate=${BUILDDATE} -X intel/kbs/cache/v1/version.Version=${VERSION} -X intel/kbs/cache/v1/version.GitHash=${GITCOMMIT}"
RUN /usr/local/go/bin/go tool cover -html=cover.out -o cover.html
FROM builder AS swagger
ARG VERSION
ARG GITCOMMIT
ARG PACKAGES_TO_COVER
WORKDIR /app
COPY . .
RUN wget https://github.com/go-swagger/go-swagger/releases/download/v0.30.0/swagger_linux_amd64 -O /usr/local/bin/swagger
RUN chmod +x /usr/local/bin/swagger