Files
oc-discovery/Dockerfile

61 lines
1.4 KiB
Docker
Raw Normal View History

2025-11-12 09:14:13 +01:00
# -------------------- deps stage --------------------
2025-01-15 16:32:12 +01:00
FROM golang:alpine AS deps
2023-03-09 11:45:29 +01:00
2025-01-15 16:32:12 +01:00
WORKDIR /app
COPY go.mod go.sum ./
2025-11-12 09:14:13 +01:00
RUN sed -i '/replace/d' go.mod && \
go mod download
# -------------------- builder stage --------------------
2025-11-12 10:11:09 +01:00
FROM golang:alpine AS builder
2023-03-09 11:45:29 +01:00
2025-11-12 09:14:13 +01:00
# Buildx injects these
ARG TARGETOS
ARG TARGETARCH
2025-01-15 16:32:12 +01:00
2025-11-12 09:14:13 +01:00
# We want static binaries for scratch
ENV CGO_ENABLED=0
2025-01-15 16:32:12 +01:00
2025-11-12 09:14:13 +01:00
WORKDIR /app
2023-03-09 11:45:29 +01:00
2025-11-12 09:14:13 +01:00
# tools needed during build
RUN apk add --no-cache git
2023-03-09 11:45:29 +01:00
2025-11-12 09:14:13 +01:00
# install bee for the BUILD platform
2025-01-15 16:32:12 +01:00
RUN go install github.com/beego/bee/v2@latest
2023-10-18 15:24:57 +02:00
2025-01-15 16:32:12 +01:00
WORKDIR /oc-discovery
2023-10-18 15:24:57 +02:00
2025-11-12 09:14:13 +01:00
# reuse module cache from deps
2025-01-15 16:32:12 +01:00
COPY --from=deps /go/pkg /go/pkg
COPY --from=deps /app/go.mod /app/go.sum ./
2023-10-18 15:24:57 +02:00
2025-11-12 09:14:13 +01:00
# copy the source code
2025-01-15 16:32:12 +01:00
COPY . .
2023-03-09 11:45:29 +01:00
2025-01-15 16:32:12 +01:00
RUN sed -i '/replace/d' go.mod
2023-03-09 11:45:29 +01:00
2025-11-12 09:14:13 +01:00
# 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
2023-03-09 11:45:29 +01:00
2025-11-12 09:14:13 +01:00
# -------------------- final image --------------------
FROM scratch
2025-01-15 16:32:12 +01:00
WORKDIR /app
2025-11-12 09:14:13 +01:00
# copy the binary & assets
COPY --from=builder /app/extracted/oc-discovery /usr/bin/oc-discovery
COPY --from=builder /app/extracted/swagger ./swagger
2025-01-15 16:32:12 +01:00
COPY --from=builder /app/extracted/docker_discovery.json /etc/oc/discovery.json
2023-03-09 11:45:29 +01:00
EXPOSE 8080
2025-11-12 09:14:13 +01:00
# run
ENTRYPOINT ["/usr/bin/oc-discovery"]