Merge branch 'add-dockerfile-method-and-start-stop-container' of https://gitee.com/devstar/devstar into add-dockerfile-method-and-start-stop-container
This commit is contained in:
@@ -339,7 +339,7 @@ func PullImageAsyncAndStartContainer(ctx *context.Context, cli *client.Client, d
|
||||
return err
|
||||
}
|
||||
|
||||
if len(opts.PostCreateCommand) >= 1 {
|
||||
if len(opts.PostCreateCommand) > 1 {
|
||||
_, err := dbEngine.Table("devcontainer_output").Insert(&devcontainer_models.DevcontainerOutput{
|
||||
Output: "",
|
||||
Status: "running",
|
||||
@@ -439,6 +439,7 @@ func PullImageAsyncAndStartContainer(ctx *context.Context, cli *client.Client, d
|
||||
}
|
||||
buffer = ""
|
||||
state = 3
|
||||
continue
|
||||
}
|
||||
|
||||
output, err = docker_module.ExecCommandInContainer(ctx, cli, containerID, cmd)
|
||||
@@ -492,6 +493,9 @@ func DockerRestartContainer(gitea_ctx *gitea_web_context.Context, opts *RepoDevC
|
||||
}
|
||||
|
||||
devContainerJson, err := GetDevcontainerJsonModel(*gitea_ctx, gitea_ctx.Repo.Repository)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cmd := []string{"/home/devcontainer_restart.sh"}
|
||||
postCreateCommand := append(cmd, devContainerJson.PostCreateCommand...)
|
||||
// 创建 exec 实例
|
||||
@@ -503,15 +507,23 @@ func DockerRestartContainer(gitea_ctx *gitea_web_context.Context, opts *RepoDevC
|
||||
Update(&devcontainer_models.DevcontainerOutput{
|
||||
Status: "running",
|
||||
})
|
||||
_, err = dbEngine.Table("devcontainer_output").
|
||||
Where("user_id = ? AND repo_id = ? AND list_id = ?", opts.UserId, opts.RepoId, state+1).
|
||||
Update(&devcontainer_models.DevcontainerOutput{
|
||||
Status: "running",
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(devContainerJson.PostCreateCommand) > 1 {
|
||||
_, err = dbEngine.Table("devcontainer_output").
|
||||
Where("user_id = ? AND repo_id = ? AND list_id = ?", opts.UserId, opts.RepoId, state+1).
|
||||
Update(&devcontainer_models.DevcontainerOutput{
|
||||
Status: "running",
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
for index, cmd := range postCreateCommand {
|
||||
|
||||
if index == len(cmd) {
|
||||
if index == 1 {
|
||||
_, err = dbEngine.Table("devcontainer_output").
|
||||
Where("user_id = ? AND repo_id = ? AND list_id = ?", opts.UserId, opts.RepoId, state).
|
||||
Update(&devcontainer_models.DevcontainerOutput{
|
||||
@@ -522,6 +534,7 @@ func DockerRestartContainer(gitea_ctx *gitea_web_context.Context, opts *RepoDevC
|
||||
}
|
||||
buffer = ""
|
||||
state = 3
|
||||
continue
|
||||
}
|
||||
|
||||
output, err := docker_module.ExecCommandInContainer(&ctx, cli, containerID, cmd)
|
||||
@@ -537,6 +550,7 @@ func DockerRestartContainer(gitea_ctx *gitea_web_context.Context, opts *RepoDevC
|
||||
})
|
||||
if err != nil {
|
||||
log.Info("Error storing output for command %v: %v\n", cmd, err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
_, err = dbEngine.Table("devcontainer_output").
|
||||
@@ -544,13 +558,19 @@ func DockerRestartContainer(gitea_ctx *gitea_web_context.Context, opts *RepoDevC
|
||||
Update(&devcontainer_models.DevcontainerOutput{
|
||||
Status: "success",
|
||||
})
|
||||
_, err = dbEngine.Table("devcontainer_output").
|
||||
Where("user_id = ? AND repo_id = ? AND list_id = ?", opts.UserId, opts.RepoId, 3).
|
||||
Update(&devcontainer_models.DevcontainerOutput{
|
||||
Status: "success",
|
||||
})
|
||||
if err != nil {
|
||||
log.Info("Error storing output for command %v: %v\n", cmd, err)
|
||||
return err
|
||||
}
|
||||
if len(devContainerJson.PostCreateCommand) > 1 {
|
||||
_, err = dbEngine.Table("devcontainer_output").
|
||||
Where("user_id = ? AND repo_id = ? AND list_id = ?", opts.UserId, opts.RepoId, 3).
|
||||
Update(&devcontainer_models.DevcontainerOutput{
|
||||
Status: "success",
|
||||
})
|
||||
if err != nil {
|
||||
log.Info("Error storing output for command %v: %v\n", cmd, err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user