standardize Deployment

This commit is contained in:
mr
2026-02-03 15:31:06 +01:00
parent 1c2ea9ca96
commit 7b68a608dd
2 changed files with 27 additions and 37 deletions

View File

@@ -1,59 +1,45 @@
# -------------------- deps stage --------------------
FROM golang:alpine AS deps FROM golang:alpine AS deps
WORKDIR /app WORKDIR /app
COPY go.mod go.sum ./ COPY go.mod go.sum ./
RUN sed -i '/replace/d' go.mod && \ RUN sed -i '/replace/d' go.mod
go mod download RUN go mod download
#----------------------------------------------------------------------------------------------
# -------------------- builder stage --------------------
FROM golang:alpine AS builder FROM golang:alpine AS builder
# Buildx injects these WORKDIR /app
ARG TARGETOS
ARG TARGETARCH
# We want static binaries for scratch RUN apk add git
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 RUN go install github.com/beego/bee/v2@latest
WORKDIR /oc-discovery WORKDIR /oc-discovery
# reuse module cache from deps
COPY --from=deps /go/pkg /go/pkg COPY --from=deps /go/pkg /go/pkg
COPY --from=deps /app/go.mod /app/go.sum ./ COPY --from=deps /app/go.mod /app/go.sum ./
# copy the source code RUN export CGO_ENABLED=0 && \
export GOOS=linux && \
export GOARCH=amd64 && \
export BUILD_FLAGS="-ldflags='-w -s'"
COPY . . COPY . .
RUN sed -i '/replace/d' go.mod RUN sed -i '/replace/d' go.mod
RUN bee pack
RUN mkdir -p /app/extracted && tar -zxvf oc-discovery.tar.gz -C /app/extracted
# build #----------------------------------------------------------------------------------------------
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH CGO_ENABLED=0 bee pack
# unpack bee's tarball FROM golang:alpine
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 WORKDIR /app
COPY --from=builder /app/extracted/oc-discovery /usr/bin/
# copy the binary & assets COPY --from=builder /app/extracted/swagger /app/swagger
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 COPY --from=builder /app/extracted/docker_discovery.json /etc/oc/discovery.json
EXPOSE 8080 EXPOSE 8080
# run ENTRYPOINT ["oc-discovery"]
ENTRYPOINT ["/usr/bin/oc-discovery"]

View File

@@ -1,10 +1,14 @@
version: '3.4' version: '3.4'
services: services:
ocdiscovery: oc-schedulerd:
image: 'opencloudregistry/oc-discovery' image: 'oc-discovery:latest'
ports: ports:
- 8088:8080 - 9002:8080
container_name: ocdiscovery container_name: oc-discovery
networks:
- oc
networks:
oc:
external: true