60 lines
1.4 KiB
Docker
60 lines
1.4 KiB
Docker
# -------------------- deps stage --------------------
|
|
FROM golang:alpine AS deps
|
|
|
|
WORKDIR /app
|
|
COPY go.mod go.sum ./
|
|
RUN sed -i '/replace/d' go.mod && \
|
|
go mod download
|
|
|
|
# -------------------- builder stage --------------------
|
|
FROM golang:alpine AS builder
|
|
|
|
# Buildx injects these
|
|
ARG TARGETOS
|
|
ARG TARGETARCH
|
|
|
|
# We want static binaries for scratch
|
|
ENV CGO_ENABLED=0
|
|
|
|
WORKDIR /app
|
|
|
|
# tools needed during build
|
|
RUN apk add --no-cache git
|
|
|
|
# install bee for the BUILD platform
|
|
RUN go install github.com/beego/bee/v2@latest
|
|
|
|
WORKDIR /oc-discovery
|
|
|
|
# reuse module cache from deps
|
|
COPY --from=deps /go/pkg /go/pkg
|
|
COPY --from=deps /app/go.mod /app/go.sum ./
|
|
|
|
# copy the source code
|
|
COPY . .
|
|
|
|
RUN sed -i '/replace/d' go.mod
|
|
|
|
# build
|
|
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH CGO_ENABLED=0 bee pack
|
|
|
|
# unpack bee's tarball
|
|
RUN mkdir -p /app/extracted && \
|
|
tar -zxvf oc-discovery.tar.gz -C /app/extracted
|
|
#&& \ sed -i 's#http://127.0.0.1:8080/swagger/swagger.json#swagger.json#g' /app/extracted/swagger/index.html
|
|
|
|
# -------------------- final image --------------------
|
|
FROM scratch
|
|
|
|
WORKDIR /app
|
|
|
|
# copy the binary & assets
|
|
COPY --from=builder /app/extracted/oc-discovery /usr/bin/oc-discovery
|
|
COPY --from=builder /app/extracted/swagger ./swagger
|
|
COPY --from=builder /app/extracted/docker_discovery.json /etc/oc/discovery.json
|
|
|
|
EXPOSE 8080
|
|
|
|
# run
|
|
ENTRYPOINT ["/usr/bin/oc-discovery"]
|