Documentation ¶
Overview ¶
Package server implements a server for docker-machine deployment.
Index ¶
- Constants
- func NewDeployService(o *Options, s *db.DBConnect, r *redis.Client, d chan bool, l *logger.Logger, ...) *deployService
- func NewRedisClient(hostname string, port int, password string, database int) (*redis.Client, error)
- func PrintUsageAndExit()
- func PrintVersionAndExit()
- type DeployRequest
- type Middleware
- type Options
- type Server
- type Status
Constants ¶
const ( // Config file defaults (yml) DefaultConfigPrefix = applicationName // Server configuration file name (YML) DefaultConfigPath = "/etc/" + applicationName // Server configuration file location. DefaultServerName = applicationName DefaultDomain = applicationName DefaultHostname = "localhost" DefaultPort = 8080 DefaultDSN = "root:root@tcp(mysql:3306)/" + applicationName DefaultRedisHost = "redis" DefaultRedisPort = "6379" DefaultRedisKeyQueue = applicationName + ":queue" DefaultRedisKeyLastDeploy = applicationName + ":lastdeploy" DefaultRedisPollInt = 5 // sec. DefaultProject = "docker" DefaultTempPath = "/tmp/" + applicationName DefaultImageTag = "latest" DefaultNumCont = 2 // Connections. TCPReadTimeout = 10 * time.Second TCPWriteTimeout = 10 * time.Second // Error messages. InvalidMediaType = "Invalid Content-Type or Accept header value." InvalidMethod = "Invalid Method for this route." InvalidBody = "Invalid body of text in request." InvalidJSONText = "Invalid JSON format in text of body in request." InvalidJSONAttribute = "Invalid - 'text' attribute in JSON not found." InvalidAuthorization = "Invalid authorization." InvalidEnvAuthorization = "Invalid authorization for environment." InvalidDeployEnv = "Invalid 'deployEnvironment'." InvalidDeployImage = "Invalid 'image'." InvalidDeployCannotQueue = "Cannot queue deploy request at this time." )
Variables ¶
This section is empty.
Functions ¶
func NewDeployService ¶
func NewDeployService(o *Options, s *db.DBConnect, r *redis.Client, d chan bool, l *logger.Logger, wg *sync.WaitGroup) *deployService
NewDeployService is a factory function that returns a new deployment service instance.
func NewRedisClient ¶
func NewRedisClient(hostname string, port int, password string, database int) (*redis.Client, error)
NewRedisClient is a factory method that returns a new redis connection.
func PrintUsageAndExit ¶
func PrintUsageAndExit()
PrintUsageAndExit is used to print out command line options.
func PrintVersionAndExit ¶
func PrintVersionAndExit()
PrintVersionAndExit prints the version of the server then exits.
Types ¶
type DeployRequest ¶
type DeployRequest struct { DeployID string `json:"deployID"` // A UUID for the request and for this deploy (client filled). ImageName string `json:"imageName"` // Image name in the repository in docker registry (client filled). ImageTag string `json:"imageTag"` // Image tag to deploy (client filled). Environment string `json:"environment"` // Environment from config.yml (client filled). EnvTag string `json:"envTag"` // Used to resolve machine names that are in the env (machine filled). EtcdEndpoint string `json:"etcdEndpoint"` // Etcd hostname and port (machine filled). Machine string `json:"machine"` // Master machine node for the cluster or local (machine filled). MetaMount string `json:"metaMount"` // Remote directory on a machine to place the metadata (machine filled). NumCont int `json:"numCont"` // Default number of containers for this environment (machine filled). Registry string `json:"registry"` // Docker registry for this environment (machine filled). Swarm bool `json:"swarm"` // Is this machine apart of a cluster (machine filled)? }
DeployRequest is a struct used to demarshal requests for a deploy and also to process.
func NewDeployRequest ¶
func NewDeployRequest(deployID string, imageName string, imageTag string, environment string, envTag string, etcdEndpoint string, machine string, metaMount string, numCont int, registry string, swarm bool) *DeployRequest
NewDeployRequest is a factory function that returns a DeployRequest instance.
func (*DeployRequest) String ¶
func (r *DeployRequest) String() string
String is an implentation of the Stringer interface so the structure is returned as a string to fmt.Print() etc.
type Middleware ¶
type Middleware struct {
// contains filtered or unexported fields
}
Middleware is used to perform filtering work on the request before the main controllers are called.
func (*Middleware) ServeHTTP ¶
func (m *Middleware) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements the interface to accept requests so they can be filtered before handling by the server.
type Options ¶
type Options struct { ConfigPath string `json:"configPath"` // Filepath to the config of the server. ConfigPrefix string `json:"configPrefix"` // Prefix of the config file name of the server. ServerName string `json:"serverName"` // Name of the server. Domain string `json:"domain"` // Domain of the server. Hostname string `json:"hostName"` // Hostname of the server. Port int `json:"port"` // HTTP api port of the server. ProfPort int `json:"profPort"` // The profiler port of the server. DSN string `json:"-"` // DSN login string to the database. RedisHostname string `json:"redisHostname"` // Hostname of a redis server. RedisPort int `json:"redisPort"` // Port of a redis server. RedisPassword string `json:"-"` // Password of a redis server. RedisDatabase int `json:"redisDatabase"` // Database of a redis server. RedisKeyLastDeploy string `json:"redisKeyLastDeploy"` // Redis key for the hash that holds the last deploys. RedisKeyQueue string `json:"redisKeyQueue"` // Redis key for the list that acts as a queue. RedisPollInt int `json:"redisPollInt"` // Redis polling interval for teh queue. GitRoot string `json:"gitRoot"` // Prefix for the git command to access account. GitRepo string `json:"gitRepo"` // Repo name on github that contains app config data. Project string `json:"project"` // Docker-compose project param. TempPath string `json:"tempPath"` // Temp directory for work. Debug bool `json:"debugEnabled"` // Is debugging enabled in the application or server. Environments map[string]map[string]string `json:"environments"` // Environments for deployment. }
Options represents parameters that are passed to the application for launching the server.
func (*Options) FillConfig ¶
Fill in the options from a viper configuration.
func (*Options) SetConfigDefaults ¶
Fill in the defaults for the viper configuration.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the main structure that represents a server instance.
func (*Server) LogRequest ¶
LogRequest logs the http request information into the logger.
func (*Server) Shutdown ¶
func (s *Server) Shutdown()
Shutdown takes down the server gracefully back to an initialize state.
func (*Server) StartProfiler ¶
func (s *Server) StartProfiler()
StartProfiler is called to enable dynamic profiling.
type Status ¶
type Status struct { Start time.Time `json:"startTime"` // The start time of the server. RequestCount int64 `json:"requestCount"` // How many requests came in to the server. RequestBytes int64 `json:"requestBytes"` // Size of the requests in bytes. RouteStats map[string]map[string]int64 `json:"routeStats"` // How many requests/bytes came into each route. }
Status contains runtime statistics.
func NewStatus ¶
NewStatus is a factory function that returns a new instance of Status. options is an optional list of functions that initialize the structure
func (*Status) IncrRequestStats ¶
IncrRequestStats increments the stats totals for the server.
func (*Status) IncrRouteStats ¶
IncrRouteStats increments the stats totals for the route.