Skip to content

Commit

Permalink
Feat/handle new fields in duplication and creation (#138)
Browse files Browse the repository at this point in the history
* feat(create with stack): handle image selection type

* feat(duplication): handle image selection type
  • Loading branch information
RomainDreidemy authored Oct 12, 2023
1 parent 7c01c10 commit d0b13a2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 17 deletions.
30 changes: 25 additions & 5 deletions api/src/services/create_by_file/create_stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,39 @@ func createServices(composeServices map[string]models.DockerComposeService, stac

index := 0
for key, composeService := range composeServices {
image := strings.Split(composeService.Image, ":")
imageSelectionType := "remote"

services = append(services, models.Service{
newService := models.Service{
StackID: stackId,
Name: key,
ContainerName: composeService.ContainerName,
DockerImage: image[0],
DockerTag: image[1],
EnvFile: composeService.EnvFile,
Entrypoint: composeService.Entrypoint,
PositionY: 10,
PositionX: float32(250*(index) + 10),
})
}

if composeService.Image != "" {
image := strings.Split(composeService.Image, ":")
tag := "latest"

if len(image) > 1 {
tag = image[1]
}

newService.DockerImage = image[0]
newService.DockerTag = tag
}

if composeService.Build != (models.DockerComposeServiceBuild{}) {
newService.Context = composeService.Build.Context
newService.Dockerfile = composeService.Build.Dockerfile
imageSelectionType = "local"
}

newService.ImageSelectionType = imageSelectionType

services = append(services, newService)

index += 1
}
Expand Down
25 changes: 13 additions & 12 deletions api/src/services/duplication/duplication.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,19 @@ func DuplicateStack(stack models.Stack) models.Stack {

func duplicateService(service models.Service, stackId string) models.Service {
return models.Service{
StackID: stackId,
Name: service.Name,
ContainerName: service.ContainerName,
Description: service.Description,
DockerImage: service.DockerImage,
DockerTag: service.DockerTag,
EnvFile: service.EnvFile,
Entrypoint: service.Entrypoint,
Context: service.Context,
Dockerfile: service.Dockerfile,
PositionX: service.PositionX,
PositionY: service.PositionY,
StackID: stackId,
Name: service.Name,
ContainerName: service.ContainerName,
ImageSelectionType: service.ImageSelectionType,
Description: service.Description,
DockerImage: service.DockerImage,
DockerTag: service.DockerTag,
EnvFile: service.EnvFile,
Entrypoint: service.Entrypoint,
Context: service.Context,
Dockerfile: service.Dockerfile,
PositionX: service.PositionX,
PositionY: service.PositionY,
}
}

Expand Down

0 comments on commit d0b13a2

Please sign in to comment.