Skip to content

Commit

Permalink
Feat/i want to set a env file path (#124)
Browse files Browse the repository at this point in the history
* feat(service): add env_file field

* feat(service): add env_file to docker compose

* feat(service): add env_file field
  • Loading branch information
RomainDreidemy authored Sep 14, 2023
1 parent 4a4dc2e commit 9d3007c
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 13 deletions.
29 changes: 16 additions & 13 deletions .idea/workspace.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 @@ -1653,6 +1653,9 @@
"entrypoint": {
"type": "string"
},
"envFile": {
"type": "string"
},
"name": {
"type": "string"
},
Expand Down Expand Up @@ -1892,6 +1895,9 @@
"entrypoint": {
"type": "string"
},
"envFile": {
"type": "string"
},
"id": {
"type": "string"
},
Expand Down Expand Up @@ -1924,6 +1930,9 @@
"entrypoint": {
"type": "string"
},
"envFile": {
"type": "string"
},
"envVariables": {
"type": "array",
"items": {
Expand Down Expand Up @@ -1980,6 +1989,9 @@
"entrypoint": {
"type": "string"
},
"envFile": {
"type": "string"
},
"name": {
"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 @@ -137,6 +137,8 @@ definitions:
type: string
entrypoint:
type: string
envFile:
type: string
name:
type: string
positionX:
Expand Down Expand Up @@ -302,6 +304,8 @@ definitions:
type: string
entrypoint:
type: string
envFile:
type: string
id:
type: string
name:
Expand All @@ -323,6 +327,8 @@ definitions:
type: string
entrypoint:
type: string
envFile:
type: string
envVariables:
items:
$ref: '#/definitions/models.ServiceEnvVariableResponse'
Expand Down Expand Up @@ -360,6 +366,8 @@ definitions:
type: string
entrypoint:
type: string
envFile:
type: string
name:
type: string
positionX:
Expand Down
1 change: 1 addition & 0 deletions api/src/models/docker_compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type DockerComposeService struct {
Build DockerComposeServiceBuild `yaml:"build,omitempty"`
Image string `yaml:"image,omitempty"`
Ports []string `yaml:"ports,omitempty"`
EnvFile string `yaml:"env_file,omitempty"`
Environment map[string]string `yaml:"environment,omitempty"`
Volumes []string `yaml:"volumes,omitempty"`
Networks []string `yaml:"networks,omitempty"`
Expand Down
5 changes: 5 additions & 0 deletions api/src/models/service_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type Service struct {
ContainerName string `gorm:"type:varchar(255)"`
DockerImage string `gorm:"type:varchar(255)"`
DockerTag string `gorm:"type:varchar(255)"`
EnvFile 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"`
Expand All @@ -31,6 +32,7 @@ type ServiceCreateInput struct {
ContainerName string `json:"containerName"`
DockerImage string `json:"dockerImage"`
DockerTag string `json:"dockerTag"`
EnvFile string `json:"envFile"`
Entrypoint string `json:"entrypoint"`
Description string `json:"description"`
PositionX float32 `json:"positionX" validate:"required"`
Expand All @@ -42,6 +44,7 @@ type ServiceUpdateInput struct {
ContainerName string `json:"containerName"`
DockerImage string `json:"dockerImage"`
DockerTag string `json:"dockerTag"`
EnvFile string `json:"envFile"`
Context string `json:"context"`
Dockerfile string `json:"dockerfile"`
Entrypoint string `json:"entrypoint"`
Expand All @@ -56,6 +59,7 @@ type ServiceResponse struct {
ContainerName string `json:"containerName"`
DockerImage string `json:"dockerImage"`
DockerTag string `json:"dockerTag"`
EnvFile string `json:"envFile"`
Entrypoint string `json:"entrypoint"`
Description string `json:"description"`
PositionX float32 `json:"positionX"`
Expand All @@ -68,6 +72,7 @@ type ServiceResponseItem struct {
ContainerName string `json:"containerName"`
DockerImage string `json:"dockerImage"`
DockerTag string `json:"dockerTag"`
EnvFile string `json:"envFile"`
Entrypoint string `json:"entrypoint"`
Description string `json:"description"`
PositionX float32 `json:"positionX"`
Expand Down
4 changes: 4 additions & 0 deletions api/src/services/docker_compose/builders/service_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ func DockerComposeServiceBuilder(service models.Service) models.DockerComposeSer
dockerComposeService.Image = BuildDockerComposeServiceImage(service)
}

if service.EnvFile != "" {
dockerComposeService.EnvFile = service.EnvFile
}

if len(service.ServicePorts) > 0 {
dockerComposeService.Ports = BuildDockerComposeServicePorts(service.ServicePorts)
}
Expand Down
17 changes: 17 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 @@ -107,6 +107,23 @@ func TestDockerComposeServicesBuilder(t *testing.T) {
},
},
},
{
name: "should have a env_file value if specified",
args: args{
services: []models.Service{
{
Name: "api",
EnvFile: "prod.env",
},
},
},
want: map[string]models.DockerComposeService{
"api": {
ContainerName: "api",
EnvFile: "prod.env",
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
3 changes: 3 additions & 0 deletions api/src/services/factories/service_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ func BuildServiceResponse(service models.Service) models.ServiceResponseItem {
ContainerName: service.ContainerName,
DockerImage: service.DockerImage,
DockerTag: service.DockerTag,
EnvFile: service.EnvFile,
Entrypoint: service.Entrypoint,
Description: service.Description,
PositionX: service.PositionX,
Expand All @@ -35,6 +36,7 @@ func BuildServiceFromServiceCreationInput(service models.ServiceCreateInput, sta
ContainerName: service.ContainerName,
DockerImage: service.DockerImage,
DockerTag: service.DockerTag,
EnvFile: service.EnvFile,
Entrypoint: service.Entrypoint,
Description: service.Description,
PositionX: service.PositionX,
Expand All @@ -49,6 +51,7 @@ func BuildServiceFromServiceUpdateInput(service models.ServiceUpdateInput) model
ContainerName: service.ContainerName,
DockerImage: service.DockerImage,
DockerTag: service.DockerTag,
EnvFile: service.EnvFile,
Entrypoint: service.Entrypoint,
Description: service.Description,
PositionX: service.PositionX,
Expand Down
7 changes: 7 additions & 0 deletions front/src/forms/editor.structure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ export const DRAWER_TYPE_STRUCTURES: EditorStructure = {
component: Input,
validator: string().nullable()
},
{
label: 'Env file',
key: 'envFile',
type: TypeList.TEXT,
component: Input,
validator: string().nullable()
},
{
label: 'Entrypoint',
key: 'entrypoint',
Expand Down

0 comments on commit 9d3007c

Please sign in to comment.