Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions agent/app/api/v2/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,26 @@ func (b *BaseApi) ComposeUpdate(c *gin.Context) {
helper.Success(c)
}

// @Tags Container Compose
// @Summary Load compose environment variables
// @Accept json
// @Param request body dto.FilePath true "request"
// @Success 200 {array} string
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /containers/compose/env [post]
func (b *BaseApi) LoadComposeEnv(c *gin.Context) {
var req dto.FilePath
if err := helper.CheckBindAndValidate(&req, c); err != nil {
return
}
data, err := containerService.LoadComposeEnv(req.Path)
if err != nil {
helper.InternalServer(c, err)
}
helper.SuccessWithData(c, data)
}

// @Tags Container
// @Summary Container logs
// @Param container query string false "容器名称"
Expand Down
10 changes: 7 additions & 3 deletions agent/app/service/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,15 @@ type IContainerService interface {
ListNetwork() ([]dto.Options, error)
PageVolume(req dto.SearchWithPage) (int64, interface{}, error)
ListVolume() ([]dto.Options, error)

PageCompose(req dto.SearchWithPage) (int64, interface{}, error)
LoadComposeEnv(name string) (string, error)
CreateCompose(req dto.ComposeCreate) error
ComposeOperation(req dto.ComposeOperation) error
TestCompose(req dto.ComposeCreate) (bool, error)
ComposeUpdate(req dto.ComposeUpdate) error
ComposeLogClean(req dto.ComposeLogClean) error

ContainerCreate(req dto.ContainerOperate, inThread bool) error
ContainerCreateByCommand(req dto.ContainerCreateByCommand) error
ContainerUpdate(req dto.ContainerOperate) error
Expand All @@ -76,14 +82,12 @@ type IContainerService interface {
ContainerOperation(req dto.ContainerOperation) error
DownloadContainerLogs(containerType, container, since, tail string, c *gin.Context) error
ContainerStats(id string) (*dto.ContainerStats, error)

Inspect(req dto.InspectReq) (string, error)
DeleteNetwork(req dto.BatchDelete) error
CreateNetwork(req dto.NetworkCreate) error
DeleteVolume(req dto.BatchDelete) error
CreateVolume(req dto.VolumeCreate) error
TestCompose(req dto.ComposeCreate) (bool, error)
ComposeUpdate(req dto.ComposeUpdate) error
ComposeLogClean(req dto.ComposeLogClean) error
Prune(req dto.ContainerPrune) error

LoadUsers(req dto.OperationWithName) []string
Expand Down
9 changes: 9 additions & 0 deletions agent/app/service/container_compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,15 @@ func (u *ContainerService) ComposeLogClean(req dto.ComposeLogClean) error {
})
}

func (u *ContainerService) LoadComposeEnv(name string) (string, error) {
envFilePath := path.Join(path.Dir(name), ".env")
file, err := os.ReadFile(envFilePath)
if err != nil {
return "", err
}
return string(file), nil
}

func (u *ContainerService) loadPath(req *dto.ComposeCreate) error {
if req.From == "template" || req.From == "edit" {
dir := fmt.Sprintf("%s/docker/compose/%s", global.Dir.DataDir, req.Name)
Expand Down
1 change: 1 addition & 0 deletions agent/router/ro_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func (s *ContainerRouter) InitRouter(Router *gin.RouterGroup) {

baRouter.POST("/compose/search", baseApi.SearchCompose)
baRouter.POST("/compose", baseApi.CreateCompose)
baRouter.POST("/compose/env", baseApi.LoadComposeEnv)
baRouter.POST("/compose/test", baseApi.TestCompose)
baRouter.POST("/compose/operate", baseApi.OperatorCompose)
baRouter.POST("/compose/clean/log", baseApi.CleanComposeLog)
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/api/modules/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ export const composeUpdate = (params: Container.ComposeUpdate) => {
export const dockerOperate = (operation: string) => {
return http.post(`/containers/docker/operate`, { operation: operation }, TimeoutEnum.T_3M);
};
export const loadComposeEnv = (path: string) => {
return http.post<string>(`/containers/compose/env`, { path: path });
};
export const loadDaemonJson = () => {
return http.get<Container.DaemonJsonConf>(`/containers/daemonjson`);
};
Expand Down
8 changes: 6 additions & 2 deletions frontend/src/views/container/compose/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<el-table
:max-height="loadTableHeight()"
:show-header="false"
@row-click="loadDetail"
@row-click="(row, column, event) => loadDetail(row, true)"
:data="data"
>
<el-table-column prop="name">
Expand Down Expand Up @@ -281,7 +281,7 @@
label-position="top"
:model="form"
:rules="rules"
v-loading="loading"
v-loading="detailLoading"
>
<el-form-item :label="$t('app.source')">
<el-radio-group v-model="form.from" @change="onEdit('form')">
Expand Down Expand Up @@ -382,6 +382,7 @@ import {
containerListStats,
inspect,
listComposeTemplate,
loadComposeEnv,
searchCompose,
testCompose,
upCompose,
Expand Down Expand Up @@ -619,6 +620,9 @@ const changePath = async () => {
};
const loadDir = async (path: string) => {
form.path = path;
await loadComposeEnv(path).then((res) => {
form.env = res.data || '';
});
};
const handleClose = () => {
search(true);
Expand Down
Loading