forked from cloud-barista/cb-spider
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDockerfile
More file actions
66 lines (44 loc) · 3.08 KB
/
Copy pathDockerfile
File metadata and controls
66 lines (44 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
##############################################################
## Stage 1 - Go Build
##############################################################
# Note: --platform=$BUILDPLATFORM runs the builder natively on the host (e.g., amd64),
# avoiding slow QEMU emulation. Cross-compilation is handled via TARGETOS/TARGETARCH.
FROM --platform=$BUILDPLATFORM golang:1.26.2 AS builder
ARG TARGETOS
ARG TARGETARCH
ENV GO111MODULE=on
# Install git for version information
RUN apt-get update -o Acquire::Retries=3 && apt-get install -y git && rm -rf /var/lib/apt/lists/*
ADD . /go/src/github.com/cloud-barista/cb-spider
WORKDIR /go/src/github.com/cloud-barista/cb-spider
# Note: Docker image provides static mode only (dynamic mode available in binary releases)
WORKDIR api-runtime
RUN VERSION=$(git describe --tags --abbrev=8 2>/dev/null | sed 's/-g.*//' || echo "unknown") && \
COMMIT_SHA=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown") && \
BUILD_TIME=$(date) && \
CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -tags cb-spider \
-ldflags="-X 'main.Version=${VERSION}' -X 'main.CommitSHA=${COMMIT_SHA}' -X 'main.BuildTime=${BUILD_TIME}'" \
-o cb-spider -v
#############################################################
## Stage 2 - Application Setup
##############################################################
FROM ubuntu:22.04 AS prod
# Note: Combine update and install in a single RUN to avoid stale package list from cached layers.
# --no-install-recommends: Skip unnecessary recommended packages to reduce image size.
# rm -rf /var/lib/apt/lists/*: Clean up apt cache (does not affect installed packages).
RUN apt-get update -o Acquire::Retries=3 && apt-get install -y --no-install-recommends ca-certificates curl && rm -rf /var/lib/apt/lists/*
# use bash
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
WORKDIR /root/go/src/github.com/cloud-barista/cb-spider
COPY --from=builder /go/src/github.com/cloud-barista/cb-spider/cloud-driver-libs/ /root/go/src/github.com/cloud-barista/cb-spider/cloud-driver-libs/
COPY --from=builder /go/src/github.com/cloud-barista/cb-spider/conf/ /root/go/src/github.com/cloud-barista/cb-spider/conf/
COPY --from=builder /go/src/github.com/cloud-barista/cb-spider/api-runtime/cb-spider /root/go/src/github.com/cloud-barista/cb-spider/api-runtime/
COPY --from=builder /go/src/github.com/cloud-barista/cb-spider/api-runtime/rest-runtime/admin-web/images/ /root/go/src/github.com/cloud-barista/cb-spider/api-runtime/rest-runtime/admin-web/images/
COPY --from=builder /go/src/github.com/cloud-barista/cb-spider/api-runtime/rest-runtime/admin-web/html/ /root/go/src/github.com/cloud-barista/cb-spider/api-runtime/rest-runtime/admin-web/html/
COPY --from=builder /go/src/github.com/cloud-barista/cb-spider/api/ /root/go/src/github.com/cloud-barista/cb-spider/api/
ENV CBSPIDER_ROOT=/root/go/src/github.com/cloud-barista/cb-spider
ENV CBLOG_ROOT=/root/go/src/github.com/cloud-barista/cb-spider
# Static mode only (dynamic mode available in binary releases)
ENV PLUGIN_SW=OFF
ENTRYPOINT [ "/root/go/src/github.com/cloud-barista/cb-spider/api-runtime/cb-spider" ]
EXPOSE 1024