Compare commits
2 Commits
master
...
feature/su
Author | SHA1 | Date |
---|---|---|
Naoki Kosaka | da16b3da58 | |
Naoki Kosaka | 773f5e28ec |
|
@ -7,6 +7,10 @@ services:
|
||||||
test: ["CMD", "redis-cli", "ping"]
|
test: ["CMD", "redis-cli", "ping"]
|
||||||
volumes:
|
volumes:
|
||||||
- "./redisdata:/data"
|
- "./redisdata:/data"
|
||||||
|
|
||||||
|
# rabbitmq:
|
||||||
|
# restart: always
|
||||||
|
# image: rabbitmq:alpine
|
||||||
|
|
||||||
worker:
|
worker:
|
||||||
build: .
|
build: .
|
||||||
|
@ -20,6 +24,7 @@ services:
|
||||||
- "./config.yml:/var/lib/relay/config.yml"
|
- "./config.yml:/var/lib/relay/config.yml"
|
||||||
depends_on:
|
depends_on:
|
||||||
- redis
|
- redis
|
||||||
|
# - rabbitmq
|
||||||
|
|
||||||
server:
|
server:
|
||||||
build: .
|
build: .
|
||||||
|
@ -33,3 +38,4 @@ services:
|
||||||
- "./config.yml:/var/lib/relay/config.yml"
|
- "./config.yml:/var/lib/relay/config.yml"
|
||||||
depends_on:
|
depends_on:
|
||||||
- redis
|
- redis
|
||||||
|
# - rabbitmq
|
||||||
|
|
2
main.go
2
main.go
|
@ -123,7 +123,6 @@ func buildCommand() *cobra.Command {
|
||||||
func initConfig(cmd *cobra.Command) {
|
func initConfig(cmd *cobra.Command) {
|
||||||
if verbose {
|
if verbose {
|
||||||
logrus.SetLevel(logrus.DebugLevel)
|
logrus.SetLevel(logrus.DebugLevel)
|
||||||
fmt.Println("DEBUG VIEW")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
configPath := cmd.Flag("config").Value.String()
|
configPath := cmd.Flag("config").Value.String()
|
||||||
|
@ -137,6 +136,7 @@ func initConfig(cmd *cobra.Command) {
|
||||||
logrus.Warn("Config file not exist. Use environment variables.")
|
logrus.Warn("Config file not exist. Use environment variables.")
|
||||||
|
|
||||||
viper.BindEnv("ACTOR_PEM")
|
viper.BindEnv("ACTOR_PEM")
|
||||||
|
viper.BindEnv("BROKER_URL")
|
||||||
viper.BindEnv("REDIS_URL")
|
viper.BindEnv("REDIS_URL")
|
||||||
viper.BindEnv("RELAY_BIND")
|
viper.BindEnv("RELAY_BIND")
|
||||||
viper.BindEnv("RELAY_DOMAIN")
|
viper.BindEnv("RELAY_DOMAIN")
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
# ACTOR_PEM: FILL_WITH_EACH_TEST
|
# ACTOR_PEM: FILL_WITH_EACH_TEST
|
||||||
|
# BROKER_URL: FILL_WITH_EACH_TEST
|
||||||
# REDIS_URL: FILL_WITH_EACH_TEST
|
# REDIS_URL: FILL_WITH_EACH_TEST
|
||||||
|
|
||||||
RELAY_BIND: 0.0.0.0:8080
|
RELAY_BIND: 0.0.0.0:8080
|
||||||
|
|
|
@ -19,7 +19,8 @@ type RelayConfig struct {
|
||||||
actorKey *rsa.PrivateKey
|
actorKey *rsa.PrivateKey
|
||||||
domain *url.URL
|
domain *url.URL
|
||||||
redisClient *redis.Client
|
redisClient *redis.Client
|
||||||
redisURL string
|
brokerURL *url.URL
|
||||||
|
redisURL *url.URL
|
||||||
serverBind string
|
serverBind string
|
||||||
serviceName string
|
serviceName string
|
||||||
serviceSummary string
|
serviceSummary string
|
||||||
|
@ -57,8 +58,11 @@ func NewRelayConfig() (*RelayConfig, error) {
|
||||||
return nil, errors.New("ACTOR_PEM: " + err.Error())
|
return nil, errors.New("ACTOR_PEM: " + err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
redisURL := viper.GetString("REDIS_URL")
|
redisURL, err := url.ParseRequestURI(viper.GetString("REDIS_URL"))
|
||||||
redisOption, err := redis.ParseURL(redisURL)
|
if err != nil {
|
||||||
|
return nil, errors.New("REDIS_URL: " + err.Error())
|
||||||
|
}
|
||||||
|
redisOption, err := redis.ParseURL(redisURL.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New("REDIS_URL: " + err.Error())
|
return nil, errors.New("REDIS_URL: " + err.Error())
|
||||||
}
|
}
|
||||||
|
@ -68,12 +72,19 @@ func NewRelayConfig() (*RelayConfig, error) {
|
||||||
return nil, errors.New("Redis Connection Test: " + err.Error())
|
return nil, errors.New("Redis Connection Test: " + err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
brokerURL, err := url.ParseRequestURI(viper.GetString("BROKER_URL"))
|
||||||
|
if err != nil {
|
||||||
|
logrus.Warn("BROKER_URL: INVALID OR EMPTY. USE REDIS_URL.")
|
||||||
|
brokerURL = redisURL
|
||||||
|
}
|
||||||
|
|
||||||
serverBind := viper.GetString("RELAY_BIND")
|
serverBind := viper.GetString("RELAY_BIND")
|
||||||
|
|
||||||
return &RelayConfig{
|
return &RelayConfig{
|
||||||
actorKey: privateKey,
|
actorKey: privateKey,
|
||||||
domain: domain,
|
domain: domain,
|
||||||
redisClient: redisClient,
|
redisClient: redisClient,
|
||||||
|
brokerURL: brokerURL,
|
||||||
redisURL: redisURL,
|
redisURL: redisURL,
|
||||||
serverBind: serverBind,
|
serverBind: serverBind,
|
||||||
serviceName: viper.GetString("RELAY_SERVICENAME"),
|
serviceName: viper.GetString("RELAY_SERVICENAME"),
|
||||||
|
@ -120,19 +131,25 @@ func (relayConfig *RelayConfig) DumpWelcomeMessage(moduleName string, version st
|
||||||
- Configuration
|
- Configuration
|
||||||
RELAY NAME : %s
|
RELAY NAME : %s
|
||||||
RELAY DOMAIN : %s
|
RELAY DOMAIN : %s
|
||||||
|
BROKER URL : %s
|
||||||
REDIS URL : %s
|
REDIS URL : %s
|
||||||
BIND ADDRESS : %s
|
BIND ADDRESS : %s
|
||||||
JOB_CONCURRENCY : %s
|
JOB_CONCURRENCY : %s
|
||||||
`, version, moduleName, relayConfig.serviceName, relayConfig.domain.Host, relayConfig.redisURL, relayConfig.serverBind, strconv.Itoa(relayConfig.jobConcurrency))
|
`, version, moduleName, relayConfig.serviceName, relayConfig.domain.Host, relayConfig.brokerURL, relayConfig.redisURL, relayConfig.serverBind, strconv.Itoa(relayConfig.jobConcurrency))
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMachineryServer create Redis backed Machinery Server from RelayConfig.
|
// NewMachineryServer create Redis backed Machinery Server from RelayConfig.
|
||||||
func NewMachineryServer(globalConfig *RelayConfig) (*machinery.Server, error) {
|
func NewMachineryServer(globalConfig *RelayConfig) (*machinery.Server, error) {
|
||||||
cnf := &config.Config{
|
cnf := &config.Config{
|
||||||
Broker: globalConfig.redisURL,
|
Broker: globalConfig.brokerURL.String(),
|
||||||
DefaultQueue: "relay",
|
DefaultQueue: "relay",
|
||||||
ResultBackend: globalConfig.redisURL,
|
ResultBackend: globalConfig.redisURL.String(),
|
||||||
ResultsExpireIn: 1,
|
ResultsExpireIn: 1,
|
||||||
|
AMQP: &config.AMQPConfig{
|
||||||
|
Exchange: "relay_exchange",
|
||||||
|
ExchangeType: "direct",
|
||||||
|
BindingKey: "relay_task",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
newServer, err := machinery.NewServer(cnf)
|
newServer, err := machinery.NewServer(cnf)
|
||||||
|
|
||||||
|
|
|
@ -88,7 +88,7 @@ func TestRelayConfig_DumpWelcomeMessage(t *testing.T) {
|
||||||
"module NAME": "Testing",
|
"module NAME": "Testing",
|
||||||
"RELAY NANE": relayConfig.serviceName,
|
"RELAY NANE": relayConfig.serviceName,
|
||||||
"RELAY DOMAIN": relayConfig.domain.Host,
|
"RELAY DOMAIN": relayConfig.domain.Host,
|
||||||
"REDIS URL": relayConfig.redisURL,
|
"REDIS URL": relayConfig.redisURL.String(),
|
||||||
"BIND ADDRESS": relayConfig.serverBind,
|
"BIND ADDRESS": relayConfig.serverBind,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,7 @@ relay --config /path/to/config.yml control
|
||||||
|
|
||||||
```yaml config.yml
|
```yaml config.yml
|
||||||
ACTOR_PEM: /var/lib/relay/actor.pem
|
ACTOR_PEM: /var/lib/relay/actor.pem
|
||||||
|
# BROKER_URL: amqp://guest:guest@rabbitmq:5672 # IF EMPTY, USE REDIS_URL
|
||||||
REDIS_URL: redis://redis:6379
|
REDIS_URL: redis://redis:6379
|
||||||
|
|
||||||
RELAY_BIND: 0.0.0.0:8080
|
RELAY_BIND: 0.0.0.0:8080
|
||||||
|
@ -63,6 +64,7 @@ JOB_CONCURRENCY: 50
|
||||||
This is **Optional** : When `config.yml` not exists, use environment variable.
|
This is **Optional** : When `config.yml` not exists, use environment variable.
|
||||||
|
|
||||||
- ACTOR_PEM
|
- ACTOR_PEM
|
||||||
|
- BROKER_URL
|
||||||
- REDIS_URL
|
- REDIS_URL
|
||||||
- RELAY_BIND
|
- RELAY_BIND
|
||||||
- RELAY_DOMAIN
|
- RELAY_DOMAIN
|
||||||
|
|
Loading…
Reference in New Issue