forked from cloud-barista/cm-beetle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
95 lines (73 loc) · 3.24 KB
/
Dockerfile
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
##############################################################
## Stage 1 - Go Build
##############################################################
FROM golang:1.23.0-bookworm AS builder
ENV GO111MODULE=on
# Set the Current Working Directory inside the container
WORKDIR /go/src/github.com/cloud-barista/cm-beetle
# Copy dependency files to the container
COPY go.mod go.sum go.work go.work.sum LICENSE ./
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
go mod download
# Copy some necessary files to the container
COPY api ./api
COPY cmd/cm-beetle ./cmd/cm-beetle
COPY pkg ./pkg
COPY scripts ./scripts
# COPY conf ./conf
# Build the Go app
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
cd cmd/cm-beetle && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags '-s -w' -tags cm-beetle -v -o cm-beetle main.go
#############################################################
## Stage 2 - Application Setup
##############################################################
FROM ubuntu:22.04 AS prod
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
# Set the Current Working Directory inside the container
WORKDIR /app
# Installing necessary packages and cleaning up
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
## Copy the Pre-built binary and necessary files from the previous stage
COPY --from=builder /go/src/github.com/cloud-barista/cm-beetle/scripts/ /app/scripts/
COPY --from=builder /go/src/github.com/cloud-barista/cm-beetle/cmd/cm-beetle/cm-beetle /app/
COPY --from=builder /go/src/github.com/cloud-barista/cm-beetle/api/ /app/api/
# COPY --from=builder /go/src/github.com/cloud-barista/cm-beetle/conf/ /app/conf/
## Set environment variables
# Set system endpoints
ENV BEETLE_ROOT=/app
## Set SELF_ENDPOINT, to access Swagger API dashboard outside (Ex: export SELF_ENDPOINT=x.x.x.x:8056)
ENV BEETLE_SELF_ENDPOINT=localhost:8056
## Set API access config
# API_ALLOW_ORIGINS (ex: https://cloud-barista.org,xxx.xxx.xxx.xxx or * for all)
# Set ENABLE_AUTH=true currently for basic auth for all routes (i.e., url or path)
ENV BEETLE_API_ALLOW_ORIGINS=* \
BEETLE_API_AUTH_ENABLED=true \
BEETLE_API_USERNAME=default \
BEETLE_API_PASSWORD=default
## Set internal DB config (lkvstore: local key-value store, default file path: ./db/beetle.db)
ENV BEETLE_LKVSTORE_PATH=/app/db/beetle.db
## Logger configuration
# Set log file path (default logfile path: ./beetle.log)
# Set log level, such as trace, debug info, warn, error, fatal, and panic
ENV BEETLE_LOGFILE_PATH=/app/log/beetle.log \
BEETLE_LOGFILE_MAXSIZE=1000 \
BEETLE_LOGFILE_MAXBACKUPS=3 \
BEETLE_LOGFILE_MAXAGE=30 \
BEETLE_LOGFILE_COMPRESS=false \
BEETLE_LOGLEVEL=info \
BEETLE_LOGWRITER=both
# Set execution environment, such as development or production
ENV BEETLE_NODE_ENV=production
## Set period for auto control goroutine invocation
ENV BEETLE_AUTOCONTROL_DURATION_MS=10000
## Set Tumblebug access config
ENV BEETLE_TUMBLEBUG_REST_URL=http://localhost:1323 \
BEETLE_TUMBLEBUG_API_USERNAME=default \
BEETLE_TUMBLEBUG_API_PASSWORD=default
ENTRYPOINT [ "/app/cm-beetle" ]
EXPOSE 8056