Skip to content

Commit

Permalink
Merge pull request #2 from MZC-CSC/configuration_setup
Browse files Browse the repository at this point in the history
Writing a Dockerfile to run container base running.
  • Loading branch information
MZC-CSC authored Jun 21, 2024
2 parents 0bbf366 + 3a851ed commit d969261
Show file tree
Hide file tree
Showing 24 changed files with 343 additions and 419 deletions.
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ ant
.gitignore
.DS_Store
meta/*.db
result/*
result/**
data/**
1 change: 0 additions & 1 deletion .env

This file was deleted.

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ jmeter.log
result/**
**.properties
meta/*.db
ant
ant
data/**
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ RUN apk add --no-cache make gcc sqlite-libs sqlite-dev build-base

WORKDIR /go/src/github.com/cloud-barista/cm-ant

COPY go.mod go.sum .
COPY go.mod go.sum ./

RUN go mod download

Expand All @@ -24,7 +24,6 @@ WORKDIR $ANT_ROOT_PATH

COPY --from=builder /go/src/github.com/cloud-barista/cm-ant/ant /app/ant
COPY --from=builder /go/src/github.com/cloud-barista/cm-ant/config.yaml /app/config.yaml
COPY --from=builder /go/src/github.com/cloud-barista/cm-ant/.env /app/.env
COPY --from=builder /go/src/github.com/cloud-barista/cm-ant/test_plan /app/test_plan
COPY --from=builder /go/src/github.com/cloud-barista/cm-ant/script /app/script
COPY --from=builder /go/src/github.com/cloud-barista/cm-ant/meta /app/meta
Expand Down
49 changes: 28 additions & 21 deletions cmd/cm-ant/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,52 @@ import (
"fmt"
"log"
"net/http"
"sync"
"time"

"github.com/cloud-barista/cm-ant/pkg/config"
"github.com/cloud-barista/cm-ant/pkg/database"
loadHanlder "github.com/cloud-barista/cm-ant/pkg/load/api/handler"
"github.com/cloud-barista/cm-ant/pkg/load/services"
priceHanlder "github.com/cloud-barista/cm-ant/pkg/price/api/handler"
"github.com/cloud-barista/cm-ant/pkg/render"
"github.com/cloud-barista/cm-ant/pkg/utils"

_ "github.com/cloud-barista/cm-ant/api"

"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"

_ "github.com/cloud-barista/cm-ant/api"
"github.com/cloud-barista/cm-ant/pkg/configuration"
zerolog "github.com/rs/zerolog/log"
echoSwagger "github.com/swaggo/echo-swagger"
)

var once sync.Once
func main() {

// @title CM-ANT API
// @version 0.1
// @description
err := config.InitConfig()

func main() {
if err != nil {
log.Fatal("CM-Ant server config error : ", err)
}

once.Do(func() {
err := configuration.Initialize()
if err != nil {
log.Println(err)
log.Fatal("error while reading config file.")
}
router := InitRouter()
log.Fatal(router.Start(fmt.Sprintf(":%s", configuration.Get().Server.Port)))
})
err = database.InitDatabase()
if err != nil {
log.Fatal("CM-Ant database initialize erro :", err)
}

router := InitRouter()
log.Fatal(router.Start(fmt.Sprintf(":%s", config.AppConfig.Server.Port)))
}

// @title CM-ANT API
// @version 0.1
// @description

func InitRouter() *echo.Echo {
e := echo.New()

e.Static("/web/templates", configuration.RootPath()+"/web/templates")
e.Static("/css", configuration.RootPath()+"/web/css")
e.Static("/js", configuration.RootPath()+"/web/js")
e.Static("/web/templates", utils.RootPath()+"/web/templates")
e.Static("/css", utils.RootPath()+"/web/css")
e.Static("/js", utils.RootPath()+"/web/js")

e.Use(
middleware.RequestLoggerWithConfig(
Expand Down Expand Up @@ -95,6 +101,7 @@ func InitRouter() *echo.Echo {
middleware.Recover(),
middleware.RequestID(),
middleware.RateLimiter(middleware.NewRateLimiterMemoryStore(20)),
middleware.CORS(),
)

e.Use(middleware.TimeoutWithConfig(middleware.TimeoutConfig{
Expand All @@ -107,7 +114,7 @@ func InitRouter() *echo.Echo {
}))

// config template
tmpl := configuration.NewTemplate()
tmpl := render.NewTemplate()

e.Renderer = tmpl

Expand Down
20 changes: 14 additions & 6 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
root:
path:

server:
port: 8880

spider:
host: http://localhost
port: 1024
Expand All @@ -10,14 +16,16 @@ tumblebug:

load:
jmeter:
workDir: "/opt/ant/jmeter"
dir: "/opt/ant/jmeter"
version: 5.3

server:
port: 8880
logging:
level: info

datasource:
database:
driver: "sqlite"
connection: "${ROOT}/meta/ant_meta.db"
username:
host: "${ROOT}/meta/ant_meta.db"
port:
user:
password:
name:
50 changes: 50 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
version: '3.8'

services:
cb-spider:
image: cloudbaristaorg/cb-spider:0.8.17
container_name: cb-spider
platform: linux/amd64
ports:
- "0.0.0.0:1024:1024"
- "0.0.0.0:2048:2048"
environment:
- PLUGIN_SW=OFF
# if you leave these values empty, REST Auth will be disabled.
- API_USERNAME=
- API_PASSWORD=
- SPIDER_LOG_LEVEL=info


# CB-Tumblebug
cb-tumblebug:
image: cloudbaristaorg/cb-tumblebug:0.8.12
container_name: cb-tumblebug
platform: linux/amd64
ports:
- "1323:1323"
depends_on:
- cb-spider
volumes:
- ./data/cb-tumblebug/meta_db/:/app/meta_db/
- ./data/cb-tumblebug/log/:/app/log/
environment:
- SPIDER_REST_URL=http://cb-spider:1024/spider
- API_USERNAME=default
- API_PASSWORD=default

cm-ant:
build:
context: ./
dockerfile: Dockerfile
container_name: cm-ant
platform: linux/amd64
ports:
- 8880:8880
depends_on:
- cb-tumblebug
environment:
- ANT_SPIDER_HOST=http://cb-spider
- ANT_SPIDER_PORT=1024
- ANT_TUMBLEBUG_HOST=http://cb-tumblebug
- ANT_TUMBLEBUG_PORT=1323
77 changes: 77 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package config

import (
"fmt"
"log"
"strings"

"github.com/cloud-barista/cm-ant/pkg/utils"
"github.com/spf13/viper"
)

var (
AppConfig AntConfig
)

type AntConfig struct {
Root struct {
Path string `yaml:"path"`
} `yaml:"root"`
Server struct {
Port string `yaml:"port"`
} `yaml:"server"`
Spider struct {
Host string `yaml:"host"`
Port string `yaml:"port"`
} `yaml:"spider"`
Tumblebug struct {
Host string `yaml:"host"`
Port string `yaml:"port"`
Username string `yaml:"username"`
Password string `yaml:"password"`
} `yaml:"tumblebug"`
Load struct {
JMeter struct {
Dir string `yaml:"dir"`
Version string `yaml:"version"`
} `yaml:"jmeter"`
} `yaml:"load"`
Logging struct {
Level string `yaml:"level"`
} `yaml:"logging"`
Database struct {
Driver string `yaml:"driver"`
Host string `yaml:"host"`
Port string `yaml:"port"`
User string `yaml:"user"`
Password string `yaml:"password"`
Name string `yaml:"name"`
} `yaml:"database"`
}

func InitConfig() error {
cfg := AntConfig{}

viper.AddConfigPath(utils.RootPath())
viper.SetConfigName("config")
viper.SetConfigType("yaml")

viper.SetEnvPrefix("ant")
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
viper.AutomaticEnv()

err := viper.ReadInConfig()
if err != nil {
return fmt.Errorf("fatal error while read config file: %w", err)
}

err = viper.Unmarshal(&cfg)
if err != nil {
return fmt.Errorf("fatal error while unmarshal from config to ant config: %w", err)
}

log.Printf("server configuration with [%+v] \n", cfg)
AppConfig = cfg

return nil
}
Loading

0 comments on commit d969261

Please sign in to comment.