From adb5636ac6a9fbb06cc1b23efad166568e18a2ed Mon Sep 17 00:00:00 2001 From: Yunkon Kim Date: Fri, 6 Sep 2024 19:08:28 +0900 Subject: [PATCH] Enhance to run Beetle server * Update to be preparing and running Beetle server * Update Dockerfile and docker-compose.yaml * Copy cloud_conf.yaml, which is required to run the Tumblebug container --- Dockerfile | 45 ++- Makefile | 8 +- cmd/cm-beetle/main.go | 78 +++-- .../cb-tumblebug/conf/cloud_conf.yaml | 96 ++++++ .../docker-compose/docker-compose.yaml | 280 +++++++++--------- pkg/api/rest/server.go | 19 +- 6 files changed, 305 insertions(+), 221 deletions(-) create mode 100644 deployments/docker-compose/cb-tumblebug/conf/cloud_conf.yaml diff --git a/Dockerfile b/Dockerfile index 9a9fcdd..2000308 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,9 +18,9 @@ RUN --mount=type=cache,target=/go/pkg/mod \ # Copy some necessary files to the container COPY api ./api COPY cmd/cm-beetle ./cmd/cm-beetle -COPY conf ./conf COPY pkg ./pkg COPY scripts ./scripts +# COPY conf ./conf # Build the Go app RUN --mount=type=cache,target=/go/pkg/mod \ @@ -46,17 +46,27 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ ## 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/conf/ /app/conf/ 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 \ - BEETLE_CBSTORE_ROOT=/app \ - BEETLE_CBLOG_ROOT=/app +ENV BEETLE_ROOT=/app -ENV BEETLE_TUMBLEBUG_REST_URL=http://localhost:1323/tumblebug +## 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) @@ -66,30 +76,19 @@ ENV BEETLE_LOGFILE_PATH=/app/log/beetle.log \ BEETLE_LOGFILE_MAXBACKUPS=3 \ BEETLE_LOGFILE_MAXAGE=30 \ BEETLE_LOGFILE_COMPRESS=false \ - BEETLE_LOGLEVEL=info + BEETLE_LOGLEVEL=info \ + BEETLE_LOGWRITER=both # Set execution environment, such as development or production ENV BEETLE_NODE_ENV=production -## Set internal DB config (SQLlite) -ENV BEETLE_SQLITE_URL=localhost:3306 \ - BEETLE_SQLITE_DATABASE=cm_beetle \ - BEETLE_SQLITE_USER=cm_beetle \ - BEETLE_SQLITE_PASSWORD=cm_beetle - -## 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 period for auto control goroutine invocation ENV BEETLE_AUTOCONTROL_DURATION_MS=10000 -## 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 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" ] diff --git a/Makefile b/Makefile index 27b7391..cdbff28 100644 --- a/Makefile +++ b/Makefile @@ -80,14 +80,14 @@ clean: ## Remove previous build @cd cmd/$(MODULE_NAME) && $(GO) clean @echo "Cleaned!" +compose: swag ## Build and up services by docker compose + @echo "Building and starting services by docker compose..." + @cd deployments/docker-compose && DOCKER_BUILDKIT=1 docker compose up --build + compose-up: ## Up services by docker compose @echo "Starting services by docker compose..." @cd deployments/docker-compose && docker compose up -compose-build-up: swag ## Build and up services by docker compose - @echo "Building and starting services by docker compose..." - @cd deployments/docker-compose && DOCKER_BUILDKIT=1 docker compose up --build - compose-down: ## Down services by docker compose @echo "Removing services by docker compose..." @cd deployments/docker-compose && docker compose down diff --git a/cmd/cm-beetle/main.go b/cmd/cm-beetle/main.go index dd8661a..c25c9d7 100644 --- a/cmd/cm-beetle/main.go +++ b/cmd/cm-beetle/main.go @@ -16,12 +16,12 @@ package main import ( "flag" - "os" "strconv" "sync" "time" "github.com/cloud-barista/cm-beetle/pkg/config" + "github.com/cloud-barista/cm-beetle/pkg/lkvstore" "github.com/cloud-barista/cm-beetle/pkg/logger" "github.com/go-resty/resty/v2" "github.com/rs/zerolog/log" @@ -52,22 +52,27 @@ func init() { // Initialize the logger logger := logger.NewLogger(logger.Config{ - LogLevel: viper.GetString("beetle.loglevel"), - LogWriter: viper.GetString("beetle.logwriter"), - LogFilePath: viper.GetString("beetle.logfile.path"), - MaxSize: viper.GetInt("beetle.logfile.maxsize"), - MaxBackups: viper.GetInt("beetle.logfile.maxbackups"), - MaxAge: viper.GetInt("beetle.logfile.maxage"), - Compress: viper.GetBool("beetle.logfile.compress"), + LogLevel: config.Beetle.LogLevel, + LogWriter: config.Beetle.LogWriter, + LogFilePath: config.Beetle.LogFile.Path, + MaxSize: config.Beetle.LogFile.MaxSize, + MaxBackups: config.Beetle.LogFile.MaxBackups, + MaxAge: config.Beetle.LogFile.MaxAge, + Compress: config.Beetle.LogFile.Compress, }) // Set the global logger log.Logger = *logger + // Initialize the local key-value store with the specified file path + dbFilePath := config.Beetle.LKVStore.Path + lkvstore.Init(lkvstore.Config{ + DbFilePath: dbFilePath, + }) + // Check Tumblebug readiness - tumblebugEp := viper.GetString("beetle.tumblebug.endpoint") - url := tumblebugEp + "/tumblebug/readyz" - isReady, err := checkReadiness(url) + apiUrl := config.Tumblebug.RestUrl + "/readyz" + isReady, err := checkReadiness(apiUrl) if err != nil || !isReady { log.Fatal().Err(err).Msg("Tumblebug is not ready. Exiting...") @@ -139,7 +144,24 @@ func checkReadiness(url string) (bool, error) { func main() { - log.Info().Msg("CM-Beetle server is starting...") + log.Info().Msg("preparing to run CM-Beetle server...") + + // Load the state from the file back into the key-value store + if err := lkvstore.LoadLkvStore(); err != nil { + log.Error().Err(err).Msgf("error loading data from the lkvstore (file).") + } + + log.Info().Msg("successfully load data from the lkvstore (file).") + + defer func() { + // Save the current state of the key-value store to file + if err := lkvstore.SaveLkvStore(); err != nil { + log.Error().Err(err).Msgf("error saving data to the lkvstore (file).") + } + log.Info().Msg("successfully save data to the lkvstore (file).") + }() + + log.Info().Msg("Setting CM-Beetle REST API server...") // Set the default port number "8056" for the REST API server to listen on port := flag.String("port", "8056", "port number for the restapiserver to listen to") @@ -151,33 +173,6 @@ func main() { } log.Debug().Msgf("port number: %s", *port) - // common.SpiderRestUrl = common.NVL(os.Getenv("BEETLE_SPIDER_REST_URL"), "http://localhost:1024/spider") - // common.DragonflyRestUrl = common.NVL(os.Getenv("BEETLE_DRAGONFLY_REST_URL"), "http://localhost:9090/dragonfly") - common.TumblebugRestUrl = common.NVL(os.Getenv("BEETLE_TUMBLEBUG_ENDPOINT"), "http://localhost:1323") + "/tumblebug" - common.DBUrl = common.NVL(os.Getenv("BEETLE_SQLITE_URL"), "localhost:3306") - common.DBDatabase = common.NVL(os.Getenv("BEETLE_SQLITE_DATABASE"), "cm_beetle") - common.DBUser = common.NVL(os.Getenv("BEETLE_SQLITE_USER"), "cm_beetle") - common.DBPassword = common.NVL(os.Getenv("BEETLE_SQLITE_PASSWORD"), "cm_beetle") - common.AutocontrolDurationMs = common.NVL(os.Getenv("BEETLE_AUTOCONTROL_DURATION_MS"), "10000") - - // load the latest configuration from DB (if exist) - // fmt.Println("") - // fmt.Println("[Update system environment]") - // common.UpdateGlobalVariable(common.StrDragonflyRestUrl) - // common.UpdateGlobalVariable(common.StrSpiderRestUrl) - // common.UpdateGlobalVariable(common.StrAutocontrolDurationMs) - - // load config - //masterConfigInfos = confighandler.GetMasterConfigInfos() - - //Setup database (meta_db/dat/cmbeetle.s3db) - log.Info().Msg("setting SQL Database") - err := os.MkdirAll("./meta_db/dat/", os.ModePerm) - if err != nil { - log.Error().Err(err).Msg("error creating directory") - } - log.Debug().Msgf("database file path: %s", "./meta_db/dat/cmbeetle.s3db") - // Watch config file changes go func() { viper.WatchConfig() @@ -187,10 +182,13 @@ func main() { if err != nil { // Handle errors reading the config file log.Fatal().Err(err).Msg("fatal error in config file") } - err = viper.Unmarshal(&common.RuntimeConf) + err = viper.Unmarshal(&config.RuntimeConfig) if err != nil { log.Panic().Err(err).Msg("error unmarshaling runtime configuration") } + config.Beetle = config.RuntimeConfig.Beetle + config.Beetle.Tumblebug.RestUrl = config.Beetle.Tumblebug.Endpoint + "/tumblebug" + config.Tumblebug = config.Beetle.Tumblebug }) }() diff --git a/deployments/docker-compose/cb-tumblebug/conf/cloud_conf.yaml b/deployments/docker-compose/cb-tumblebug/conf/cloud_conf.yaml new file mode 100644 index 0000000..44e76c8 --- /dev/null +++ b/deployments/docker-compose/cb-tumblebug/conf/cloud_conf.yaml @@ -0,0 +1,96 @@ +cloud: + common: + enable: "y" + nlb: + enable: "y" + interval: "10" + timeout: "9" + threshold: "3" + k8scluster: + enable: "y" + aws: + enable: "y" + nlb: + enable: "y" + interval: "10" + timeout: "-1" + threshold: "3" + k8scluster: + enable: "n" + azure: + enable: "y" + nlb: + enable: "y" + interval: "10" + timeout: "9" + threshold: "3" + k8scluster: + enable: "y" + gcp: + enable: "y" + nlb: + enable: "y" + interval: "10" + timeout: "9" + threshold: "3" + k8scluster: + enable: "n" + alibaba: + enable: "y" + nlb: + enable: "y" + interval: "10" + timeout: "9" + threshold: "3" + k8scluster: + enable: "y" + tencent: + enable: "y" + nlb: + enable: "y" + interval: "10" + timeout: "9" + threshold: "3" + k8scluster: + enable: "y" + ibm: + enable: "y" + nlb: + enable: "y" + interval: "10" + timeout: "9" + threshold: "3" + k8scluster: + enable: "n" + nhncloud: + enable: "y" + k8scluster: + enable: "y" + openstack: + enable: "y" + nlb: + enable: "n" + interval: "10" + timeout: "9" + threshold: "3" + k8scluster: + enable: "n" + cloudit : + enable: "y" + nlb: + enable: "n" + interval: "10" + timeout: "9" + threshold: "3" + k8scluster: + enable: "n" +nlbsw: + sw: "HAProxy" + version: "latest" + commandNlbPrepare: "wget https://raw.githubusercontent.com/cloud-barista/cb-tumblebug/main/scripts/nlb/deployNlb.sh; wget https://raw.githubusercontent.com/cloud-barista/cb-tumblebug/main/scripts/nlb/addTargetNode.sh; wget https://raw.githubusercontent.com/cloud-barista/cb-tumblebug/main/scripts/nlb/applyConfig.sh; chmod +x ~/deployNlb.sh ~/addTargetNode.sh ~/applyConfig.sh" + commandNlbDeploy: "sudo ~/deployNlb.sh" + commandNlbAddTargetNode: "sudo ~/addTargetNode.sh" + commandNlbApplyConfig: "sudo ~/applyConfig.sh" + nlbMcisCommonSpec: "aws-ap-northeast-2-t2-small" + nlbMcisCommonImage: "ubuntu18.04" + nlbMcisSubGroupSize: "2" diff --git a/deployments/docker-compose/docker-compose.yaml b/deployments/docker-compose/docker-compose.yaml index 50022cf..870a4bb 100644 --- a/deployments/docker-compose/docker-compose.yaml +++ b/deployments/docker-compose/docker-compose.yaml @@ -1,15 +1,123 @@ +networks: + internal_network: + internal: true + external_network: + driver: bridge + services: - # etcd - etcd: + # cm-beetle + cm-beetle: + image: cloudbaristaorg/cm-beetle:0.2.0 + container_name: cm-beetle + pull_policy: missing + build: + context: ${COMPOSE_PROJECT_ROOT} + dockerfile: Dockerfile + platform: linux/amd64 + networks: + - internal_network + - external_network + ports: + - target: 8056 + published: 8056 + protocol: tcp + depends_on: + - cb-tumblebug + volumes: + - ${COMPOSE_PROJECT_ROOT}/container-volume/cm-beetle-container/log/:/app/log/ + - ${COMPOSE_PROJECT_ROOT}/container-volume/cm-beetle-container/db/:/app/db/ + environment: + # - BEETLE_ROOT=/app + - BEETLE_SELF_ENDPOINT=localhost:8056 + # - BEETLE_API_ALLOW_ORIGINS=* + # - BEETLE_API_AUTH_ENABLED=true + # - BEETLE_API_USERNAME=default + # - BEETLE_API_PASSWORD=default + # - BEETLE_LKVSTORE_PATH=/app/db/beetle.db + # - 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=debug + # - BEETLE_LOGWRITER=both + - BEETLE_NODE_ENV=development + # - BEETLE_AUTOCONTROL_DURATION_MS=10000 + - BEETLE_TUMBLEBUG_ENDPOINT=http://cb-tumblebug:1323 + # - BEETLE_TUMBLEBUG_API_USERNAME=default + # - BEETLE_TUMBLEBUG_API_PASSWORD=default + healthcheck: # for CM-Beetle + test: [ "CMD", "curl", "-f", "http://localhost:8056/beetle/readyz" ] + interval: 1m + timeout: 5s + retries: 3 + start_period: 10s + + # CB-Tumblebug + cb-tumblebug: + image: cloudbaristaorg/cb-tumblebug:0.9.10 + container_name: cb-tumblebug + # build: + # context: . + # dockerfile: Dockerfile + platform: linux/amd64 + networks: + - internal_network + - external_network + ports: + - 1323:1323 + depends_on: + - cb-tumblebug-etcd + # - cb-tumblebug-etcd-conf + - cb-spider + volumes: + - ./cb-tumblebug/conf/:/app/conf/ + - ${COMPOSE_PROJECT_ROOT}/container-volume/cb-tumblebug-container/meta_db/:/app/meta_db/ + - ${COMPOSE_PROJECT_ROOT}/container-volume/cb-tumblebug-container/log/:/app/log/ + environment: + # - TB_ROOT_PATH=/app + - TB_SPIDER_REST_URL=http://cb-spider:1024/spider + - TB_ETCD_ENDPOINTS=http://cb-tumblebug-etcd:2379 + # - TB_ETCD_AUTH_ENABLED=true + # - TB_ETCD_USERNAME=default + # - TB_ETCD_PASSWORD=default + # - TB_SQLITE_URL=localhost:3306 + # - TB_SQLITE_DATABASE=cb_tumblebug + # - TB_SQLITE_USER=cb_tumblebug + # - TB_SQLITE_PASSWORD=cb_tumblebug + # - TB_ALLOW_ORIGINS=* + # - TB_AUTH_ENABLED=true + # - TB_API_USERNAME=default + # - TB_API_PASSWORD=default + # - TB_AUTOCONTROL_DURATION_MS=10000 + # - TB_SELF_ENDPOINT=localhost:1323 + # - TB_DRAGONFLY_REST_URL=http://cb-dragonfly:9090/dragonfly + # - TB_DEFAULT_NAMESPACE=default + # - TB_DEFAULT_CREDENTIALHOLDER=admin + # - TB_LOGFILE_PATH=/app/log/tumblebug.log + # - TB_LOGFILE_MAXSIZE=1000 + # - TB_LOGFILE_MAXBACKUPS=3 + # - TB_LOGFILE_MAXAGE=30 + # - TB_LOGFILE_COMPRESS=false + # - TB_LOGLEVEL=debug + # - TB_LOGWRITER=both + # - TB_NODE_ENV=development + healthcheck: # for CB-Tumblebug + test: [ "CMD", "curl", "-f", "http://localhost:1323/tumblebug/readyz" ] + interval: 1m + timeout: 5s + retries: 3 + start_period: 10s + + # cb-tumblebug-etcd + cb-tumblebug-etcd: image: gcr.io/etcd-development/etcd:v3.5.14 - container_name: etcd + container_name: cb-tumblebug-etcd + networks: + - internal_network ports: - - target: 2379 # Port assinged to etcd in the container - published: 2379 # Port to be exposed to the host - protocol: tcp # Protocol of the port - - target: 2380 # Port assinged to etcd in the container - published: 2380 # Port to be exposed to the host - protocol: tcp # Protocol of the port + - 2379:2379 + - 2380:2380 volumes: - ${COMPOSE_PROJECT_ROOT}/container-volume/etcd/data:/etcd-data entrypoint: /usr/local/bin/etcd @@ -47,43 +155,22 @@ services: retries: 3 start_period: 10s - # etcd-conf - etcd-conf: - image: alpine:latest - container_name: etcd-conf - depends_on: - - etcd - volumes: - - ./etcd/:/scripts/etcd/ - environment: - - ETCD_VERSION_TAG=v3.5.14 - - ETCD_ENDPOINTS=http://etcd:2379 - - ETCD_PATH=/tmp/etcd-download-test - - ETCD_AUTH_ENABLED=true - - ETCD_ROOT_PASSWORD=default - - ETCD_ADMIN_USERNAME=default - - ETCD_ADMIN_PASSWORD=default - command: sh -c "sh /scripts/etcd/etcd-conf.sh" - healthcheck: # for etcd-conf - test: ["CMD", "test", "-f", "/tmp/healthcheck"] - interval: 30s - timeout: 10s - retries: 3 - start_period: 10s - # CB-Spider cb-spider: - # image: cloudbaristaorg/cb-spider:0.9.0 - image: cloudbaristaorg/cb-spider:edge + image: cloudbaristaorg/cb-spider:0.9.3 container_name: cb-spider + # build: + # context: ../cb-spider + # dockerfile: Dockerfile platform: linux/amd64 + networks: + - internal_network + - external_network # for outbound access (not ideal for security) + # expose: + # - 1024 ports: - - target: 1024 - published: 1024 - protocol: tcp + - 1024:1024 volumes: - # - ./conf/log_conf.yaml:/root/go/src/github.com/cloud-barista/cb-spider/conf/log_conf.yaml - # - ./conf/store_conf.yaml:/root/go/src/github.com/cloud-barista/cb-spider/conf/store_conf.yaml - ${COMPOSE_PROJECT_ROOT}/container-volume/cb-spider-container/meta_db/:/root/go/src/github.com/cloud-barista/cb-spider/meta_db/ - ${COMPOSE_PROJECT_ROOT}/container-volume/cb-spider-container/log/:/root/go/src/github.com/cloud-barista/cb-spider/log/ environment: @@ -94,7 +181,7 @@ services: # - API_PASSWORD= - SPIDER_LOG_LEVEL=error - SPIDER_HISCALL_LOG_LEVEL=error - - ID_TRANSFORM_MODE=ON + - ID_TRANSFORM_MODE=OFF healthcheck: # for CB-Spider test: [ "CMD", "curl", "-f", "http://localhost:1024/spider/readyz" ] interval: 1m @@ -102,117 +189,22 @@ services: retries: 3 start_period: 10s - # CB-Tumblebug - cb-tumblebug: - image: cloudbaristaorg/cb-tumblebug:0.9.6 - container_name: cb-tumblebug - platform: linux/amd64 - ports: - - target: 1323 - published: 1323 - protocol: tcp - depends_on: - - cb-spider - - etcd-conf - volumes: - # - ./conf/:/app/conf/ - - ${COMPOSE_PROJECT_ROOT}/container-volume/cb-tumblebug-container/meta_db/:/app/meta_db/ - - ${COMPOSE_PROJECT_ROOT}/container-volume/cb-tumblebug-container/log/:/app/log/ - environment: - # - TB_ROOT_PATH=/app - - TB_SPIDER_REST_URL=http://cb-spider:1024/spider - - TB_DRAGONFLY_REST_URL=http://cb-dragonfly:9090/dragonfly - # - TB_SQLITE_URL=localhost:3306 - # - TB_SQLITE_DATABASE=cb_tumblebug - # - TB_SQLITE_USER=cb_tumblebug - # - TB_SQLITE_PASSWORD=cb_tumblebug - - TB_ETCD_ENDPOINTS=http://etcd:2379 - # - TB_ETCD_AUTH_ENABLED=true - # - TB_ETCD_USERNAME=default - # - TB_ETCD_PASSWORD=default - # - TB_ALLOW_ORIGINS=* - # - TB_AUTH_ENABLED=true - # - TB_API_USERNAME=default - # - TB_API_PASSWORD=default - # - TB_AUTOCONTROL_DURATION_MS=10000 - - TB_SELF_ENDPOINT=localhost:1323 - # - TB_DEFAULT_NAMESPACE=ns01 - # - TB_DEFAULT_CREDENTIALHOLDER=admin - # - TB_LOGFILE_PATH=/app/log/tumblebug.log - - TB_LOGFILE_MAXSIZE=1000 - # - TB_LOGFILE_MAXBACKUPS=3 - # - TB_LOGFILE_MAXAGE=30 - # - TB_LOGFILE_COMPRESS=false - # - TB_LOGLEVEL=debug - # - TB_LOGWRITER=both - # - TB_NODE_ENV=development - healthcheck: # for CB-Tumblebug - test: [ "CMD", "curl", "-f", "http://localhost:1323/tumblebug/readyz" ] - interval: 1m - timeout: 5s - retries: 3 - start_period: 10s - - # cm-beetle - cm-beetle: - image: cloudbaristaorg/cm-beetle:0.2.0 - pull_policy: missing - build: - context: ${COMPOSE_PROJECT_ROOT} - dockerfile: Dockerfile - container_name: cm-beetle - ports: - - target: 8056 - published: 8056 - protocol: tcp - depends_on: - - cb-tumblebug - volumes: - - ${COMPOSE_PROJECT_ROOT}/conf/:/app/conf/ - - ${COMPOSE_PROJECT_ROOT}/container-volume/cm-beetle-container/log/:/app/log/ - environment: - # - BEETLE_ROOT=/app - # - BEETLE_CBSTORE_ROOT=/app - # - BEETLE_CBLOG_ROOT=/app - - BEETLE_TUMBLEBUG_ENDPOINT=http://cb-tumblebug:1323 - # - 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=debug - # - BEETLE_LOGWRITER=both - - BEETLE_NODE_ENV=development - # - BEETLE_SQLITE_URL=localhost:3306 - # - BEETLE_SQLITE_DATABASE=cm_beetle - # - BEETLE_SQLITE_USER=cm_beetle - # - BEETLE_SQLITE_PASSWORD=cm_beetle - # - BEETLE_API_ALLOW_ORIGINS=* - # - BEETLE_API_AUTH_ENABLED=true - # - BEETLE_API_USERNAME=default - # - BEETLE_API_PASSWORD=default - # - BEETLE_AUTOCONTROL_DURATION_MS=10000 - - BEETLE_SELF_ENDPOINT=localhost:8056 - healthcheck: # for CM-Beetle - test: [ "CMD", "curl", "-f", "http://localhost:8056/beetle/readyz" ] - interval: 1m - timeout: 5s - retries: 3 - start_period: 10s - - # cb-mapui (optionally use) + # cb-mapui cb-mapui: - image: cloudbaristaorg/cb-mapui:0.9.3 + image: cloudbaristaorg/cb-mapui:0.9.4 container_name: cb-mapui + # build: + # context: ../cb-mapui + # dockerfile: Dockerfile + networks: + - external_network ports: - target: 1324 published: 1324 protocol: tcp - # depends_on: - # - cb-tumblebug healthcheck: # for cb-mapui test: ["CMD", "nc", "-vz", "localhost", "1324"] interval: 1m timeout: 5s retries: 3 - start_period: 10s \ No newline at end of file + start_period: 10s diff --git a/pkg/api/rest/server.go b/pkg/api/rest/server.go index 4c93841..074c348 100644 --- a/pkg/api/rest/server.go +++ b/pkg/api/rest/server.go @@ -27,8 +27,8 @@ import ( rest_common "github.com/cloud-barista/cm-beetle/pkg/api/rest/common" "github.com/cloud-barista/cm-beetle/pkg/api/rest/controller" "github.com/cloud-barista/cm-beetle/pkg/api/rest/middlewares" + "github.com/cloud-barista/cm-beetle/pkg/config" "github.com/cloud-barista/cm-beetle/pkg/core/common" - "github.com/spf13/viper" "crypto/subtle" "fmt" @@ -106,9 +106,9 @@ func RunServer(port string) { e.HideBanner = true //e.colorer.Printf(banner, e.colorer.Red("v"+Version), e.colorer.Blue(website)) - allowedOrigins := viper.GetString("beetle.api.allow.origins") + allowedOrigins := config.Beetle.API.Allow.Origins if allowedOrigins == "" { - log.Fatal().Msg("allow_ORIGINS env variable for CORS is " + allowedOrigins + + log.Fatal().Msg("ALLOW_ORIGINS env variable for CORS is " + allowedOrigins + ". Please provide a proper value and source setup.env again. EXITING...") } @@ -118,11 +118,10 @@ func RunServer(port string) { })) // Conditions to prevent abnormal operation due to typos (e.g., ture, falss, etc.) - enableAuth := viper.GetString("beetle.api.auth.enabled") == "true" - - apiUser := viper.GetString("beetle.api.username") - apiPass := viper.GetString("beetle.api.password") + enableAuth := config.Beetle.API.Auth.Enabled + apiUser := config.Beetle.API.Username + apiPass := config.Beetle.API.Password if enableAuth { e.Use(middleware.BasicAuthWithConfig(middleware.BasicAuthConfig{ // Skip authentication for some routes that do not require authentication @@ -130,7 +129,7 @@ func RunServer(port string) { if c.Path() == "/beetle/readyz" || c.Path() == "/beetle/httpVersion" || strings.HasPrefix(c.Path(), "/tumblebug") { - log.Debug().Msgf("Skip authentication for %s", c.Path()) + // log.Debug().Msgf("Skip authentication for %s", c.Path()) return true } return false @@ -157,7 +156,7 @@ func RunServer(port string) { gTumblebug := e.Group("/tumblebug") // Set the target server for the proxy - target := viper.GetString("beetle.tumblebug.endpoint") + target := config.Tumblebug.Endpoint url, err := url.Parse(target) if err != nil { e.Logger.Fatal(err) @@ -253,7 +252,7 @@ func RunServer(port string) { gSample.DELETE("/users/:id", controller.DeleteUser) // Start API server - selfEndpoint := viper.GetString("beetle.self.endpoint") + selfEndpoint := config.Beetle.Self.Endpoint apidashboard := " http://" + selfEndpoint + "/beetle/api" if enableAuth {