server

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 9, 2015 License: MIT Imports: 18 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindServiceVersions

func FindServiceVersions(serviceName string, units []*schema.Unit) []string

FindServiceUnits parses an array of units returned from fleet and collects all the versions present for the given service. This doesn't currently look at the state of the units, it simply looks for matching service names and returns an array of all the unique versions found.

Types

type Deploy

type Deploy struct {
	Version         string `json:"version"`
	DestroyPrevious bool   `json:"destroy_previous"`
	Timestamp       string `json:"timestamp,omitempty"`
	InstanceCount   int    `json:"instance_count,omitempty"`
}

Deploy is the struct that defines all the options for creating a new deploy and is wrapped by DeployRequest and deserialized in the Create function.

type DeployRequest

type DeployRequest struct {
	Deploy Deploy `json:"deploy"`
}

DeployRequest is the wrapper struct used to deserialize the JSON payload that is sent for creating a new deploy.

type DeploysResource

type DeploysResource struct {
	Fleet       FleetClient
	ImagePrefix string
}

DeploysResource is the HTTP resource responsible for creating and destroying deployments of services.

func (*DeploysResource) Create

func (dr *DeploysResource) Create(u *url.URL, h http.Header, req *DeployRequest) (int, http.Header, interface{}, error)

Create is the POST endpoint for kicking off a new deployment of the service and version provided. It uses these parameters to spin up tasks that will asyncronously start new units via Fleet and optionally wait for units to complete launching so that it can destroy old versions of the service that are no longer desired.

This function assumes that it is nested inside `/services/{name}` and that Tigertonic is extracting the service name and providing it via query params.

func (*DeploysResource) Destroy

func (dr *DeploysResource) Destroy(u *url.URL, h http.Header, req interface{}) (int, http.Header, interface{}, error)

Destroy is the DELETE endpoint for destroying the units associated with the service name and version provided. It will destroy all instances of a unit that exists within Fleet. If a timestamp query parameter is provided, only units that match that timestamp will be destroyed.

This function assumes that it is nested inside `/services/{name}/versions/{version}` and that Tigertonic is extracting the service name/version and providing it via query params.

type DeploysterService

type DeploysterService struct {
	AppVersion  string
	Listen      string
	Username    string
	Password    string
	ImagePrefix string
	RootMux     *tigertonic.TrieServeMux
	Mux         *tigertonic.TrieServeMux
	Server      *tigertonic.Server
}

DeploysterService is the HTTP server that ties together all the resources, configures routing and dependencies, and authenticates requests. The server will listen for requests in the address:port that is passed as the listen string. The provided username/password will be used for HTTP basic auth for all requests. An image prefix can be either a private registry address:port or a username on the public registry (basically something that'll be appended to the service name, e.g. mmmmhm/servicename or my.registry:5000/servicename).

func NewDeploysterService

func NewDeploysterService(listen string, version string, username string, password string, imagePrefix string) *DeploysterService

NewDeploysterService returns a configured DeploysterService, ready to listen for HTTP requests via the provided listen string.

func (*DeploysterService) Close

func (ds *DeploysterService) Close() error

Close gracefully stops listening for new requests

func (*DeploysterService) ConfigureRoutes

func (ds *DeploysterService) ConfigureRoutes()

ConfigureRoutes sets up resources and their dependencies so that we can configure all the HTTP routes that will be supported by the server.

func (*DeploysterService) ListenAndServe

func (ds *DeploysterService) ListenAndServe() error

ListenAndServe starts the HTTP server.

func (*DeploysterService) ListenAndServeTLS

func (ds *DeploysterService) ListenAndServeTLS(certPath string, keyPath string) error

ListenAndServe starts the HTTPS server with the given certificate and key.

type DockerClient

type DockerClient interface {
	CreateContainer(docker.CreateContainerOptions) (*docker.Container, error)
	StartContainer(string, *docker.HostConfig) error
	AttachToContainer(docker.AttachToContainerOptions) error
	InspectContainer(string) (*docker.Container, error)
	RemoveContainer(docker.RemoveContainerOptions) error
}

DockerClient is the interface required for TasksResource to be able to create, start, attach, inspect, and remove Docker containers.

type ExtractableUnit

type ExtractableUnit schema.Unit

ExtractableUnit is the local struct for a fleet.Unit with added functions for extracting the name, version, and instance that deployster encodes into the Fleet unit name.

func (*ExtractableUnit) ExtractBaseName

func (eu *ExtractableUnit) ExtractBaseName() string

ExtractBaseName returns the name of the service from the Fleet unit name. Given "railsapp:cf2e8ac:2006.01.02-15.04.05@1.service" this returns "railsapp"

func (*ExtractableUnit) ExtractInstance

func (eu *ExtractableUnit) ExtractInstance() string

ExtractInstance returns the instance of the service from the Fleet unit name. Given "railsapp:cf2e8ac:2006.01.02-15.04.05@1.service" this returns "1"

func (*ExtractableUnit) ExtractTimestamp added in v0.3.0

func (eu *ExtractableUnit) ExtractTimestamp() string

ExtractTimestamp returns the deploy timestamp that is appended to the Fleet unit name. Given "railsapp:cf2e8ac:2006.01.02-15.04.05@1.service" this returns "2013-06-05T14:10:43Z"

func (*ExtractableUnit) ExtractVersion

func (eu *ExtractableUnit) ExtractVersion() string

ExtractVersion returns the version of the service from the Fleet unit name. Given "railsapp:cf2e8ac:2006.01.02-15.04.05@1.service" this returns "cf2e8ac"

func (*ExtractableUnit) IsManaged added in v0.3.0

func (eu *ExtractableUnit) IsManaged() bool

ExtractBaseName returns the name of the service from the Fleet unit name. Given "railsapp:cf2e8ac:2006.01.02-15.04.05@1.service" this returns "railsapp"

type FleetClient added in v0.3.0

type FleetClient interface {
	Units() ([]*schema.Unit, error)
	CreateUnit(*schema.Unit) error
	DestroyUnit(string) error
	UnitStates() ([]*schema.UnitState, error)
	SetUnitTargetState(string, string) error
}

type Task

type Task struct {
	Version string `json:"version"`
	Command string `json:"command"`
}

Task is the JSON payload required to launch a new task.

type TaskRequest

type TaskRequest struct {
	Task Task `json:"task"`
}

TaskRequest is the top-level wrapper for the Task in the JSON payload sent by the client.

type TasksResource

type TasksResource struct {
	Docker      DockerClient
	ImagePrefix string
}

TasksResource is the HTTP resource responsible for launching new tasks via the Docker API in an opinionated and conventional way. Using the provided ImagePrefix and the payload passed to the Create endpoint, we can construct the image name to pull from the Docker Hub Registry so that the task can be launched.

func (*TasksResource) Create

func (tr *TasksResource) Create(w http.ResponseWriter, r *http.Request)

Create handles launching new tasks and streaming the output back over the http.ResponseWriter. It expects a JSON payload that can be decoded into a TaskRequest.

If an error occurs decoding the JSON or creating/running the container, an Internal Server Error will be returned in the response. However, if an error occurs after this point, we've already sent a 200 OK and started streaming the response body. This means the task was successfully launched, but the task could have possibly errored out. At the end of the task output, the exit code of the task will be printed so that it can be handled by the client if necessary.

type UnitTemplate

type UnitTemplate struct {
	Name        string
	Version     string
	ImagePrefix string
	Timestamp   string
}

UnitTemplate is the view model that is passed to the template parser that renders a unit file.

type UnitsResource

type UnitsResource struct {
	Fleet FleetClient
}

UnitsResource is the HTTP resource responsible for getting basic information on all units that exist for a given service.

func (*UnitsResource) Index

func (ur *UnitsResource) Index(u *url.URL, h http.Header, req interface{}) (int, http.Header, *UnitsResponse, error)

Index is the GET endpoint for listing all units that exist for a given service.

This function assumes that it is nested inside `/services/{name}` and that Tigertonic is extracting the service name and providing it via query params.

type UnitsResponse

type UnitsResponse struct {
	Units []VersionedUnit `json:"units"`
}

UnitsResponse is the wrapper struct for the JSON payload returned by the Index action.

type VersionedUnit

type VersionedUnit struct {
	Service      string `json:"service"`
	Instance     string `json:"instance"`
	Version      string `json:"version"`
	CurrentState string `json:"current_state"`
	DesiredState string `json:"desired_state"`
	MachineID    string `json:"machine_id"`
	Timestamp    string `json:"deploy_timestamp"`
}

VersionedUnit is our representation of a Fleet unit. Largely, the difference is that Fleet units don't care about versioning, so this lets us bridge the gap by exploding data that is encoded in the Fleet unit name into the proper fields appropriate for deployster.

func FindServiceUnits

func FindServiceUnits(serviceName string, version string, units []*schema.Unit) []VersionedUnit

FindServiceUnits parses an array of units returned from fleet and looks for only the units that match the given service name, which is a subset of the Fleet unit name. It collects all those units and returns an array of VersionedUnit structs that have had their additional deployster-specific fields populated from the Fleet unit name.

Optional filtering by version is available too. If all versions are desired, set version to "". If a specific version is desired, set version to that version.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL