app

package
v0.0.0-...-8ecd7f4 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: BSD-3-Clause Imports: 53 Imported by: 20

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAlreadyHaveAccess = errors.New("team already have access to this app")
	ErrNoAccess          = errors.New("team does not have access to this app")
	ErrCannotOrphanApp   = errors.New("cannot revoke access from this team, as it's the unique team with access to the app")
	ErrDisabledPlatform  = errors.New("Disabled Platform, only admin users can create applications with the platform")

	ErrRouterAlreadyLinked = errors.New("router already linked to this app")

	ErrNoVersionProvisioner = errors.New("The current app provisioner does not support multiple versions handling")
	ErrKillUnitProvisioner  = errors.New("The current app provisioner does not support killing a unit")
	ErrSwapMultipleVersions = errors.New("swapping apps with multiple versions is not allowed")
	ErrSwapMultipleRouters  = errors.New("swapping apps with multiple routers is not supported")
	ErrSwapDifferentRouters = errors.New("swapping apps with different routers is not supported")
	ErrSwapNoCNames         = errors.New("no cnames to swap")
	ErrSwapDeprecated       = errors.New("swapping using router api v2 will work only with cnameOnly")
)
View Source
var (
	AuthScheme auth.Scheme
)
View Source
var (
	ErrAppAlreadyExists = errors.New("there is already an app with this name")
)
View Source
var SuppressedEnv = "*** (private variable)"
View Source
var TestLogWriterWaitOnClose = false

TestLogWriterWaitOnClose should only be set when running tests to avoid different test cases interacting.

Functions

func AppService

func AppService() (appTypes.AppService, error)

func Build

func Build(ctx context.Context, opts DeployOptions) (string, error)

func CacheService

func CacheService() (cache.AppCacheService, error)

func CreateApp

func CreateApp(ctx context.Context, app *App, user *auth.User) error

CreateApp creates a new app.

Creating a new app is a process composed of the following steps:

  1. Save the app in the database
  2. Provision the app using the provisioner

func Delete

func Delete(ctx context.Context, app *App, evt *event.Event, requestID string) error

Delete deletes an app.

func Deploy

func Deploy(ctx context.Context, opts DeployOptions) (string, error)

Deploy runs a deployment of an application. It will first try to run an archive based deploy (if opts.ArchiveURL is not empty), and then fallback to the Git based deployment.

func GetAppRouterUpdater

func GetAppRouterUpdater() *appRouterUpdater

func MigrateDeploysToEvents

func MigrateDeploysToEvents() error

func PlanService

func PlanService() (appTypes.PlanService, error)

func PlatformService

func PlatformService() (appTypes.PlatformService, error)

func QuotaService

func QuotaService() (quotaTypes.QuotaService, error)

func RenameTeam

func RenameTeam(ctx context.Context, oldName, newName string) error

func RollbackUpdate

func RollbackUpdate(ctx context.Context, app *App, imageID, reason string, disableRollback bool) error

func Swap

func Swap(ctx context.Context, app1, app2 *App, cnameOnly bool) error

Swap calls the Router.Swap and updates the app.CName in the database.

func Units

func Units(ctx context.Context, apps []App) (map[string]AppUnitsResponse, error)

func ValidateOrigin

func ValidateOrigin(origin string) bool

Types

type App

type App struct {
	Env             map[string]bindTypes.EnvVar
	ServiceEnvs     []bindTypes.ServiceEnvVar
	Platform        string `bson:"framework"`
	PlatformVersion string
	Name            string
	CName           []string
	Teams           []string
	TeamOwner       string
	Owner           string
	Plan            appTypes.Plan
	UpdatePlatform  bool
	Lock            appTypes.AppLock
	Pool            string
	Description     string
	Router          string
	RouterOpts      map[string]string
	Deploys         uint
	Tags            []string
	Error           string
	Routers         []appTypes.AppRouter
	Metadata        appTypes.Metadata
	Processes       []appTypes.Process

	// UUID is a v4 UUID lazily generated on the first call to GetUUID()
	UUID string

	// InterApp Properties implemented by provision.InterAppProvisioner
	// it is lazy generated on the first call to FillInternalAddresses
	InternalAddresses []provision.AppInternalAddress `json:",omitempty" bson:"-"`

	Quota quota.Quota
	// contains filtered or unexported fields
}

App is the main type in tsuru. An app represents a real world application. This struct holds information about the app: its name, address, list of teams that have access to it, used platform, etc.

func GetByName

func GetByName(ctx context.Context, name string) (*App, error)

GetByName queries the database to find an app identified by the given name.

func List

func List(ctx context.Context, filter *Filter) ([]App, error)

List returns the list of apps filtered through the filter parameter.

func (*App) AddCName

func (app *App) AddCName(cnames ...string) error

AddCName adds a CName to app. It updates the attribute, calls the SetCName function on the provisioner and saves the app in the database, returning an error when it cannot save the change in the database or add the CName on the provisioner.

func (*App) AddInstance

func (app *App) AddInstance(addArgs bind.AddInstanceArgs) error

func (*App) AddRouter

func (app *App) AddRouter(appRouter appTypes.AppRouter) error

func (*App) AddUnits

func (app *App) AddUnits(n uint, process, versionStr string, w io.Writer) error

AddUnits creates n new units within the provisioner, saves new units in the database and enqueues the apprc serialization.

func (*App) AutoScale

func (app *App) AutoScale(spec provision.AutoScaleSpec) error

func (*App) AutoScaleInfo

func (app *App) AutoScaleInfo() ([]provision.AutoScaleSpec, error)

func (*App) Context

func (app *App) Context() context.Context

func (*App) DeleteVersion

func (app *App) DeleteVersion(ctx context.Context, w io.Writer, versionStr string) error

DeleteVersion deletes an app version.

func (*App) DeployedVersions

func (app *App) DeployedVersions() ([]int, error)

func (*App) Envs

func (app *App) Envs() map[string]bindTypes.EnvVar

Envs returns a map representing the apps environment variables.

func (*App) GetAddresses

func (app *App) GetAddresses() ([]string, error)

func (*App) GetCertificates

func (app *App) GetCertificates() (map[string]map[string]string, error)

func (*App) GetCname

func (app *App) GetCname() []string

GetCname returns the cnames of the app.

func (*App) GetDeploys

func (app *App) GetDeploys() uint

GetDeploys returns the amount of deploys of an app.

func (*App) GetHealthcheckData

func (app *App) GetHealthcheckData() (routerTypes.HealthcheckData, error)

func (*App) GetInternalBindableAddresses

func (app *App) GetInternalBindableAddresses() ([]string, error)

func (*App) GetMetadata

func (app *App) GetMetadata(process string) appTypes.Metadata

func (*App) GetName

func (app *App) GetName() string

GetName returns the name of the app.

func (*App) GetPlan

func (app *App) GetPlan() appTypes.Plan

func (*App) GetPlatform

func (app *App) GetPlatform() string

GetPlatform returns the platform of the app.

func (*App) GetPlatformVersion

func (app *App) GetPlatformVersion() string

GetPlatformVersion returns the platform version of the app.

func (*App) GetPool

func (app *App) GetPool() string

GetPool returns the pool of the app.

func (*App) GetProcess

func (app *App) GetProcess(process string) *appTypes.Process

func (*App) GetQuota

func (app *App) GetQuota() (*quota.Quota, error)

func (*App) GetQuotaInUse

func (app *App) GetQuotaInUse() (int, error)

func (*App) GetRegistry

func (app *App) GetRegistry() (imgTypes.ImageRegistry, error)

func (*App) GetRouters

func (app *App) GetRouters() []appTypes.AppRouter

func (*App) GetRoutersWithAddr

func (app *App) GetRoutersWithAddr() ([]appTypes.AppRouter, error)

func (*App) GetTeamOwner

func (app *App) GetTeamOwner() string

GetTeamOwner returns the team owner of the app.

func (*App) GetTeams

func (app *App) GetTeams() []authTypes.Team

GetTeams returns a slice of teams that have access to the app.

func (*App) GetTeamsName

func (app *App) GetTeamsName() []string

GetTeamsName returns the names of the app teams.

func (*App) GetUUID

func (app *App) GetUUID() (string, error)

GetUUID returns the app v4 UUID. An UUID will be generated if it does not exist.

func (*App) GetUpdatePlatform

func (app *App) GetUpdatePlatform() bool

func (*App) Grant

func (app *App) Grant(team *authTypes.Team) error

Grant allows a team to have access to an app. It returns an error if the team already have access to the app.

func (*App) InstanceEnvs

func (app *App) InstanceEnvs(serviceName, instanceName string) map[string]bindTypes.EnvVar

InstanceEnvs returns a map of environment variables that belongs to the given service and service instance.

func (*App) KillUnit

func (app *App) KillUnit(unitName string, force bool) error

func (*App) LastLogs

func (app *App) LastLogs(ctx context.Context, logService appTypes.AppLogService, args appTypes.ListLogArgs) ([]appTypes.Applog, error)

LastLogs returns a list of the last `lines` log of the app, matching the fields in the log instance received as an example.

func (*App) ListTags

func (app *App) ListTags() []string

func (*App) MarshalJSON

func (app *App) MarshalJSON() ([]byte, error)

MarshalJSON marshals the app in json format.

func (*App) RemoveAutoScale

func (app *App) RemoveAutoScale(process string) error

func (*App) RemoveCName

func (app *App) RemoveCName(cnames ...string) error

func (*App) RemoveCertificate

func (app *App) RemoveCertificate(name string) error

func (*App) RemoveInstance

func (app *App) RemoveInstance(removeArgs bind.RemoveInstanceArgs) error

func (*App) RemoveRouter

func (app *App) RemoveRouter(name string) error

func (*App) RemoveUnits

func (app *App) RemoveUnits(ctx context.Context, n uint, process, versionStr string, w io.Writer) error

RemoveUnits removes n units from the app. It's a process composed of multiple steps:

  1. Remove units from the provisioner
  2. Update quota

func (*App) ReplaceContext

func (app *App) ReplaceContext(ctx context.Context)

func (*App) Restart

func (app *App) Restart(ctx context.Context, process, versionStr string, w io.Writer) error

Restart runs the restart hook for the app, writing its output to w.

func (*App) Revoke

func (app *App) Revoke(team *authTypes.Team) error

Revoke removes the access from a team. It returns an error if the team do not have access to the app.

func (*App) RoutableAddresses

func (app *App) RoutableAddresses(ctx context.Context) ([]appTypes.RoutableAddresses, error)

func (*App) Run

func (app *App) Run(cmd string, w io.Writer, args provision.RunArgs) error

Run executes the command in app units, sourcing apprc before running the command.

func (*App) SetCertificate

func (app *App) SetCertificate(name, certificate, key string) error

func (*App) SetEnvs

func (app *App) SetEnvs(setEnvs bind.SetEnvArgs) error

SetEnvs saves a list of environment variables in the app.

func (*App) SetPool

func (app *App) SetPool() error

func (*App) SetQuotaLimit

func (app *App) SetQuotaLimit(limit int) error

func (*App) SetRoutable

func (app *App) SetRoutable(ctx context.Context, version appTypes.AppVersion, isRoutable bool) error

func (*App) SetUpdatePlatform

func (app *App) SetUpdatePlatform(check bool) error

func (*App) Shell

func (app *App) Shell(opts provision.ExecOptions) error

func (*App) Start

func (app *App) Start(ctx context.Context, w io.Writer, process, versionStr string) error

Start starts the app calling the provisioner.Start method and changing the units state to StatusStarted.

func (*App) Stop

func (app *App) Stop(ctx context.Context, w io.Writer, process, versionStr string) error

func (*App) SuppressSensitiveEnvs

func (a *App) SuppressSensitiveEnvs()

func (*App) Units

func (app *App) Units() ([]provision.Unit, error)

Units returns the list of units.

func (*App) UnitsMetrics

func (app *App) UnitsMetrics() ([]provision.UnitMetric, error)

func (*App) UnsetEnvs

func (app *App) UnsetEnvs(unsetEnvs bind.UnsetEnvArgs) error

UnsetEnvs removes environment variables from an app, serializing the remaining list of environment variables to all units of the app.

func (*App) Update

func (app *App) Update(args UpdateAppArgs) (err error)

Update changes informations of the application.

func (*App) UpdateRouter

func (app *App) UpdateRouter(appRouter appTypes.AppRouter) error

func (*App) ValidateService

func (app *App) ValidateService(services ...string) error

func (*App) VerticalAutoScaleRecommendations

func (app *App) VerticalAutoScaleRecommendations() ([]provision.RecommendedResources, error)

type AppUnitsResponse

type AppUnitsResponse struct {
	Units []provision.Unit
	Err   error
}

type DeployData

type DeployData struct {
	ID          bson.ObjectId `bson:"_id,omitempty"`
	App         string
	Timestamp   time.Time
	Duration    time.Duration
	Commit      string
	Error       string
	Image       string
	Version     int
	Log         string
	User        string
	Origin      string
	CanRollback bool
	Diff        string
	Message     string
}

func GetDeploy

func GetDeploy(id string) (*DeployData, error)

func ListDeploys

func ListDeploys(ctx context.Context, filter *Filter, skip, limit int) ([]DeployData, error)

ListDeploys returns the list of deploy that match a given filter.

type DeployOptions

type DeployOptions struct {
	App              *App
	Commit           string
	BuildTag         string
	ArchiveURL       string
	Dockerfile       string
	FileSize         int64
	File             io.ReadCloser `bson:"-"`
	OutputStream     io.Writer     `bson:"-"`
	User             string
	Image            string
	Origin           string
	Event            *event.Event `bson:"-"`
	Kind             provisionTypes.DeployKind
	Message          string
	Rollback         bool
	Build            bool
	NewVersion       bool
	OverrideVersions bool
}

func (*DeployOptions) GetKind

func (o *DeployOptions) GetKind() (kind provisionTypes.DeployKind)

func (*DeployOptions) GetOrigin

func (o *DeployOptions) GetOrigin() string

type Filter

type Filter struct {
	Name        string
	NameMatches string
	Platform    string
	TeamOwner   string
	UserOwner   string
	Pool        string
	Pools       []string
	Statuses    []string
	Locked      bool
	Tags        []string
	Extra       map[string][]string
}

func (*Filter) ExtraIn

func (f *Filter) ExtraIn(name string, value string)

func (*Filter) IsEmpty

func (f *Filter) IsEmpty() bool

func (*Filter) Query

func (f *Filter) Query() bson.M

type LogWriter

type LogWriter struct {
	AppName string
	Source  string
	// contains filtered or unexported fields
}

func (*LogWriter) Async

func (w *LogWriter) Async()

func (*LogWriter) Close

func (w *LogWriter) Close()

func (*LogWriter) Wait

func (w *LogWriter) Wait(timeout time.Duration) error

func (*LogWriter) Write

func (w *LogWriter) Write(data []byte) (int, error)

Write writes and logs the data.

type UpdateAppArgs

type UpdateAppArgs struct {
	UpdateData    App
	Writer        io.Writer
	ShouldRestart bool
}

type UpdateUnitsResult

type UpdateUnitsResult struct {
	ID    string
	Found bool
}

Directories

Path Synopsis
Package bind provides interfaces and types for use when binding an app to a service.
Package bind provides interfaces and types for use when binding an app to a service.
gc

Jump to

Keyboard shortcuts

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