diff --git a/Dockerfile b/Dockerfile index 01c264d..d1c8211 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 +WORKDIR /app -# We want static binaries for scratch -ENV CGO_ENABLED=0 +RUN apk add git -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 +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"] diff --git a/docker-compose.yml b/docker-compose.yml index 791661b..6b38646 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 - \ No newline at end of file +networks: + oc: + external: true \ No newline at end of file