Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0b18195

Browse files
feat: runtime support config extra_hosts (#10750)
Refs #10250
1 parent 6ce3375 commit 0b18195

File tree

31 files changed

+230
-101
lines changed

31 files changed

+230
-101
lines changed

‎agent/app/dto/request/runtime.go‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type NodeConfig struct {
3232
ExposedPorts []ExposedPort `json:"exposedPorts"`
3333
Environments []Environment `json:"environments"`
3434
Volumes []Volume `json:"volumes"`
35+
ExtraHosts []ExtraHost `json:"extraHosts"`
3536
}
3637

3738
type Environment struct {
@@ -49,6 +50,11 @@ type ExposedPort struct {
4950
HostIP string `json:"hostIP"`
5051
}
5152

53+
type ExtraHost struct {
54+
Hostname string `json:"hostname"`
55+
IP string `json:"ip"`
56+
}
57+
5258
type RuntimeDelete struct {
5359
ID uint `json:"id"`
5460
ForceDelete bool `json:"forceDelete"`
@@ -135,6 +141,7 @@ type PHPContainerConfig struct {
135141
ExposedPorts []ExposedPort `json:"exposedPorts"`
136142
Environments []Environment `json:"environments"`
137143
Volumes []Volume `json:"volumes"`
144+
ExtraHosts []ExtraHost `json:"extraHosts"`
138145
}
139146

140147
type RuntimeRemark struct {

‎agent/app/dto/response/runtime.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type RuntimeDTO struct {
2828
ExposedPorts []request.ExposedPort `json:"exposedPorts"`
2929
Environments []request.Environment `json:"environments"`
3030
Volumes []request.Volume `json:"volumes"`
31+
ExtraHosts []request.ExtraHost `json:"extraHosts"`
3132
ContainerStatus string `json:"containerStatus"`
3233
Container string `json:"container"`
3334
Remark string `json:"remark"`

‎agent/app/service/runtime.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,7 @@ func (r *RuntimeService) GetPHPContainerConfig(id uint) (*request.PHPContainerCo
11351135
ExposedPorts: runtimeDTO.ExposedPorts,
11361136
Environments: runtimeDTO.Environments,
11371137
Volumes: runtimeDTO.Volumes,
1138+
ExtraHosts: runtimeDTO.ExtraHosts,
11381139
}
11391140
return res, nil
11401141
}

‎agent/app/service/runtime_utils.go‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,16 @@ func handleCompose(env gotenv.Env, composeContent []byte, create request.Runtime
635635
for _, volume := range create.Volumes {
636636
volumes = append(volumes, fmt.Sprintf("%s:%s", volume.Source, volume.Target))
637637
}
638+
639+
var extraHosts []interface{}
640+
for _, host := range create.ExtraHosts {
641+
extraHosts = append(extraHosts, fmt.Sprintf("%s:%s", host.Hostname, host.IP))
642+
}
643+
delete(serviceValue, "extraHosts")
644+
if len(extraHosts) > 0 {
645+
serviceValue["extra_hosts"] = extraHosts
646+
}
647+
638648
serviceValue["volumes"] = volumes
639649
break
640650
}
@@ -842,6 +852,33 @@ func getDockerComposeVolumes(yml []byte) ([]request.Volume, error) {
842852
return res, nil
843853
}
844854

855+
func getDockerComposeExtraHosts(yml []byte) ([]request.ExtraHost, error) {
856+
var (
857+
composeProject docker.ComposeProject
858+
err error
859+
)
860+
err = yaml.Unmarshal(yml, &composeProject)
861+
if err != nil {
862+
return nil, err
863+
}
864+
var res []request.ExtraHost
865+
for _, service := range composeProject.Services {
866+
for _, extraHosts := range service.ExtraHosts {
867+
envArray := strings.Split(extraHosts, ":")
868+
source := envArray[0]
869+
target := ""
870+
if len(envArray) > 1 {
871+
target = envArray[1]
872+
}
873+
res = append(res, request.ExtraHost{
874+
Hostname: source,
875+
IP: target,
876+
})
877+
}
878+
}
879+
return res, nil
880+
}
881+
845882
func checkRuntimePortExist(port int, scanPort bool, runtimeID uint) error {
846883
errMap := make(map[string]interface{})
847884
errMap["port"] = port
@@ -982,6 +1019,11 @@ func handleRuntimeDTO(res *response.RuntimeDTO, runtime model.Runtime) error {
9821019
return err
9831020
}
9841021

1022+
res.ExtraHosts, err = getDockerComposeExtraHosts(composeByte)
1023+
if err != nil {
1024+
return err
1025+
}
1026+
9851027
defaultVolumes := make(map[string]string)
9861028
switch runtime.Type {
9871029
case constant.RuntimeNode, constant.RuntimeJava, constant.RuntimePython, constant.RuntimeDotNet:

‎agent/utils/docker/compose.go‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ type ComposeProject struct {
5757
type Service struct {
5858
Image string `yaml:"image"`
5959
Environment Environment `yaml:"environment"`
60-
Volumes []string `json:"volumes"`
61-
Restart string `json:"restart"`
60+
Volumes []string `yaml:"volumes"`
61+
ExtraHosts []string `yaml:"extra_hosts"`
62+
Restart string `yaml:"restart"`
6263
}
6364

6465
type Environment struct {

‎frontend/src/api/interface/ai.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,11 @@ export namespace AI {
199199
target: string;
200200
}
201201

202+
export interface ExtraHosts {
203+
hostname: string;
204+
ip: string;
205+
}
206+
202207
export interface TensorRTLLM {
203208
id?: number;
204209
name: string;
@@ -211,6 +216,7 @@ export namespace AI {
211216
exposedPorts?: ExposedPort[];
212217
environments?: Environment[];
213218
volumes?: Volume[];
219+
extraHosts?: ExtraHosts[];
214220
}
215221

216222
export interface TensorRTLLMDTO extends TensorRTLLM {

‎frontend/src/api/interface/runtime.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export namespace Runtime {
4242
exposedPorts?: ExposedPort[];
4343
environments?: Environment[];
4444
volumes?: Volume[];
45+
extraHosts?: ExtraHost[];
4546
container: string;
4647
}
4748

@@ -62,6 +63,7 @@ export namespace Runtime {
6263
exposedPorts?: ExposedPort[];
6364
environments?: Environment[];
6465
volumes?: Volume[];
66+
extraHosts?: ExtraHost[];
6567
remark?: string;
6668
}
6769

@@ -70,7 +72,6 @@ export namespace Runtime {
7072
containerPort: number;
7173
hostIP: string;
7274
}
73-
7475
export interface Environment {
7576
key: string;
7677
value: string;
@@ -80,6 +81,11 @@ export namespace Runtime {
8081
target: string;
8182
}
8283

84+
export interface ExtraHost {
85+
hostname: string;
86+
ip: string;
87+
}
88+
8389
export interface RuntimeUpdate {
8490
name: string;
8591
appDetailID: number;
@@ -222,6 +228,7 @@ export namespace Runtime {
222228
exposedPorts: ExposedPort[];
223229
environments: Environment[];
224230
volumes: Volume[];
231+
extraHosts: ExtraHost[];
225232
}
226233

227234
export interface RemarkUpdate {

‎frontend/src/lang/modules/en.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2963,6 +2963,7 @@ const message = {
29632963
dirHelper: 'Note: Please fill in the directory path inside the container',
29642964
concurrency: 'Concurrency Scheme',
29652965
loadStatus: 'Load Status',
2966+
extraHosts: 'Host mapping',
29662967
},
29672968
process: {
29682969
pid: 'Process ID',

‎frontend/src/lang/modules/es-es.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2934,6 +2934,7 @@ const message = {
29342934
dirHelper: 'Nota: rellena la ruta del directorio dentro del contenedor',
29352935
concurrency: 'Esquema de concurrencia',
29362936
loadStatus: 'Estado de carga',
2937+
extraHosts: 'Mapeo de host',
29372938
},
29382939
process: {
29392940
pid: 'ID de proceso',

‎frontend/src/lang/modules/ja.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2855,6 +2855,7 @@ const message = {
28552855
dirHelper: 'ノート: コンテナ内のディレクトリパスを入力してください',
28562856
concurrency: '並行処理スキーム',
28572857
loadStatus: '負荷状態',
2858+
extraHosts: 'ホストマッピング',
28582859
},
28592860
process: {
28602861
pid: 'プロセスID',

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /