Dockerfile upgrade for multi target
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
52
Dockerfile
52
Dockerfile
@@ -1,46 +1,60 @@
|
||||
# -------------------- deps stage --------------------
|
||||
FROM golang:alpine AS deps
|
||||
|
||||
WORKDIR /app
|
||||
COPY go.mod go.sum ./
|
||||
RUN sed -i '/replace/d' go.mod
|
||||
RUN go mod download
|
||||
RUN sed -i '/replace/d' go.mod && \
|
||||
go mod download
|
||||
|
||||
#----------------------------------------------------------------------------------------------
|
||||
# -------------------- builder stage --------------------
|
||||
FROM --platform=$BUILDPLATFORM golang:alpine AS builder
|
||||
|
||||
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 ./
|
||||
|
||||
RUN export CGO_ENABLED=0 && \
|
||||
export GOOS=linux && \
|
||||
export GOARCH=amd64 && \
|
||||
export BUILD_FLAGS="-ldflags='-w -s'"
|
||||
|
||||
# copy the source code
|
||||
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
|
||||
#RUN sed -i 's/http:\/\/127.0.0.1:8080\/swagger\/swagger.json/swagger.json/g' /app/extracted/swagger/index.html
|
||||
|
||||
#----------------------------------------------------------------------------------------------
|
||||
# build
|
||||
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH CGO_ENABLED=0 bee pack
|
||||
|
||||
FROM golang:alpine
|
||||
# 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
|
||||
|
||||
WORKDIR /app
|
||||
COPY --from=builder /app/extracted/oc-discovery /usr/bin/
|
||||
#COPY --from=builder /app/extracted/swagger /app/swagger
|
||||
|
||||
# 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/docker_discovery.json /etc/oc/discovery.json
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
ENTRYPOINT ["oc-discovery"]
|
||||
# run
|
||||
ENTRYPOINT ["/usr/bin/oc-discovery"]
|
||||
|
||||
Reference in New Issue
Block a user