domain

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2023 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAppNameAlreadyTaken               = apperr.New("app_name_already_taken")
	ErrVCSNotConfigured                  = apperr.New("vcs_not_configured")
	ErrAppCleanupNeeded                  = apperr.New("app_cleanup_needed")
	ErrAppCleanupRequested               = apperr.New("app_cleanup_requested")
	ErrAppHasRunningOrPendingDeployments = apperr.New("app_has_running_or_pending_deployments")
)
View Source
var (
	ErrCouldNotPromoteProductionDeployment = apperr.New("could_not_promote_production_deployment")
	ErrInvalidSourceDeployment             = apperr.New("invalid_source_deployment")
)
View Source
var (
	ErrNoValidSourceFound   = errors.New("no_valid_source_found")
	ErrInvalidSourcePayload = errors.New("invalid_source_payload")

	SourceDataTypes = storage.NewDiscriminatedMapper(func(sd SourceData) string { return sd.Kind() })
)
View Source
var (
	ErrNotInPendingState = apperr.New("not_in_pending_state")
	ErrNotInRunningState = apperr.New("not_in_running_state")
)
View Source
var (
	ErrInvalidAppName = apperr.New("invalid_app_name")
)
View Source
var (
	ErrInvalidEnvironmentName = apperr.New("invalid_environment_name")
)
View Source
var ErrInvalidUrl = apperr.New("invalid_url")

Functions

This section is empty.

Types

type App

type App struct {
	event.Emitter
	// contains filtered or unexported fields
}

func AppFrom

func AppFrom(scanner storage.Scanner) (a App, err error)

Recreates an app from the persistent storage.

func NewApp

func NewApp(name UniqueAppName, createdBy domain.UserID) (app App)

Instantiates a new App.

func (*App) Delete

func (a *App) Delete(deployments RunningOrPendingAppDeploymentsCount) error

Delete the application. This will only succeed if there are no running or pending deployments and a cleanup request has been made.

func (*App) HasEnvironmentVariables

func (a *App) HasEnvironmentVariables(vars EnvironmentsEnv)

Store environement variables per env and per services for this application.

func (App) ID

func (a App) ID() AppID

func (App) NewDeployment

func (a App) NewDeployment(
	deployNumber DeploymentNumber,
	meta SourceData,
	env Environment,
	requestedBy domain.UserID,
) (d Deployment, err error)

Creates a new deployment for this app. This method acts as a factory for the deployment entity to make sure a new deployment can be created for an app.

func (App) Promote

func (a App) Promote(
	source Deployment,
	deployNumber DeploymentNumber,
	requestedBy domain.UserID,
) (d Deployment, err error)

Promote the given deployment to the production environment

func (App) Redeploy

func (a App) Redeploy(
	source Deployment,
	deployNumber DeploymentNumber,
	requestedBy domain.UserID,
) (d Deployment, err error)

Redeploy the given deployment.

func (*App) RemoveEnvironmentVariables

func (a *App) RemoveEnvironmentVariables()

Removes all environment variables for this application.

func (*App) RemoveVersionControl

func (a *App) RemoveVersionControl()

Removes the version control configuration from the app.

func (*App) RequestCleanup

func (a *App) RequestCleanup(requestedBy domain.UserID)

Request backend cleaning for this application. This marks the application for deletion.

func (*App) UseVersionControl

func (a *App) UseVersionControl(config VCSConfig)

Sets an app version control configuration.

func (App) VCS

func (a App) VCS() monad.Maybe[VCSConfig]

type AppCleanupRequested

type AppCleanupRequested struct {
	bus.Notification

	ID        AppID
	Requested shared.Action[domain.UserID]
}

func (AppCleanupRequested) Name_ added in v1.2.0

func (AppCleanupRequested) Name_() string

type AppCreated

type AppCreated struct {
	bus.Notification

	ID      AppID
	Name    UniqueAppName
	Created shared.Action[domain.UserID]
}

func (AppCreated) Name_ added in v1.2.0

func (AppCreated) Name_() string

type AppDeleted

type AppDeleted struct {
	bus.Notification

	ID AppID
}

func (AppDeleted) Name_ added in v1.2.0

func (AppDeleted) Name_() string

type AppEnvChanged

type AppEnvChanged struct {
	bus.Notification

	ID  AppID
	Env EnvironmentsEnv
}

func (AppEnvChanged) Name_ added in v1.2.0

func (AppEnvChanged) Name_() string

type AppEnvRemoved

type AppEnvRemoved struct {
	bus.Notification

	ID AppID
}

func (AppEnvRemoved) Name_ added in v1.2.0

func (AppEnvRemoved) Name_() string

type AppID

type AppID string

type AppName

type AppName string

func AppNameFrom

func AppNameFrom(value string) (AppName, error)

Creates an AppName from a given raw value and returns any error if the value is not a valid AppName.

type AppVCSConfigured

type AppVCSConfigured struct {
	bus.Notification

	ID     AppID
	Config VCSConfig
}

func (AppVCSConfigured) Name_ added in v1.2.0

func (AppVCSConfigured) Name_() string

type AppVCSRemoved

type AppVCSRemoved struct {
	bus.Notification

	ID AppID
}

func (AppVCSRemoved) Name_ added in v1.2.0

func (AppVCSRemoved) Name_() string

type AppsReader

type AppsReader interface {
	IsNameUnique(context.Context, AppName) (UniqueAppName, error)
	GetByID(context.Context, AppID) (App, error)
}

type AppsWriter

type AppsWriter interface {
	Write(context.Context, ...*App) error
}

type ArtifactManager added in v1.1.0

type ArtifactManager interface {
	// Prepare the build directory and logger for the given deployment.
	// Returns the build directory path and the logger to use for each of the deployment steps.
	// You MUST close the logger if no err has been returned.
	PrepareBuild(context.Context, Deployment) (string, DeploymentLogger, error)
	// Cleanup an application artefacts.
	Cleanup(context.Context, App) error
	// Returns the absolute path to a deployment log file.
	LogPath(context.Context, Deployment) string
}

Manage all build artifacts.

type Backend

type Backend interface {
	Run(context.Context, string, DeploymentLogger, Deployment) (Services, error) // Launch a deployment stored in the given path through the backend and return services that has been deployed
	Cleanup(context.Context, App) error                                          // Cleanup an application, which means removing every possible stuff related to it
}

Backend service used to run an application services.

type Config

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

Holds data related to the configuration of the final application. It should have everything needed to resolve service and image name and is the primarly used structure during the deployment configuration process by the backend.

func NewConfig

func NewConfig(app App, environment Environment) Config

Builds a new config from the given application.

func (Config) AppName

func (c Config) AppName() UniqueAppName

func (Config) Env

func (c Config) Env() monad.Maybe[ServicesEnv]

func (Config) Environment

func (c Config) Environment() Environment

func (Config) EnvironmentVariablesFor

func (c Config) EnvironmentVariablesFor(service string) (m monad.Maybe[EnvVars])

Retrieve environment variables associated with the given service name. FIXME: If I want to follow my mantra, it should returns a readonly map

func (Config) ProjectName

func (c Config) ProjectName() string

Retrieve the name of the project wich is the combination of the appname and the environment targeted by this configuration.

func (Config) SubDomain

func (c Config) SubDomain() string

Returns the subdomain that will be used to expose services of an app.

type Deployment

type Deployment struct {
	event.Emitter
	// contains filtered or unexported fields
}

func DeploymentFrom

func DeploymentFrom(scanner storage.Scanner) (d Deployment, err error)

func (Deployment) Config

func (d Deployment) Config() Config

func (*Deployment) HasEnded

func (d *Deployment) HasEnded(services Services, deploymentErr error) error

Mark the deployment has ended with availables services or with an error if any. The internal status of the deployment will be updated accordingly.

func (*Deployment) HasStarted

func (d *Deployment) HasStarted() error

Mark a deployment has started.

func (Deployment) ID

func (d Deployment) ID() DeploymentID

func (Deployment) Requested added in v1.1.0

func (d Deployment) Requested() shared.Action[domain.UserID]

func (Deployment) Source added in v1.1.0

func (d Deployment) Source() SourceData

type DeploymentCreated

type DeploymentCreated struct {
	bus.Notification

	ID        DeploymentID
	Config    Config
	State     State
	Source    SourceData
	Requested shared.Action[domain.UserID]
}

func (DeploymentCreated) Name_ added in v1.2.0

func (DeploymentCreated) Name_() string

type DeploymentID

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

func DeploymentIDFrom

func DeploymentIDFrom(app AppID, number DeploymentNumber) DeploymentID

Construct a deployment id from an app and a deployment number

func (DeploymentID) AppID

func (i DeploymentID) AppID() AppID

func (DeploymentID) DeploymentNumber

func (i DeploymentID) DeploymentNumber() DeploymentNumber

type DeploymentLogger added in v1.1.0

type DeploymentLogger interface {
	io.WriteCloser

	Stepf(string, ...any)
	Warnf(string, ...any)
	Infof(string, ...any)
	Error(error)
}

Specific logger interface use by deployment jobs to document the deployment process.

type DeploymentNumber

type DeploymentNumber int

The deployment unique identifier is a composite key based on the app id and the deployment number.

type DeploymentStateChanged

type DeploymentStateChanged struct {
	bus.Notification

	ID    DeploymentID
	State State
}

func (DeploymentStateChanged) Name_ added in v1.2.0

type DeploymentStatus

type DeploymentStatus uint8
const (
	DeploymentStatusPending DeploymentStatus = iota
	DeploymentStatusRunning
	DeploymentStatusFailed
	DeploymentStatusSucceeded
)

type DeploymentsReader

type DeploymentsReader interface {
	GetByID(context.Context, DeploymentID) (Deployment, error)
	GetNextDeploymentNumber(context.Context, AppID) (DeploymentNumber, error)
	GetRunningDeployments(context.Context) ([]Deployment, error)
	GetRunningOrPendingDeploymentsCount(context.Context, AppID) (RunningOrPendingAppDeploymentsCount, error)
}

type DeploymentsWriter

type DeploymentsWriter interface {
	Write(context.Context, ...*Deployment) error
}

type EnvVars

type EnvVars map[string]string // Environment variables key pair

type Environment

type Environment string
const (
	// The production environment has a special meaning when determining the application domain.
	Production Environment = "production"
	// Staging environment
	Staging Environment = "staging"
)

func EnvironmentFrom

func EnvironmentFrom(value string) (Environment, error)

Creates a new environment value object from a raw value.

func (Environment) IsProduction

func (e Environment) IsProduction() bool

Returns true if the given environment represents the production one.

type EnvironmentsEnv

type EnvironmentsEnv map[Environment]ServicesEnv // Environment variables per deployment environment

func EnvironmentsEnvFrom

func EnvironmentsEnvFrom(raw map[string]map[string]map[string]string) (EnvironmentsEnv, error)

Builds the map of environment variables per env and per service from a raw value.

func (EnvironmentsEnv) Equals

func (e EnvironmentsEnv) Equals(other EnvironmentsEnv) bool

func (*EnvironmentsEnv) Scan

func (e *EnvironmentsEnv) Scan(value any) error

func (EnvironmentsEnv) Value

func (e EnvironmentsEnv) Value() (driver.Value, error)

type RunningOrPendingAppDeploymentsCount

type RunningOrPendingAppDeploymentsCount uint

type Service

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

Hold data related to services deployed and runned upon a deployment success.

func (Service) Image

func (s Service) Image() string

func (Service) IsExposed

func (s Service) IsExposed() bool

func (Service) MarshalJSON

func (s Service) MarshalJSON() ([]byte, error)

func (Service) Name

func (s Service) Name() string

func (Service) QualifiedName

func (s Service) QualifiedName() string

func (*Service) UnmarshalJSON

func (s *Service) UnmarshalJSON(b []byte) error

func (Service) Url

func (s Service) Url() monad.Maybe[Url]

type Services

type Services []Service

Custom types to hold Service array which implements the Scanner and Valuer interface to store it as a json string in the database (no need to create another table for it).

func (Services) Internal

func (s Services) Internal(conf Config, name, image string) (Services, Service)

Append a new service (not exposed to the outside world) to the current services array.

func (Services) Public

func (s Services) Public(baseUrl Url, conf Config, name, image string) (Services, Service)

Append a new exposed service to the current array. Given a base url and a deployment config, it will generate the correct URL for the provided service name.

func (*Services) Scan

func (s *Services) Scan(value any) error

func (Services) Value

func (s Services) Value() (driver.Value, error)

type ServicesEnv

type ServicesEnv map[string]EnvVars // Environment variables per service name

func (*ServicesEnv) Scan

func (e *ServicesEnv) Scan(value any) error

func (ServicesEnv) Value

func (e ServicesEnv) Value() (driver.Value, error)

type Source added in v1.1.0

type Source interface {
	Prepare(App, any) (SourceData, error)                              // Prepare the given payload for the given application, doing any needed validation
	Fetch(context.Context, string, DeploymentLogger, Deployment) error // Retrieve deployment data and store them in the given path before passing in to a backend
}

Represents a source which has initiated a deployment.

type SourceData added in v1.1.0

type SourceData interface {
	Kind() string
	NeedVCS() bool
}

Contains stuff related to how the deployment has been triggered. The inner data depends on the Source which has been requested.

type State

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

Holds together information related to the current deployment state. With a value object, it is easier to validate consistency between all those related properties. The default value represents a pending state.

func (State) ErrCode

func (s State) ErrCode() monad.Maybe[string]

func (State) Failed

func (s State) Failed(err error) (State, error)

func (State) FinishedAt

func (s State) FinishedAt() monad.Maybe[time.Time]

func (State) Services

func (s State) Services() monad.Maybe[Services]

func (State) Started

func (s State) Started() (State, error)

func (State) StartedAt

func (s State) StartedAt() monad.Maybe[time.Time]

func (State) Status

func (s State) Status() DeploymentStatus

func (State) Succeeded

func (s State) Succeeded(services Services) (State, error)

type UniqueAppName

type UniqueAppName AppName // Represents the unique name of an app and will be used as a subdomain.

type Url

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

Url struct which embed an url.URL struct and provides additional methods and meaning.

func UrlFrom

func UrlFrom(raw string) (Url, error)

Try to parse a raw url into an Url struct.

func (Url) Host

func (u Url) Host() string

func (Url) MarshalJSON

func (u Url) MarshalJSON() ([]byte, error)

func (*Url) Scan

func (u *Url) Scan(value any) error

func (Url) String

func (u Url) String() string

func (Url) SubDomain

func (u Url) SubDomain(subdomain string) Url

Returns a new url representing a subdomain.

func (*Url) UnmarshalJSON

func (u *Url) UnmarshalJSON(b []byte) error

func (Url) UseSSL

func (u Url) UseSSL() bool

func (Url) Value

func (u Url) Value() (driver.Value, error)

type VCSConfig

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

Holds the vcs configuration of an application.

func NewVCSConfig

func NewVCSConfig(url Url) VCSConfig

Instantiates a new version control config object.

func (VCSConfig) Authenticated

func (c VCSConfig) Authenticated(token string) VCSConfig

If this repository needs authentication, use the provided token.

func (VCSConfig) Equals

func (c VCSConfig) Equals(other VCSConfig) bool

func (VCSConfig) Public

func (c VCSConfig) Public() VCSConfig

Returns a new VCS Config without the token.

func (VCSConfig) Token

func (c VCSConfig) Token() monad.Maybe[string]

func (VCSConfig) Url

func (c VCSConfig) Url() Url

func (VCSConfig) WithUrl

func (c VCSConfig) WithUrl(url Url) VCSConfig

Updates the VCS Config with the provided url.

Jump to

Keyboard shortcuts

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