67 lines
1.8 KiB
Go
67 lines
1.8 KiB
Go
package config
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"io/ioutil"
|
|
)
|
|
|
|
// Config is the whole configuration for the forge platform deployment.
|
|
type Config struct {
|
|
ProjectName string `json:"project"`
|
|
Docker DockerConfig `json:"docker"`
|
|
Services ServicesConfig `json:"services"`
|
|
}
|
|
|
|
// DockerConfig contains the configuration for docker specific components.
|
|
type DockerConfig struct {
|
|
Network DockerNetworkConfig `json:"network"`
|
|
SharedVolume DockerSharedVolumeConfig `json:"sharedVolume"`
|
|
}
|
|
|
|
// DockerNetworkConfig contains configuration for creating the docker network.
|
|
type DockerNetworkConfig struct {
|
|
Name string `json:"name"`
|
|
Subnet string `json:"subnet"`
|
|
Driver string `json:"driver"`
|
|
}
|
|
|
|
// DockerSharedVolumeConfig contains configuration
|
|
// for creating the shared volume.
|
|
type DockerSharedVolumeConfig struct {
|
|
Name string `json:"name"`
|
|
}
|
|
|
|
// Services contains a list of services and their configuration.
|
|
type ServicesConfig struct {
|
|
Traefik TraefikConfig `json:"traefik"`
|
|
}
|
|
|
|
// TraefikConfig contains configuration for the Traefik container.
|
|
type TraefikConfig struct {
|
|
CheckNewVersion bool `json:"checkNewVersion"`
|
|
ContainerIp string `json:"containerIp"`
|
|
Domain string `json:"domain"`
|
|
GroupId int
|
|
LogLevel string `json:"logLevel"`
|
|
SendAnonymousUsage bool `json:"sendAnonymousUsage"`
|
|
Version string `json:"version"`
|
|
}
|
|
|
|
// NewConfig creates a new Config value from a given
|
|
// JSON file.
|
|
func NewConfig(file string) (Config, error) {
|
|
var c Config
|
|
var err error
|
|
|
|
data, err := ioutil.ReadFile(file)
|
|
if err != nil {
|
|
return c, fmt.Errorf("unable to read data from %s...\n%v", file, err)
|
|
}
|
|
|
|
if err = json.Unmarshal(data, &c); err != nil {
|
|
return c, fmt.Errorf("unable to decode the JSON configuration from %s...\n%v", file, err)
|
|
}
|
|
|
|
return c, nil
|
|
}
|