Skip to content

Commit

Permalink
add postgres package test
Browse files Browse the repository at this point in the history
  • Loading branch information
tedim52 committed Feb 16, 2024
1 parent 1b437e4 commit f4b3152
Show file tree
Hide file tree
Showing 4 changed files with 365 additions and 277 deletions.
2 changes: 1 addition & 1 deletion core/server/api_container/server/api_container_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ func (apicService *ApiContainerService) RunStarlarkPackage(args *kurtosis_core_r
logrus.Warn("An error occurred tracking kurtosis run event")
}

logrus.Infof("package id: %v\n main func name: %v\n actual relative path to main file: %v\n script with run func: %v\n serialized params:%v\n%v",
logrus.Infof("package id: %v\n main func name: %v\n actual relative path to main file: %v\n script with run func: %v\n serialized params:%v\n",
detectedPackageId,
mainFuncName,
actualRelativePathToMainFile,
Expand Down
26 changes: 14 additions & 12 deletions core/server/api_container/server/startosis_engine/plan_yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ type PlanYaml struct {

// Service represents a service in the system.
type Service struct {
Uuid string `yaml:"uuid,omitempty"`
Name string `yaml:"name,omitempty"`
Image string `yaml:"image,omitempty"`
EnvVars []*EnvironmentVariable `yaml:"envVars,omitempty"`
Ports []*Port `yaml:"ports,omitempty"`
Files []*FileMount `yaml:"files,omitempty"`
Uuid string `yaml:"uuid,omitempty"` // done
Name string `yaml:"name,omitempty"` // done
Image string `yaml:"image,omitempty"` // done
Cmd []string `yaml:"command,omitempty"` // done
Entrypoint []string `yaml:"entrypoint,omitempty"` // done
EnvVars []*EnvironmentVariable `yaml:"envVars,omitempty"` // done
Ports []*Port `yaml:"ports,omitempty"` // done
Files []*FileMount `yaml:"files,omitempty"`
}

// FilesArtifact represents a collection of files.
Expand All @@ -41,10 +43,11 @@ type EnvironmentVariable struct {

// Port represents a port.
type Port struct {
TransportProtocol ApplicationProtocol `yaml:"transportProtocol,omitempty"`
Name string `yaml:"name,omitempty"`
Number uint16 `yaml:"number,omitempty"`

PortName string `yaml:"portName,omitempty"`
PortNum uint16 `yaml:"portNum,omitempty"`
TransportProtocol TransportProtocol `yaml:"transportProtocol,omitempty"`
ApplicationProtocol ApplicationProtocol `yaml:"applicationProtocol,omitempty"`
}

// ApplicationProtocol represents the application protocol used.
Expand All @@ -55,9 +58,8 @@ type TransportProtocol string

// FileMount represents a mount point for files.
type FileMount struct {
MountPath string `yaml:"mountPath,omitempty"`
FilesArtifactUuid string `yaml:"filesArtifactUuid,omitempty"`
FilesArtifactName string `yaml:"filesArtifactName,omitempty"`
MountPath string `yaml:"mountPath,omitempty"`
filesArtifacts []*FilesArtifact // TODO: support persistent directories
}

// Task represents a task to be executed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ type PlanYamlGeneratorImpl struct {

packageReplaceOptions map[string]string

// index of files artifact uuid
// this provides a look up to see what files artifacts have been processed
filesArtifactIndex map[string]bool

// Representation of plan in yaml the plan is being processed, the yaml gets updated
planYaml *PlanYaml
}
Expand Down Expand Up @@ -134,7 +138,8 @@ func (pyg *PlanYamlGeneratorImpl) updatePlanYamlFromAddService(addServiceInstruc

// start building Service Yaml object
service := &Service{}
service.Uuid = string(addServiceInstruction.GetUuid()) // uuid of the object is the uuid of the instruction that created that object
// TODO: mock uuid generator so I can add uuids
//service.Uuid = string(addServiceInstruction.GetUuid()) // uuid of the object is the uuid of the instruction that created that object

serviceName, err := builtin_argument.ExtractArgumentValue[starlark.String](arguments, add_service.ServiceNameArgName)
if err != nil {
Expand All @@ -146,24 +151,71 @@ func (pyg *PlanYamlGeneratorImpl) updatePlanYamlFromAddService(addServiceInstruc
if err != nil {
return startosis_errors.WrapWithInterpretationError(err, "Unable to extract value for '%s' argument", add_service.ServiceConfigArgName)
}
serviceConfig, err := starlarkServiceConfig.ToKurtosisType( // is this an expensive call
serviceConfig, err := starlarkServiceConfig.ToKurtosisType( // is this an expensive call? it's made twice - once during interpretation
pyg.serviceNetwork,
pyg.locatorOfModuleInWhichThisBuiltInIsBeingCalled,
pyg.planYaml.PackageId,
pyg.packageContentProvider,
pyg.packageReplaceOptions)

service.Image = serviceConfig.GetContainerImageName() // TODO: support image build specs
service.Cmd = serviceConfig.GetCmdArgs()
service.Entrypoint = serviceConfig.GetEntrypointArgs()

// ports
service.Ports = []*Port{}
for portName, configPort := range serviceConfig.GetPrivatePorts() { // TODO: support public ports
port := &Port{
TransportProtocol: ApplicationProtocol(configPort.GetTransportProtocol().String()),
PortName: portName,
PortNum: configPort.GetNumber(),
TransportProtocol: TransportProtocol(configPort.GetTransportProtocol().String()),
ApplicationProtocol: ApplicationProtocol(*configPort.GetMaybeApplicationProtocol()),
Name: portName,
Number: configPort.GetNumber(),
}
service.Ports = append(service.Ports, port)
}

// env vars
service.EnvVars = []*EnvironmentVariable{}
for key, val := range serviceConfig.GetEnvVars() {
envVar := &EnvironmentVariable{
Key: key,
Value: val,
}
service.EnvVars = append(service.EnvVars, envVar)
}

// adding a file, also means adding a files artifact IF it doesn't exist already
// 1. create the files artifact, with the correct identifier
// 2. add the files artifact to the plan yaml if it doesn't alrady exist
service.Files = []*FileMount{}
// but the question is where did the artifact identifier come from? is it a new one or is it an old one?
// if it's an old one that was already created, how do we know that it was already created
// but there's a difference between it being created and it coming from somewhere
for mountPath, artifactIdentifiers := range serviceConfig.GetFilesArtifactsExpansion().ServiceDirpathsToArtifactIdentifiers {
// create files artifact objects
filesArtifacts := []*FilesArtifact{}
for _, identifier := range artifactIdentifiers {
filesArtifact := &FilesArtifact{
Uuid: identifier,
Name: "", // TODO: how do we get this if the FilesArtifact wasn't created by a different instruction
Files: map[string]string{}, // TODO: how do we get this if FilesArtifact wasn't created by a different instruction
}
// if the files artifact haven't already been tracked, add it to list of known files artifacts
if _, ok := pyg.filesArtifactIndex[identifier]; !ok {
pyg.planYaml.FilesArtifacts = append(pyg.planYaml.FilesArtifacts, filesArtifact)
pyg.filesArtifactIndex[identifier] = true
}
filesArtifacts = append(filesArtifacts, filesArtifact)
}

fileMount := &FileMount{
MountPath: mountPath,
filesArtifacts: filesArtifacts,
}
service.Files = append(service.Files, fileMount)
}

pyg.planYaml.Services = append(pyg.planYaml.Services, service)
return nil
}

Expand Down
Loading

0 comments on commit f4b3152

Please sign in to comment.