Skip to content

Commit

Permalink
Feat/i want to change the container name (#123)
Browse files Browse the repository at this point in the history
* feat(service): add containerName field

* feat(service): handle container name in docker compose

* feat(service): add container name field
  • Loading branch information
RomainDreidemy authored Sep 14, 2023
1 parent cb006e7 commit 4a4dc2e
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 83 deletions.
2 changes: 1 addition & 1 deletion .idea/dataSources.local.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions api/docs/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions api/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1638,6 +1638,9 @@
"positionY"
],
"properties": {
"containerName": {
"type": "string"
},
"description": {
"type": "string"
},
Expand Down Expand Up @@ -1874,6 +1877,9 @@
"models.ServiceResponse": {
"type": "object",
"properties": {
"containerName": {
"type": "string"
},
"description": {
"type": "string"
},
Expand Down Expand Up @@ -1903,6 +1909,9 @@
"models.ServiceResponseItem": {
"type": "object",
"properties": {
"containerName": {
"type": "string"
},
"description": {
"type": "string"
},
Expand Down Expand Up @@ -1950,6 +1959,9 @@
"models.ServiceUpdateInput": {
"type": "object",
"properties": {
"containerName": {
"type": "string"
},
"context": {
"type": "string"
},
Expand Down
8 changes: 8 additions & 0 deletions api/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ definitions:
type: object
models.ServiceCreateInput:
properties:
containerName:
type: string
description:
type: string
dockerImage:
Expand Down Expand Up @@ -290,6 +292,8 @@ definitions:
type: object
models.ServiceResponse:
properties:
containerName:
type: string
description:
type: string
dockerImage:
Expand All @@ -309,6 +313,8 @@ definitions:
type: object
models.ServiceResponseItem:
properties:
containerName:
type: string
description:
type: string
dockerImage:
Expand Down Expand Up @@ -340,6 +346,8 @@ definitions:
type: object
models.ServiceUpdateInput:
properties:
containerName:
type: string
context:
type: string
description:
Expand Down
89 changes: 47 additions & 42 deletions api/src/models/service_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ package models
import "github.com/google/uuid"

type Service struct {
ID *uuid.UUID `gorm:"type:uuid;default:uuid_generate_v4();primary_key"`
Name string `gorm:"type:varchar(255)"`
DockerImage string `gorm:"type:varchar(255)"`
DockerTag string `gorm:"type:varchar(255)"`
Entrypoint string `gorm:"type:varchar(255)"`
Description string `gorm:"type:text"`
PositionX float32 `gorm:"type:decimal(20,8);not null"`
PositionY float32 `gorm:"type:decimal(20,8);not null"`
Context string `gorm:"type:varchar(255)"`
Dockerfile string `gorm:"type:varchar(255)"`
ID *uuid.UUID `gorm:"type:uuid;default:uuid_generate_v4();primary_key"`
Name string `gorm:"type:varchar(255)"`
ContainerName string `gorm:"type:varchar(255)"`
DockerImage string `gorm:"type:varchar(255)"`
DockerTag string `gorm:"type:varchar(255)"`
Entrypoint string `gorm:"type:varchar(255)"`
Description string `gorm:"type:text"`
PositionX float32 `gorm:"type:decimal(20,8);not null"`
PositionY float32 `gorm:"type:decimal(20,8);not null"`
Context string `gorm:"type:varchar(255)"`
Dockerfile string `gorm:"type:varchar(255)"`

StackID string `gorm:"type:uuid;not null"`
Stack Stack
Expand All @@ -26,47 +27,51 @@ type Service struct {
}

type ServiceCreateInput struct {
Name string `json:"name"`
DockerImage string `json:"dockerImage"`
DockerTag string `json:"dockerTag"`
Entrypoint string `json:"entrypoint"`
Description string `json:"description"`
PositionX float32 `json:"positionX" validate:"required"`
PositionY float32 `json:"positionY" validate:"required"`
Name string `json:"name"`
ContainerName string `json:"containerName"`
DockerImage string `json:"dockerImage"`
DockerTag string `json:"dockerTag"`
Entrypoint string `json:"entrypoint"`
Description string `json:"description"`
PositionX float32 `json:"positionX" validate:"required"`
PositionY float32 `json:"positionY" validate:"required"`
}

type ServiceUpdateInput struct {
Name string `json:"name"`
DockerImage string `json:"dockerImage"`
DockerTag string `json:"dockerTag"`
Context string `json:"context"`
Dockerfile string `json:"dockerfile"`
Entrypoint string `json:"entrypoint"`
Description string `json:"description"`
PositionX float32 `json:"positionX"`
PositionY float32 `json:"positionY"`
Name string `json:"name"`
ContainerName string `json:"containerName"`
DockerImage string `json:"dockerImage"`
DockerTag string `json:"dockerTag"`
Context string `json:"context"`
Dockerfile string `json:"dockerfile"`
Entrypoint string `json:"entrypoint"`
Description string `json:"description"`
PositionX float32 `json:"positionX"`
PositionY float32 `json:"positionY"`
}

type ServiceResponse struct {
ID *uuid.UUID `json:"id"`
Name string `json:"name"`
DockerImage string `json:"dockerImage"`
DockerTag string `json:"dockerTag"`
Entrypoint string `json:"entrypoint"`
Description string `json:"description"`
PositionX float32 `json:"positionX"`
PositionY float32 `json:"positionY"`
ID *uuid.UUID `json:"id"`
Name string `json:"name"`
ContainerName string `json:"containerName"`
DockerImage string `json:"dockerImage"`
DockerTag string `json:"dockerTag"`
Entrypoint string `json:"entrypoint"`
Description string `json:"description"`
PositionX float32 `json:"positionX"`
PositionY float32 `json:"positionY"`
}

type ServiceResponseItem struct {
ID *uuid.UUID `json:"id"`
Name string `json:"name"`
DockerImage string `json:"dockerImage"`
DockerTag string `json:"dockerTag"`
Entrypoint string `json:"entrypoint"`
Description string `json:"description"`
PositionX float32 `json:"positionX"`
PositionY float32 `json:"positionY"`
ID *uuid.UUID `json:"id"`
Name string `json:"name"`
ContainerName string `json:"containerName"`
DockerImage string `json:"dockerImage"`
DockerTag string `json:"dockerTag"`
Entrypoint string `json:"entrypoint"`
Description string `json:"description"`
PositionX float32 `json:"positionX"`
PositionY float32 `json:"positionY"`

Volumes []ServiceVolumeResponse `json:"volumes"`
EnvVariables []ServiceEnvVariableResponse `json:"envVariables"`
Expand Down
6 changes: 5 additions & 1 deletion api/src/services/docker_compose/builders/service_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ func DockerComposeServicesBuilder(services []models.Service) map[string]models.D
}

func DockerComposeServiceBuilder(service models.Service) models.DockerComposeService {
if service.ContainerName == "" {
service.ContainerName = service.Name
}

dockerComposeService := models.DockerComposeService{
ContainerName: service.Name,
ContainerName: service.ContainerName,
Entrypoint: service.Entrypoint,
}

Expand Down
16 changes: 16 additions & 0 deletions api/src/services/docker_compose/builders/service_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,22 @@ func TestDockerComposeServicesBuilder(t *testing.T) {
},
},
},
{
name: "should use the container name if specified",
args: args{
services: []models.Service{
{
Name: "api",
ContainerName: "Api container name",
},
},
},
want: map[string]models.DockerComposeService{
"api": {
ContainerName: "Api container name",
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
68 changes: 29 additions & 39 deletions api/src/services/factories/service_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@ import (

func BuildServiceResponse(service models.Service) models.ServiceResponseItem {
return models.ServiceResponseItem{
ID: service.ID,
Name: service.Name,
DockerImage: service.DockerImage,
DockerTag: service.DockerTag,
Entrypoint: service.Entrypoint,
Description: service.Description,
PositionX: service.PositionX,
PositionY: service.PositionY,
Volumes: BuildServiceVolumeResponses(service.ServiceVolumes),
EnvVariables: BuildServiceEnvVariableResponses(service.ServiceEnvVariables),
Ports: BuildServicePortResponses(service.ServicePorts),
ID: service.ID,
Name: service.Name,
ContainerName: service.ContainerName,
DockerImage: service.DockerImage,
DockerTag: service.DockerTag,
Entrypoint: service.Entrypoint,
Description: service.Description,
PositionX: service.PositionX,
PositionY: service.PositionY,
Volumes: BuildServiceVolumeResponses(service.ServiceVolumes),
EnvVariables: BuildServiceEnvVariableResponses(service.ServiceEnvVariables),
Ports: BuildServicePortResponses(service.ServicePorts),
}
}

Expand All @@ -28,40 +29,29 @@ func BuildServiceResponses(services []models.Service) []models.ServiceResponseIt
return serializedServices
}

func BuildServiceBoardResponses(services []models.Service) []models.BoardItem {
serializedServices := make([]models.BoardItem, 0)
for i := 0; i < len(services); i++ {
serializedServices = append(serializedServices, models.BoardItem{
ID: services[i].ID,
Name: services[i].Name,
PositionX: services[i].PositionX,
PositionY: services[i].PositionY,
})
}
return serializedServices
}

func BuildServiceFromServiceCreationInput(service models.ServiceCreateInput, stackId string) models.Service {
return models.Service{
Name: service.Name,
DockerImage: service.DockerImage,
DockerTag: service.DockerTag,
Entrypoint: service.Entrypoint,
Description: service.Description,
PositionX: service.PositionX,
PositionY: service.PositionY,
StackID: stackId,
Name: service.Name,
ContainerName: service.ContainerName,
DockerImage: service.DockerImage,
DockerTag: service.DockerTag,
Entrypoint: service.Entrypoint,
Description: service.Description,
PositionX: service.PositionX,
PositionY: service.PositionY,
StackID: stackId,
}
}

func BuildServiceFromServiceUpdateInput(service models.ServiceUpdateInput) models.Service {
return models.Service{
Name: service.Name,
DockerImage: service.DockerImage,
DockerTag: service.DockerTag,
Entrypoint: service.Entrypoint,
Description: service.Description,
PositionX: service.PositionX,
PositionY: service.PositionY,
Name: service.Name,
ContainerName: service.ContainerName,
DockerImage: service.DockerImage,
DockerTag: service.DockerTag,
Entrypoint: service.Entrypoint,
Description: service.Description,
PositionX: service.PositionX,
PositionY: service.PositionY,
}
}
8 changes: 8 additions & 0 deletions front/src/forms/editor.structure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ export const DRAWER_TYPE_STRUCTURES: EditorStructure = {
validator: string().nullable(),
maxLength: 15
},
{
label: 'Container name',
key: 'containerName',
type: TypeList.TEXT,
component: Input,
validator: string().nullable(),
maxLength: 25
},
{
label: 'Docker Image',
key: 'dockerImage',
Expand Down

0 comments on commit 4a4dc2e

Please sign in to comment.