Solved the problem of generating swagger and minimal image (scratch)

This commit is contained in:
pb
2023-11-02 15:49:33 +01:00
parent afae00fe62
commit 67d36b533f
5 changed files with 40 additions and 71 deletions

View File

@@ -1,61 +1,27 @@
FROM golang as builder
FROM golang:alpine as builder
LABEL maintainer="Valentin KIVACHUK BURDA"
WORKDIR /app
ENV DOCKER_ENVIRONMENT=true
ENV CGO_ENABLED=0
ENV GOOS=linux
ENV GO111MODULE=on
EXPOSE 49618
WORKDIR /go/src/oc-catalog
#######################################################
COPY go.mod .
COPY go.sum .
COPY . .
RUN go get github.com/beego/bee/v2 && go install github.com/beego/bee/v2@master
# Manually download swagger during build
RUN ["/bin/bash", "-c", \
"set -eo pipefail; \
mkdir -p swagger; \
curl -sL https://github.com/beego/swagger/archive/v3.tar.gz | tar xvvvz --overwrite -C swagger --strip-components=1"]
# Generating the swagger
RUN timeout 20 bee run -gendoc=true -downdoc=true -runmode=dev || :
RUN sed -i 's/http:\/\/127.0.0.1:8080\/swagger\/swagger.json/swagger.json/g' swagger/index.html
RUN sed -i 's/https:\/\/petstore.swagger.io\/v2\/swagger.json/swagger.json/g' swagger/index.html
RUN go mod download -x
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" .
# COPY . .
COPY main.go go.mod go.sum ./
FROM scratch
COPY controllers controllers
COPY models models
COPY routers routers
COPY selfapi selfapi
COPY services services
COPY conf conf
COPY scripts scripts
WORKDIR /app
# RUN go build -a -tags netgo -ldflags '-w -extldflags "-static"' -installsuffix cgo .
COPY ./docker_catalog.json /etc/oc/catalog.json
COPY --from=builder /app/oc-catalog /usr/bin/
COPY --from=builder /app/swagger /app/swagger
RUN bee generate docs
EXPOSE 8080
# COPY . .
# FROM golang
# WORKDIR /go/src/oc-catalog
# COPY --from=builder /go/src/oc-catalog .
ENV DOCKER_ENVIRONMENT=true
RUN go build .
# UglyFix: Generate comments from swagger
RUN timeout 10 bee run -runargs test || exit 0
CMD [ "bee", "run", "-gendoc=true" ]
ENTRYPOINT ["oc-catalog"]