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
WORKDIR /app
COPY go.mod go.sum ./
RUN sed -i '/replace/d' go.mod && \
go mod download
RUN sed -i '/replace/d' go.mod
RUN 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
RUN apk add 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
RUN export CGO_ENABLED=0 && \
export GOOS=linux && \
export GOARCH=amd64 && \
export BUILD_FLAGS="-ldflags='-w -s'"
COPY . .
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
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
FROM golang:alpine
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/oc-discovery /usr/bin/
COPY --from=builder /app/extracted/swagger /app/swagger
COPY --from=builder /app/extracted/docker_discovery.json /etc/oc/discovery.json
EXPOSE 8080
# run
ENTRYPOINT ["/usr/bin/oc-discovery"]
ENTRYPOINT ["oc-discovery"]

View File

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