gce

package
v0.0.0-...-1907995 Latest Latest
Warning

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

Go to latest
Published: May 6, 2018 License: Apache-2.0 Imports: 42 Imported by: 0

Documentation

Overview

Package gce provides tools to deploy Perkeep on Google Compute Engine.

Index

Constants

View Source
const (
	DefaultInstanceName = "camlistore-server"
	DefaultMachineType  = "g1-small"
	DefaultRegion       = "us-central1"

	ConsoleURL = "https://console.developers.google.com"
)

Variables

View Source
var (
	// Verbose enables more info to be printed.
	Verbose bool
)

Functions

func LooksLikeRegion

func LooksLikeRegion(s string) bool

LooksLikeRegion reports whether s looks like a GCE region.

func NewOAuthConfig

func NewOAuthConfig(clientID, clientSecret string) *oauth2.Config

NewOAuthConfig returns an OAuth configuration template.

func ZonesOfRegion

func ZonesOfRegion(hc *http.Client, project, region string) (zones []string, err error)

TODO(bradfitz,mpl): move this to go4.org/cloud/google/gceutil

Types

type Config

type Config struct {
	ClientID       string `json:"clientID"`       // handler's credentials for OAuth. Required.
	ClientSecret   string `json:"clientSecret"`   // handler's credentials for OAuth. Required.
	Project        string `json:"project"`        // any Google Cloud project we can query to get the valid Google Cloud zones. Optional. Set from metadata on GCE.
	ServiceAccount string `json:"serviceAccount"` // JSON file with credentials to Project. Optional. Unused on GCE.
	DataDir        string `json:"dataDir"`        // where to store the instances configurations and states. Optional.
}

Config is the set of parameters to initialize the DeployHandler.

type DeployHandler

type DeployHandler struct {
	// contains filtered or unexported fields
}

DeployHandler serves a wizard that helps with the deployment of Perkeep on Google Compute Engine. It must be initialized with NewDeployHandler.

func NewDeployHandler

func NewDeployHandler(host, prefix string) (*DeployHandler, error)

NewDeployHandler initializes a DeployHandler that serves at https://host/prefix/ and returns it. A Google account client ID should be set in CAMLI_GCE_CLIENTID with its corresponding client secret in CAMLI_GCE_CLIENTSECRET.

func NewDeployHandlerFromConfig

func NewDeployHandlerFromConfig(host, prefix string, cfg *Config) (*DeployHandler, error)

NewDeployHandlerFromConfig initializes a DeployHandler from cfg. Host and prefix have the same meaning as for NewDeployHandler. cfg should not be nil.

func (*DeployHandler) AddTemplateTheme

func (h *DeployHandler) AddTemplateTheme(text string) error

AddTemplateTheme allows to enhance the aesthetics of the default template. To that effect, text can provide the template definitions for "header", "banner", "toplinks", and "footer".

func (*DeployHandler) ServeHTTP

func (h *DeployHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*DeployHandler) SetLogger

func (h *DeployHandler) SetLogger(lg *log.Logger)

func (*DeployHandler) SetScheme

func (h *DeployHandler) SetScheme(scheme string)

type Deployer

type Deployer struct {
	// Client is an OAuth2 client, authenticated for working with
	// the user's Google Cloud resources.
	Client *http.Client

	Conf *InstanceConf

	*log.Logger // Cannot be nil.
	// contains filtered or unexported fields
}

Deployer creates and starts an instance such as defined in Conf.

func (*Deployer) Create

func (d *Deployer) Create(ctx context.Context) (*compute.Instance, error)

Create sets up and starts a Google Compute Engine instance as defined in d.Conf. It creates the necessary Google Storage buckets beforehand.

func (*Deployer) CreateProject

func (d *Deployer) CreateProject(ctx context.Context) (string, error)

CreateProject creates a new Google Cloud Project. It returns the project ID, which is a random number in (0,1e10), prefixed with "camlistore-launcher-".

func (*Deployer) Get

func (d *Deployer) Get() (*compute.Instance, error)

Get returns the Instance corresponding to the Project, Zone, and Name defined in the Deployer's Conf.

type InstanceConf

type InstanceConf struct {
	Name          string // Name given to the virtual machine instance.
	Project       string // Google project ID where the instance is created.
	CreateProject bool   // CreateProject defines whether to first create project.
	Machine       string // Machine type.
	Zone          string // GCE zone; see https://cloud.google.com/compute/docs/zones
	Hostname      string // Fully qualified domain name.

	Ctime time.Time // Timestamp for this configuration.

	WIP bool // Whether to use the perkeepd-WORKINPROGRESS.tar.gz tarball instead of the "production" one
	// contains filtered or unexported fields
}

InstanceConf is the configuration for the Google Compute Engine instance that will be deployed.

type TemplateData

type TemplateData struct {
	Title             string
	Help              map[string]template.HTML // help bits within the form.
	Hints             []string                 // helping hints printed in case of an error.
	Err               error
	Prefix            string        // handler prefix.
	InstanceKey       string        // instance creation identifier, for the JS code to regularly poll for progress.
	PiggyGIF          string        // URI to the piggy gif for progress animation.
	Conf              *InstanceConf // Configuration requested by the user
	InstanceIP        string        `json:",omitempty"` // instance IP address that we display after successful creation.
	InstanceHostname  string        `json:",omitempty"`
	ProjectConsoleURL string
	ProjectID         string // set by us when we've just created a project on the behalf of the user
	ZoneValues        []string
	MachineValues     []string
	CamliVersion      string // git revision found in https://storage.googleapis.com/camlistore-release/docker/VERSION

	// Unused stuff, but needed by page.html. See TODO above,
	// before AddTemplateTheme.
	GoImportDomain   string
	GoImportUpstream string
}

TemplateData is the data passed for templates of tplHTML.

Jump to

Keyboard shortcuts

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