domain

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: May 18, 2023 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EnvPrefix = "NS_"

	EnvMySQLHostnameKey = EnvPrefix + "MYSQL_HOSTNAME"
	EnvMySQLPortKey     = EnvPrefix + "MYSQL_PORT"
	EnvMySQLUserKey     = EnvPrefix + "MYSQL_USER"
	EnvMySQLPasswordKey = EnvPrefix + "MYSQL_PASSWORD"
	EnvMySQLDatabaseKey = EnvPrefix + "MYSQL_DATABASE"

	EnvMongoDBHostnameKey = EnvPrefix + "MONGODB_HOSTNAME"
	EnvMongoDBPortKey     = EnvPrefix + "MONGODB_PORT"
	EnvMongoDBUserKey     = EnvPrefix + "MONGODB_USER"
	EnvMongoDBPasswordKey = EnvPrefix + "MONGODB_PASSWORD"
	EnvMongoDBDatabaseKey = EnvPrefix + "MONGODB_DATABASE"
)

All environment variables injected by neoshowcase must have NS_ prefix

View Source
const IDLength = 22

Variables

View Source
var EmptyCommit = strings.Repeat("0", 40)
View Source
var (
	// ErrFileNotFound ファイルが存在しない
	ErrFileNotFound = errors.New("not found")
)

Functions

func Base64EncodedPublicKey

func Base64EncodedPublicKey(keys *ssh.PublicKeys) string

func DBName

func DBName(applicationID string) string

func DeleteArtifact

func DeleteArtifact(s Storage, artifactID string) error

func DeleteBuildLog

func DeleteBuildLog(s Storage, buildID string) error

func GetArtifact

func GetArtifact(s Storage, artifactID string) (filename string, r io.ReadCloser, err error)

func GetBuildLog

func GetBuildLog(s Storage, buildID string) ([]byte, error)

func GitAuthMethod

func GitAuthMethod(repo *Repository, sshFallback *ssh.PublicKeys) (transport.AuthMethod, error)

func MatchDomain

func MatchDomain(source, target string) bool

func NewID

func NewID() string

NewID 22文字のランダムな文字列を生成

func SaveArtifact

func SaveArtifact(s Storage, artifactID string, src io.Reader) error

SaveArtifact Artifactをtar形式で保存する

func SaveBuildLog

func SaveBuildLog(s Storage, buildID string, src io.Reader) error

func ValidateDomain

func ValidateDomain(domain string) error

func ValidateWildcardDomain

func ValidateWildcardDomain(domain string) error

Types

type Application

type Application struct {
	ID            string
	Name          string
	RepositoryID  string
	RefName       string
	DeployType    DeployType
	Running       bool
	Container     ContainerState
	CurrentCommit string
	WantCommit    string
	CreatedAt     time.Time
	UpdatedAt     time.Time

	Config           ApplicationConfig
	Websites         []*Website
	PortPublications []*PortPublication
	OwnerIDs         []string
}

func (*Application) Apply

func (a *Application) Apply(args *UpdateApplicationArgs)

func (*Application) IsOwner

func (a *Application) IsOwner(user *User) bool

func (*Application) SelfValidate

func (a *Application) SelfValidate() error

func (*Application) Validate

func (a *Application) Validate(
	ctx context.Context,
	actor *User,
	controller ControllerServiceClient,
	existingApps []*Application,
	domains AvailableDomainSlice,
	ports AvailablePortSlice,
) (validateErr error, err error)

func (*Application) WebsiteConflicts

func (a *Application) WebsiteConflicts(existing []*Application, actor *User) bool

type ApplicationConfig

type ApplicationConfig struct {
	UseMariaDB  bool
	UseMongoDB  bool
	BuildConfig BuildConfig
	Entrypoint  string
	Command     string
}

func (*ApplicationConfig) CommandArgs

func (c *ApplicationConfig) CommandArgs() []string

func (*ApplicationConfig) EntrypointArgs

func (c *ApplicationConfig) EntrypointArgs() []string

func (*ApplicationConfig) Validate

func (c *ApplicationConfig) Validate(deployType DeployType) error

type ApplicationRepository

type ApplicationRepository interface {
	GetApplications(ctx context.Context, cond GetApplicationCondition) ([]*Application, error)
	GetApplication(ctx context.Context, id string) (*Application, error)
	CreateApplication(ctx context.Context, app *Application) error
	UpdateApplication(ctx context.Context, id string, args *UpdateApplicationArgs) error
	BulkUpdateState(ctx context.Context, m map[string]ContainerState) error
	DeleteApplication(ctx context.Context, id string) error
}

type Artifact

type Artifact struct {
	ID        string
	BuildID   string
	Size      int64
	CreatedAt time.Time
	DeletedAt optional.Of[time.Time]
}

func GetArtifactsInUse

func GetArtifactsInUse(ctx context.Context, appRepo ApplicationRepository, buildRepo BuildRepository) ([]*Artifact, error)

func NewArtifact

func NewArtifact(buildID string, size int64) *Artifact

type ArtifactRepository

type ArtifactRepository interface {
	GetArtifacts(ctx context.Context, cond GetArtifactCondition) ([]*Artifact, error)
	CreateArtifact(ctx context.Context, artifact *Artifact) error
	UpdateArtifact(ctx context.Context, id string, args UpdateArtifactArgs) error
	HardDeleteArtifacts(ctx context.Context, cond GetArtifactCondition) error
}

type AuthenticationType

type AuthenticationType int
const (
	AuthenticationTypeOff AuthenticationType = iota
	AuthenticationTypeSoft
	AuthenticationTypeHard
)

type AvailableDomain

type AvailableDomain struct {
	Domain    string
	Available bool
}

func (*AvailableDomain) Validate

func (a *AvailableDomain) Validate() error

type AvailableDomainRepository

type AvailableDomainRepository interface {
	GetAvailableDomains(ctx context.Context) (AvailableDomainSlice, error)
	AddAvailableDomain(ctx context.Context, ad *AvailableDomain) error
	DeleteAvailableDomain(ctx context.Context, domain string) error
}

type AvailableDomainSlice

type AvailableDomainSlice []*AvailableDomain

func (AvailableDomainSlice) IsAvailable

func (s AvailableDomainSlice) IsAvailable(fqdn string) bool

type AvailablePort added in v0.3.0

type AvailablePort struct {
	StartPort int
	EndPort   int
	Protocol  PortPublicationProtocol
}

func (*AvailablePort) Validate added in v0.3.0

func (ap *AvailablePort) Validate() error

type AvailablePortRepository added in v0.3.0

type AvailablePortRepository interface {
	GetAvailablePorts(ctx context.Context) (AvailablePortSlice, error)
	AddAvailablePort(ctx context.Context, ap *AvailablePort) error
	DeleteAvailablePort(ctx context.Context, ap *AvailablePort) error
}

type AvailablePortSlice added in v0.3.0

type AvailablePortSlice []*AvailablePort

func (AvailablePortSlice) IsAvailable added in v0.3.0

func (s AvailablePortSlice) IsAvailable(port int, protocol PortPublicationProtocol) bool

type Backend

type Backend interface {
	Start(ctx context.Context) error
	Dispose(ctx context.Context) error

	AuthAllowed(targetDomain string) bool
	ListenContainerEvents() (sub <-chan *ContainerEvent, unsub func())
	Synchronize(ctx context.Context, s *DesiredState) error
	GetContainer(ctx context.Context, appID string) (*Container, error)
	ListContainers(ctx context.Context) ([]*Container, error)
	ExecContainer(ctx context.Context, appID string, cmd []string, stdin io.Reader, stdout, stderr io.Writer) error
}

type Build

type Build struct {
	ID            string
	Commit        string
	Status        BuildStatus
	ApplicationID string
	QueuedAt      time.Time
	StartedAt     optional.Of[time.Time]
	UpdatedAt     optional.Of[time.Time]
	FinishedAt    optional.Of[time.Time]
	Retriable     bool
	Artifact      optional.Of[Artifact]
}

func NewBuild

func NewBuild(applicationID string, commit string) *Build

type BuildConfig

type BuildConfig interface {
	BuildType() BuildType
	Validate() error
	// contains filtered or unexported methods
}

type BuildConfigRuntimeBuildpack

type BuildConfigRuntimeBuildpack struct {
	Context string
	// contains filtered or unexported fields
}

func (*BuildConfigRuntimeBuildpack) BuildType

func (bc *BuildConfigRuntimeBuildpack) BuildType() BuildType

func (*BuildConfigRuntimeBuildpack) Validate

func (bc *BuildConfigRuntimeBuildpack) Validate() error

type BuildConfigRuntimeCmd

type BuildConfigRuntimeCmd struct {
	BaseImage     string
	BuildCmd      string
	BuildCmdShell bool
	// contains filtered or unexported fields
}

func (*BuildConfigRuntimeCmd) BuildType

func (bc *BuildConfigRuntimeCmd) BuildType() BuildType

func (*BuildConfigRuntimeCmd) Validate

func (bc *BuildConfigRuntimeCmd) Validate() error

type BuildConfigRuntimeDockerfile

type BuildConfigRuntimeDockerfile struct {
	DockerfileName string
	Context        string
	// contains filtered or unexported fields
}

func (*BuildConfigRuntimeDockerfile) BuildType

func (bc *BuildConfigRuntimeDockerfile) BuildType() BuildType

func (*BuildConfigRuntimeDockerfile) Validate

func (bc *BuildConfigRuntimeDockerfile) Validate() error

type BuildConfigStaticCmd

type BuildConfigStaticCmd struct {
	BaseImage     string
	BuildCmd      string
	BuildCmdShell bool
	ArtifactPath  string
	// contains filtered or unexported fields
}

func (*BuildConfigStaticCmd) BuildType

func (bc *BuildConfigStaticCmd) BuildType() BuildType

func (*BuildConfigStaticCmd) Validate

func (bc *BuildConfigStaticCmd) Validate() error

type BuildConfigStaticDockerfile

type BuildConfigStaticDockerfile struct {
	DockerfileName string
	Context        string
	ArtifactPath   string
	// contains filtered or unexported fields
}

func (*BuildConfigStaticDockerfile) BuildType

func (bc *BuildConfigStaticDockerfile) BuildType() BuildType

func (*BuildConfigStaticDockerfile) Validate

func (bc *BuildConfigStaticDockerfile) Validate() error

type BuildRepository

type BuildRepository interface {
	GetBuilds(ctx context.Context, cond GetBuildCondition) ([]*Build, error)
	GetBuild(ctx context.Context, buildID string) (*Build, error)
	CreateBuild(ctx context.Context, build *Build) error
	UpdateBuild(ctx context.Context, id string, args UpdateBuildArgs) error
	MarkCommitAsRetriable(ctx context.Context, applicationID string, commit string) error
	DeleteBuilds(ctx context.Context, cond GetBuildCondition) error
}

type BuildStatus

type BuildStatus int
const (
	BuildStatusQueued BuildStatus = iota
	BuildStatusBuilding
	BuildStatusSucceeded
	BuildStatusFailed
	BuildStatusCanceled
	BuildStatusSkipped
)

func (BuildStatus) IsFinished

func (t BuildStatus) IsFinished() bool

type BuildType

type BuildType int
const (
	BuildTypeRuntimeBuildpack BuildType = iota
	BuildTypeRuntimeCmd
	BuildTypeRuntimeDockerfile
	BuildTypeStaticCmd
	BuildTypeStaticDockerfile
)

func (BuildType) DeployType

func (b BuildType) DeployType() DeployType

type Container

type Container struct {
	ApplicationID string
	State         ContainerState
}

type ContainerEvent

type ContainerEvent struct {
	ApplicationID string
}

type ContainerLog

type ContainerLog struct {
	Time time.Time
	Log  string
}

type ContainerLogger

type ContainerLogger interface {
	Get(ctx context.Context, appID string, before time.Time) ([]*ContainerLog, error)
	Stream(ctx context.Context, appID string, after time.Time) (<-chan *ContainerLog, error)
}

type ContainerState

type ContainerState int
const (
	ContainerStateMissing ContainerState = iota
	ContainerStateStarting
	ContainerStateRunning
	ContainerStateExited
	ContainerStateErrored
	ContainerStateUnknown
)

type ControllerBuilderService

type ControllerBuilderService interface {
	pbconnect.ControllerBuilderServiceHandler
	ListenBuilderIdle() (sub <-chan struct{}, unsub func())
	ListenBuildSettled() (sub <-chan struct{}, unsub func())
	BroadcastBuilder(req *pb.BuilderRequest)
}

type ControllerBuilderServiceClient

type ControllerBuilderServiceClient interface {
	ConnectBuilder(ctx context.Context, onRequest func(req *pb.BuilderRequest), response <-chan *pb.BuilderResponse) error
}

type ControllerSSGenService

type ControllerSSGenService interface {
	pbconnect.ControllerSSGenServiceHandler
	BroadcastSSGen(req *pb.SSGenRequest)
}

type ControllerSSGenServiceClient

type ControllerSSGenServiceClient interface {
	ConnectSSGen(ctx context.Context, onRequest func(req *pb.SSGenRequest)) error
}

type ControllerServiceClient

type ControllerServiceClient interface {
	AuthAvailable(ctx context.Context, fqdn string) (bool, error)
	FetchRepository(ctx context.Context, repositoryID string) error
	RegisterBuilds(ctx context.Context) error
	SyncDeployments(ctx context.Context) error
	StreamBuildLog(ctx context.Context, buildID string) (<-chan *pb.BuildLog, error)
	CancelBuild(ctx context.Context, buildID string) error
}

type CreateArgs

type CreateArgs struct {
	// Database データベース/ユーザー名
	Database string
	// Password アクセスパスワード
	Password string
}

CreateArgs データベース作成引数

type CreateUserArgs

type CreateUserArgs struct {
	Name string
}

type DeleteArgs

type DeleteArgs struct {
	// Database データベース/ユーザー名
	Database string
}

DeleteArgs データベース削除引数

type DeployType

type DeployType int
const (
	DeployTypeRuntime DeployType = iota
	DeployTypeStatic
)

type DesiredState

type DesiredState struct {
	Runtime     []*RuntimeDesiredState
	StaticSites []*StaticSite
}

type Environment

type Environment struct {
	ApplicationID string
	Key           string
	Value         string
	System        bool
}

type EnvironmentRepository

type EnvironmentRepository interface {
	GetEnv(ctx context.Context, cond GetEnvCondition) ([]*Environment, error)
	SetEnv(ctx context.Context, env *Environment) error
	DeleteEnv(ctx context.Context, cond GetEnvCondition) error
}

type GetApplicationCondition

type GetApplicationCondition struct {
	IDIn         optional.Of[[]string]
	RepositoryID optional.Of[string]
	UserID       optional.Of[string]
	DeployType   optional.Of[DeployType]
	Running      optional.Of[bool]
	// InSync WantCommit が CurrentCommit に一致する
	InSync optional.Of[bool]
}

type GetArtifactCondition

type GetArtifactCondition struct {
	ApplicationID optional.Of[string]
	IsDeleted     optional.Of[bool]
}

type GetBuildCondition

type GetBuildCondition struct {
	ApplicationID optional.Of[string]
	Commit        optional.Of[string]
	CommitIn      optional.Of[[]string]
	Status        optional.Of[BuildStatus]
	Retriable     optional.Of[bool]
}

type GetEnvCondition

type GetEnvCondition struct {
	ApplicationIDIn optional.Of[[]string]
	ApplicationID   optional.Of[string]
	Key             optional.Of[string]
}

type GetRepositoryCondition

type GetRepositoryCondition struct {
	IDs    optional.Of[[]string]
	URLs   optional.Of[[]string]
	UserID optional.Of[string]
}

type GetUserCondition

type GetUserCondition struct {
	Admin optional.Of[bool]
}

type GetUserKeyCondition

type GetUserKeyCondition struct {
	UserIDs optional.Of[[]string]
}

type GitRepositoryRepository

type GitRepositoryRepository interface {
	GetRepositories(ctx context.Context, condition GetRepositoryCondition) ([]*Repository, error)
	GetRepository(ctx context.Context, id string) (*Repository, error)
	CreateRepository(ctx context.Context, repo *Repository) error
	UpdateRepository(ctx context.Context, id string, args *UpdateRepositoryArgs) error
	DeleteRepository(ctx context.Context, id string) error
}

type MariaDBManager

type MariaDBManager interface {
	GetHost() (host string, port int)
	// Create データベースが存在しない場合、作成します
	Create(ctx context.Context, args CreateArgs) error
	// Delete データベースが存在する場合、削除します
	Delete(ctx context.Context, args DeleteArgs) error
	// IsExist データベースが存在するか確認します
	IsExist(ctx context.Context, dbname string) (bool, error)
	Close(ctx context.Context) error
}

MariaDBManager MariaDBマネージャー

type MongoDBManager

type MongoDBManager interface {
	GetHost() (host string, port int)
	// Create データベースが存在しない場合、作成します
	Create(ctx context.Context, args CreateArgs) error
	// Delete データベースが存在する場合、削除します
	Delete(ctx context.Context, args DeleteArgs) error
	// IsExist データベースが存在するか確認します
	IsExist(ctx context.Context, dbname string) (bool, error)
	Close(ctx context.Context) error
}

MongoDBManager Mongoマネージャー

type PortPublication added in v0.3.0

type PortPublication struct {
	InternetPort    int
	ApplicationPort int
	Protocol        PortPublicationProtocol
}

func (*PortPublication) ConflictsWith added in v0.3.0

func (p *PortPublication) ConflictsWith(existing []*Application) bool

func (*PortPublication) ToUnavailablePort added in v0.3.0

func (p *PortPublication) ToUnavailablePort() *UnavailablePort

func (*PortPublication) Validate added in v0.3.0

func (p *PortPublication) Validate() error

type PortPublicationProtocol added in v0.3.0

type PortPublicationProtocol string
const (
	PortPublicationProtocolTCP PortPublicationProtocol = "tcp"
	PortPublicationProtocolUDP PortPublicationProtocol = "udp"
)

type PubSub

type PubSub[E any] struct {
	// contains filtered or unexported fields
}

PubSub is a simple pub-sub for single event type. A zero-value PubSub is ready for use.

func (*PubSub[E]) Publish

func (p *PubSub[E]) Publish(event E)

func (*PubSub[E]) Subscribe

func (p *PubSub[E]) Subscribe() (sub <-chan E, unsub func())

type Repository

type Repository struct {
	ID       string
	Name     string
	URL      string
	Auth     optional.Of[RepositoryAuth]
	OwnerIDs []string
}

func (*Repository) Apply

func (r *Repository) Apply(args *UpdateRepositoryArgs)

func (*Repository) IsOwner

func (r *Repository) IsOwner(user *User) bool

func (*Repository) Validate

func (r *Repository) Validate() error

type RepositoryAuth

type RepositoryAuth struct {
	Method   RepositoryAuthMethod
	Username string
	Password string
	SSHKey   string
}

func (*RepositoryAuth) Validate

func (r *RepositoryAuth) Validate() error

type RepositoryAuthMethod

type RepositoryAuthMethod int
const (
	RepositoryAuthMethodBasic RepositoryAuthMethod = iota
	RepositoryAuthMethodSSH
)

type RuntimeDesiredState

type RuntimeDesiredState struct {
	App       *Application
	ImageName string
	ImageTag  string
	Envs      map[string]string
}

type SSEngine

type SSEngine interface {
	Start(ctx context.Context) error
	Reconcile(sites []*StaticSite) error
	Shutdown(ctx context.Context) error
}

type SSHConfig

type SSHConfig struct {
	Port int `mapstructure:"port" yaml:"port"`
}

type StaticServerDocumentRootPath

type StaticServerDocumentRootPath string

type StaticServerPort

type StaticServerPort int

type StaticSite

type StaticSite struct {
	Application *Application
	Website     *Website
	ArtifactID  string
}

func GetActiveStaticSites

func GetActiveStaticSites(ctx context.Context, appRepo ApplicationRepository, buildRepo BuildRepository) ([]*StaticSite, error)

type Storage

type Storage interface {
	Save(filename string, src io.Reader) error
	Open(filename string) (io.ReadCloser, error)
	Delete(filename string) error
}

Storage ストレージインターフェース

type StorageConfig

type StorageConfig struct {
	Type  string `mapstructure:"type" yaml:"type"`
	Local struct {
		// Dir 保存ディレクトリ
		Dir string `mapstructure:"dir" yaml:"dir"`
	} `mapstructure:"local" yaml:"local"`
	S3 struct {
		// Bucket バケット名
		Bucket       string `mapstructure:"bucket" yaml:"bucket"`
		Endpoint     string `mapstructure:"endpoint" yaml:"endpoint"`
		Region       string `mapstructure:"region" yaml:"region"`
		AccessKey    string `mapstructure:"accessKey" yaml:"accessKey"`
		AccessSecret string `mapstructure:"accessSecret" yaml:"accessSecret"`
	} `mapstructure:"s3" yaml:"s3"`
	Swift struct {
		// UserName ユーザー名
		UserName string `mapstructure:"username" yaml:"username"`
		// APIKey APIキー(パスワード)
		APIKey string `mapstructure:"apiKey" yaml:"apiKey"`
		// TenantName テナント名
		TenantName string `mapstructure:"tenantName" yaml:"tenantName"`
		// TenantID テナントID
		TenantID string `mapstructure:"tenantId" yaml:"tenantId"`
		// Container コンテナ名
		Container string `mapstructure:"container" yaml:"container"`
		// AuthURL 認証エンドポイント
		AuthURL string `mapstructure:"authUrl" yaml:"authUrl"`
	} `mapstructure:"swift" yaml:"swift"`
}

type UnavailablePort added in v0.3.0

type UnavailablePort struct {
	Port     int
	Protocol PortPublicationProtocol
}

type UpdateApplicationArgs

type UpdateApplicationArgs struct {
	Name             optional.Of[string]
	RefName          optional.Of[string]
	Running          optional.Of[bool]
	Container        optional.Of[ContainerState]
	CurrentCommit    optional.Of[string]
	WantCommit       optional.Of[string]
	UpdatedAt        optional.Of[time.Time]
	Config           optional.Of[ApplicationConfig]
	Websites         optional.Of[[]*Website]
	PortPublications optional.Of[[]*PortPublication]
	OwnerIDs         optional.Of[[]string]
}

type UpdateArtifactArgs

type UpdateArtifactArgs struct {
	DeletedAt optional.Of[time.Time]
}

type UpdateBuildArgs

type UpdateBuildArgs struct {
	FromStatus optional.Of[BuildStatus]
	Status     optional.Of[BuildStatus]
	StartedAt  optional.Of[time.Time]
	UpdatedAt  optional.Of[time.Time]
	FinishedAt optional.Of[time.Time]
}

type UpdateRepositoryArgs

type UpdateRepositoryArgs struct {
	Name     optional.Of[string]
	URL      optional.Of[string]
	Auth     optional.Of[optional.Of[RepositoryAuth]]
	OwnerIDs optional.Of[[]string]
}

type User

type User struct {
	ID    string
	Name  string
	Admin bool
}

func NewUser

func NewUser(name string) *User

type UserKey

type UserKey struct {
	ID        string
	UserID    string
	PublicKey string
}

func NewUserKey

func NewUserKey(userID string, publicKey string) (*UserKey, error)

func (*UserKey) MarshalKey

func (u *UserKey) MarshalKey() []byte

func (*UserKey) Validate

func (u *UserKey) Validate() error

type UserRepository

type UserRepository interface {
	GetOrCreateUser(ctx context.Context, name string) (*User, error)
	GetUsers(ctx context.Context, cond GetUserCondition) ([]*User, error)
	GetUserKeys(ctx context.Context, cond GetUserKeyCondition) ([]*UserKey, error)
	CreateUserKey(ctx context.Context, key *UserKey) error
	DeleteUserKey(ctx context.Context, keyID string, userID string) error
}

type Website

type Website struct {
	ID             string
	FQDN           string
	PathPrefix     string
	StripPrefix    bool
	HTTPS          bool
	H2C            bool
	HTTPPort       int
	Authentication AuthenticationType
}

func (*Website) Equals

func (w *Website) Equals(target *Website) bool

func (*Website) Validate

func (w *Website) Validate() error

type WildcardDomains

type WildcardDomains []string

func (WildcardDomains) TLSTargetDomain

func (wd WildcardDomains) TLSTargetDomain(website *Website) string

func (WildcardDomains) Validate

func (wd WildcardDomains) Validate() error

Directories

Path Synopsis
Package mock_domain is a generated GoMock package.
Package mock_domain is a generated GoMock package.

Jump to

Keyboard shortcuts

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