Skip to content
25 changes: 25 additions & 0 deletions api/proto/neoshowcase/protobuf/gateway.proto
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ message SimpleCommit {
enum DeployType {
RUNTIME = 0;
STATIC = 1;
FUNCTION = 2;
}

message AutoShutdownConfig {
Expand Down Expand Up @@ -137,6 +138,10 @@ message StaticConfig {
bool spa = 2;
}

message FunctionConfig {
string artifact_path = 1;
}

message BuildConfigStaticBuildpack {
StaticConfig static_config = 1;
string context = 2;
Expand All @@ -154,6 +159,23 @@ message BuildConfigStaticDockerfile {
string context = 3;
}

message BuildConfigFunctionBuildpack {
FunctionConfig function_config = 1;
string context = 2;
}

message BuildConfigFunctionCmd {
FunctionConfig function_config = 1;
string base_image = 2;
string build_cmd = 3;
}

message BuildConfigFunctionDockerfile {
FunctionConfig function_config = 1;
string dockerfile_name = 2;
string context = 3;
}

message ApplicationConfig {
oneof build_config {
BuildConfigRuntimeBuildpack runtime_buildpack = 1;
Expand All @@ -162,6 +184,9 @@ message ApplicationConfig {
BuildConfigStaticBuildpack static_buildpack = 4;
BuildConfigStaticCmd static_cmd = 5;
BuildConfigStaticDockerfile static_dockerfile = 6;
BuildConfigFunctionBuildpack function_buildpack = 7;
BuildConfigFunctionCmd function_cmd = 8;
BuildConfigFunctionDockerfile function_dockerfile = 9;
}
}

Expand Down
238 changes: 177 additions & 61 deletions dashboard/src/api/neoshowcase/protobuf/gateway_pb.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,14 @@ export const configMessageToSchema = (config: ApplicationConfig): ApplicationCon
},
}),
)
.with(
{
case: P.union('functionBuildpack', 'functionDockerfile', 'functionCmd'),
},
(buildConfig) => {
throw new Error(`Currently function build config type ${buildConfig.case} is not supported`)
},
)
.with({ case: undefined }, () => undefined)
.exhaustive()

Expand Down Expand Up @@ -326,6 +334,14 @@ export const configMessageToSchema = (config: ApplicationConfig): ApplicationCon
},
}),
)
.with(
{
case: P.union('functionBuildpack', 'functionCmd', 'functionDockerfile'),
},
(buildConfig) => {
throw new Error(`Currently function build config type ${buildConfig.case} is not supported`)
},
)
.with({ case: undefined }, () => undefined)
.exhaustive()

Expand Down
29 changes: 18 additions & 11 deletions migrations/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ CREATE TABLE `repository_owners`

CREATE TABLE `repository_commits`
(
`hash` CHAR(40) PRIMARY KEY COMMENT 'Commit SHA-1 Hash',
`author_name` VARCHAR(256) NOT NULL COMMENT 'Author Name',
`author_email` VARCHAR(256) NOT NULL COMMENT 'Author Email',
`author_date` DATETIME(6) NOT NULL COMMENT 'Author Date',
`committer_name` VARCHAR(256) NOT NULL COMMENT 'Committer Name',
`committer_email` VARCHAR(256) NOT NULL COMMENT 'Committer Email',
`committer_date` DATETIME(6) NOT NULL COMMENT 'Commit Date',
`message` TEXT NOT NULL COMMENT 'Commit Message',
`error` TINYINT(1) NOT NULL COMMENT 'メタ情報取得に失敗したか'
`hash` CHAR(40) PRIMARY KEY COMMENT 'Commit SHA-1 Hash',
`author_name` VARCHAR(256) NOT NULL COMMENT 'Author Name',
`author_email` VARCHAR(256) NOT NULL COMMENT 'Author Email',
`author_date` DATETIME(6) NOT NULL COMMENT 'Author Date',
`committer_name` VARCHAR(256) NOT NULL COMMENT 'Committer Name',
`committer_email` VARCHAR(256) NOT NULL COMMENT 'Committer Email',
`committer_date` DATETIME(6) NOT NULL COMMENT 'Commit Date',
`message` TEXT NOT NULL COMMENT 'Commit Message',
`error` TINYINT(1) NOT NULL COMMENT 'メタ情報取得に失敗したか'
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_general_ci COMMENT = 'コミットメタ情報テーブル';
Expand All @@ -79,7 +79,11 @@ CREATE TABLE `applications`
`repository_id` VARCHAR(22) NOT NULL COMMENT 'リポジトリID',
`ref_name` VARCHAR(100) NOT NULL COMMENT 'Gitブランチ・タグ名',
`commit` CHAR(40) NOT NULL COMMENT '解決されたコミット',
`deploy_type` ENUM ('runtime', 'static') NOT NULL COMMENT 'デプロイタイプ',
`deploy_type` ENUM (
'runtime',
'static',
'function'
) NOT NULL COMMENT 'デプロイタイプ',
`running` TINYINT(1) NOT NULL COMMENT 'アプリを起動させるか(desired state)',
`container` ENUM (
'missing',
Expand Down Expand Up @@ -117,7 +121,10 @@ CREATE TABLE `application_config`
'runtime-dockerfile',
'static-buildpack',
'static-cmd',
'static-dockerfile'
'static-dockerfile',
'function-buildpack',
'function-cmd',
'function-dockerfile'
) NOT NULL COMMENT 'ビルドタイプ',
`base_image` VARCHAR(1000) NOT NULL COMMENT 'ベースイメージの名前',
`build_cmd` TEXT NOT NULL COMMENT 'ビルドコマンド',
Expand Down
1 change: 1 addition & 0 deletions pkg/domain/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type DeployType int
const (
DeployTypeRuntime DeployType = iota
DeployTypeStatic
DeployTypeFunction
)

var EmptyCommit = strings.Repeat("0", 40)
Expand Down
2 changes: 2 additions & 0 deletions pkg/domain/app_artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (

const BuilderStaticArtifactName = "website.tar.gz"

const BuilderFunctionArtifactName = "function.tar.gz"

type Artifact struct {
ID string
Name string
Expand Down
107 changes: 107 additions & 0 deletions pkg/domain/app_build_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ const (
BuildTypeStaticBuildpack
BuildTypeStaticCmd
BuildTypeStaticDockerfile
BuildTypeFunctionBuildpack
BuildTypeFunctionCmd
BuildTypeFunctionDockerfile
)

func (b BuildType) DeployType() DeployType {
Expand All @@ -26,6 +29,8 @@ func (b BuildType) DeployType() DeployType {
return DeployTypeRuntime
case BuildTypeStaticBuildpack, BuildTypeStaticCmd, BuildTypeStaticDockerfile:
return DeployTypeStatic
case BuildTypeFunctionBuildpack, BuildTypeFunctionCmd, BuildTypeFunctionDockerfile:
return DeployTypeFunction
default:
panic(fmt.Sprintf("unknown build type: %v", b))
}
Expand Down Expand Up @@ -107,6 +112,10 @@ func (rc *RuntimeConfig) GetStaticConfig() StaticConfig {
panic("not static config")
}

func (rc *RuntimeConfig) GetFunctionConfig() FunctionConfig {
panic("not function config")
}

type StaticConfig struct {
ArtifactPath string
SPA bool
Expand Down Expand Up @@ -135,6 +144,41 @@ func (sc *StaticConfig) GetStaticConfig() StaticConfig {
return *sc
}

func (sc *StaticConfig) GetFunctionConfig() FunctionConfig {
panic("not function config")
}

type FunctionConfig struct {
ArtifactPath string
}

func (fc *FunctionConfig) Validate() error {
if fc.ArtifactPath == "" {
return errors.New("artifact_path is required for function builds")
}
return nil
}

func (fc *FunctionConfig) MariaDB() bool {
return false
}

func (fc *FunctionConfig) MongoDB() bool {
return false
}

func (fc *FunctionConfig) GetRuntimeConfig() RuntimeConfig {
panic("not runtime config")
}

func (fc *FunctionConfig) GetStaticConfig() StaticConfig {
panic("not static config")
}

func (fc *FunctionConfig) GetFunctionConfig() FunctionConfig {
return *fc
}

type BuildConfig interface {
isBuildConfig()
BuildType() BuildType
Expand All @@ -145,6 +189,7 @@ type BuildConfig interface {

GetRuntimeConfig() RuntimeConfig
GetStaticConfig() StaticConfig
GetFunctionConfig() FunctionConfig
}

type buildConfigEmbed struct{}
Expand Down Expand Up @@ -277,3 +322,65 @@ func (bc *BuildConfigStaticDockerfile) Validate() error {
}
return nil
}

type BuildConfigFunctionBuildpack struct {
FunctionConfig
Context string
buildConfigEmbed
}

func (bc *BuildConfigFunctionBuildpack) BuildType() BuildType {
return BuildTypeFunctionBuildpack
}

func (bc *BuildConfigFunctionBuildpack) Validate() error {
if err := bc.FunctionConfig.Validate(); err != nil {
return err
}
// NOTE: context is not necessary
return nil
}

type BuildConfigFunctionCmd struct {
FunctionConfig
BaseImage string
BuildCmd string
buildConfigEmbed
}

func (bc *BuildConfigFunctionCmd) BuildType() BuildType {
return BuildTypeFunctionCmd
}

func (bc *BuildConfigFunctionCmd) Validate() error {
if err := bc.FunctionConfig.Validate(); err != nil {
return err
}
// NOTE: base image is not necessary (default: scratch)
// NOTE: build cmd is not necessary
if bc.ArtifactPath == "" {
return errors.New("artifact_path is required")
}
return nil
}

type BuildConfigFunctionDockerfile struct {
FunctionConfig
DockerfileName string
Context string
buildConfigEmbed
}

func (bc *BuildConfigFunctionDockerfile) BuildType() BuildType {
return BuildTypeFunctionDockerfile
}

func (bc *BuildConfigFunctionDockerfile) Validate() error {
if err := bc.FunctionConfig.Validate(); err != nil {
return err
}
if bc.DockerfileName == "" {
return errors.New("dockerfile_name is required")
}
return nil
}
Loading