domain

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2023 License: GPL-3.0 Imports: 16 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 (
	ErrNotInPendingState = apperr.New("not_in_pending_state")
	ErrNotInRunningState = apperr.New("not_in_running_state")
)
View Source
var (
	ErrNoValidTriggerFound   = apperr.New("no_valid_trigger_found")
	ErrInvalidTriggerPayload = apperr.New("invalid_trigger_payload")
	ErrTriggerFetchFailed    = apperr.New("trigger_fetch_failed")
)
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 Meta,
	env Environment,
	tmpl DeploymentDirTemplate,
	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) Path

func (a App) Path(relativeTo ...string) string

Retrieve the application directory relative to the given path.

func (App) Promote

func (a App) Promote(
	source Deployment,
	deployNumber DeploymentNumber,
	tmpl DeploymentDirTemplate,
	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,
	tmpl DeploymentDirTemplate,
	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 {
	ID        AppID
	Requested shared.Action[domain.UserID]
}

type AppCreated

type AppCreated struct {
	ID      AppID
	Name    UniqueAppName
	Created shared.Action[domain.UserID]
}

type AppDeleted

type AppDeleted struct {
	ID AppID
}

type AppEnvChanged

type AppEnvChanged struct {
	ID  AppID
	Env EnvironmentsEnv
}

type AppEnvRemoved

type AppEnvRemoved struct {
	ID AppID
}

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 {
	ID     AppID
	Config VCSConfig
}

type AppVCSRemoved

type AppVCSRemoved struct {
	ID AppID
}

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 Backend

type Backend interface {
	Run(context.Context, Deployment) (Services, error) // Launch a deployment 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.

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) LogPath

func (d Deployment) LogPath(relativeTo ...string) string

Retrieve the path where the log for this deployment is stored relative to the given directories.

func (Deployment) Path

func (d Deployment) Path(relativeTo ...string) string

Retrieve the deployment path relative to the given directories.

func (Deployment) Trigger

func (d Deployment) Trigger() Meta

type DeploymentCreated

type DeploymentCreated struct {
	ID        DeploymentID
	Path      string
	Config    Config
	State     State
	Trigger   Meta
	Requested shared.Action[domain.UserID]
}

type DeploymentDirTemplate

type DeploymentDirTemplate interface {
	Execute(DeploymentTemplateData) string
}

Since the build directory is a template, materialize it with this tiny interface. Making it a template enables the user to configure how the deployment directory should be built.

type DeploymentID

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

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

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 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 {
	ID    DeploymentID
	State State
}

type DeploymentStatus

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

type DeploymentTemplateData

type DeploymentTemplateData struct {
	Number      DeploymentNumber
	Environment Environment
}

Template data used to build a deployment path.

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 Kind

type Kind string

Specific type to represents a trigger kind to add helper methods on it.

const KindGit Kind = "git"

Represents a trigger which will fetch source code from Git. It is defined here because it has special meanings (see below).

func (Kind) IsVCS

func (k Kind) IsVCS() bool

Gets wether this kind of trigger is a version controlled one. For now it only checks for git but in the future, maybe there will be other VCS to deal with.

type Meta

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

Contains stuff related to how the deployment has been triggered. The inner data depends on the Trigger which has been requested, this is why I use primitive types here.

func NewMeta

func NewMeta(kind Kind, data string) Meta

Builds a new deployment meta from a kind and any additional data. You should never call it outside a Trigger implementation since it will be picked by a job to actually initiate the deployment.

func (Meta) Data

func (m Meta) Data() string

func (Meta) Kind

func (m Meta) Kind() Kind

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 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.

func NewState

func NewState(logfile string) State

Builds up a new pending state with the config filename.

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) LogFile

func (s State) LogFile() string

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 Trigger

type Trigger interface {
	Prepare(App, any) (Meta, error)          // Prepare the given payload for the given application, doing any needed validation
	Fetch(context.Context, Deployment) error // Retrieve deployment data before passing in to a backend
}

Represents a trigger which has initiated a deployment.

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 meanings.

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