Skip to content

Commit

Permalink
generate template section from necessary pieces instead of just assum…
Browse files Browse the repository at this point in the history
…ing it's there
  • Loading branch information
DireLines committed Aug 21, 2024
1 parent d1d9e4a commit 9176272
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions cmd/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ func init() {
projectCmd.AddCommand(project.StartProjectCmd)
projectCmd.AddCommand(project.DeployProjectCmd)
projectCmd.AddCommand(project.BuildProjectCmd)
projectCmd.AddCommand(project.GenerateEndpointConfigCmd)
}
11 changes: 9 additions & 2 deletions cmd/project/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ func deployProject(networkVolumeId string) (endpointId string, err error) {

// }

func buildEndpointConfig(projectFolder string) (err error) {
func buildEndpointConfig(projectFolder string, projectId string) (err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("panic: %v", r)
Expand All @@ -638,7 +638,14 @@ func buildEndpointConfig(projectFolder string) (err error) {
// parse project toml
config := loadProjectConfig()
endpointConfig := mustGetPathAs[*toml.Tree](config, "endpoint")
templateConfig := mustGetPathAs[*toml.Tree](config, "template")

templateConfig := toml.Tree{}
templateConfig.Set("name", fmt.Sprintf("%s-endpoint-%s-%d", projectName, projectId, time.Now().UnixMilli()))
templateConfig.Set("image_name", mustGetPathAs[string](config, "project", "base_image")) //TODO: make it a parameter
templateConfig.Set("env", mustGetPathAs[*toml.Tree](config, "project", "env_vars"))
templateConfig.Set("docker_start_cmd", mustGetPathAs[string](config, "project", "docker_start_cmd"))
templateConfig.Set("container_disk_in_gb", mustGetPathAs[int64](config, "project", "container_disk_size_gb"))
templateConfig.Set("volume_mount_path", mustGetPathAs[string](config, "project", "volume_mount_path"))
// dump these into their own toml
resultTree := toml.Tree{}
resultTree.Set("endpoint", endpointConfig)
Expand Down
16 changes: 16 additions & 0 deletions cmd/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,22 @@ var DeployProjectCmd = &cobra.Command{
},
}

var GenerateEndpointConfigCmd = &cobra.Command{
Use: "generate-endpoint-config",
Args: cobra.ExactArgs(0),
Short: "generates an endpoint configuration file for the current project",
Long: "generates an endpoint configuration file for the current project",
Run: func(cmd *cobra.Command, args []string) {
projectDir, err := os.Getwd()
if err != nil {
fmt.Println("Error getting current directory:", err)
return
}
projectConfig := loadProjectConfig()
projectId := mustGetPathAs[string](projectConfig, "project", "uuid")
buildEndpointConfig(projectDir, projectId)
},
}
var BuildProjectCmd = &cobra.Command{
Use: "build",
Args: cobra.ExactArgs(0),
Expand Down

0 comments on commit 9176272

Please sign in to comment.