add restart command and fix bug
This commit is contained in:
@@ -126,16 +126,15 @@ func GetAllMappedPort(cli *client.Client, containerID string) (string, error) {
|
||||
func PushImage(dockerHost string, username string, password string, registryUrl string, imageRef string) error {
|
||||
script := "docker " + "-H " + dockerHost + " login -u " + username + " -p " + password + " " + registryUrl + " "
|
||||
cmd := exec.Command("sh", "-c", script)
|
||||
output, err := cmd.CombinedOutput()
|
||||
log.Info(string(output))
|
||||
_, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// 推送到仓库
|
||||
script = "docker " + "-H " + dockerHost + " push " + imageRef
|
||||
cmd = exec.Command("sh", "-c", script)
|
||||
output, err = cmd.CombinedOutput()
|
||||
log.Info(string(output))
|
||||
_, err = cmd.CombinedOutput()
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -248,7 +247,6 @@ func CreateAndStartContainer(cli *client.Client, opts *CreateDevcontainerOptions
|
||||
},
|
||||
PortBindings: opts.PortBindings,
|
||||
}
|
||||
log.Info("%v", opts.PortBindings)
|
||||
if len(opts.Binds) > 0 {
|
||||
hostConfig.Binds = opts.Binds
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ func GetRepoDevContainerDetails(ctx *context.Context) {
|
||||
ctx.Data["HasValidDevContainerJSON"] = isValidRepoDevcontainerJson
|
||||
ctx.Data["Repository"] = ctx.Repo.Repository
|
||||
ctx.Data["ContextUser"] = ctx.Doer
|
||||
ctx.Data["CreateDevcontainerSettingUrl"] = "/" + ctx.Doer.Name + "/" + ctx.Repo.Repository.Name + "/dev-container/createConfiguration"
|
||||
ctx.Data["CreateDevcontainerSettingUrl"] = "/" + ctx.ContextUser.Name + "/" + ctx.Repo.Repository.Name + "/dev-container/createConfiguration"
|
||||
ctx.Data["EditDevcontainerConfigurationUrl"] = ctx.Repo.RepoLink + "/_edit/" + ctx.Repo.Repository.DefaultBranch + "/.devcontainer/devcontainer.json"
|
||||
ctx.Data["TreeNames"] = []string{".devcontainer", "devcontainer.json"}
|
||||
ctx.Data["TreePaths"] = []string{".devcontainer", ".devcontainer/devcontainer.json"}
|
||||
@@ -204,7 +204,6 @@ func UpdateRepoDevContainerForCurrentActor(ctx *context.Context) {
|
||||
ctx.JSON(400, map[string]string{"message": "输入错误"})
|
||||
return
|
||||
}
|
||||
log.Info(updateInfo.SaveMethod + "asdafgsa")
|
||||
opts := &devcontainer_service.UpdateDevcontainerOptions{
|
||||
ImageName: updateInfo.ImageName,
|
||||
PassWord: updateInfo.PassWord,
|
||||
|
||||
@@ -342,7 +342,6 @@ func GetWebTerminalURL(ctx context.Context, devcontainerName string) (string, er
|
||||
func Get_IDE_TerminalURL(ctx *gitea_context.Context, devcontainer *RepoDevContainer) (string, error) {
|
||||
var access_token string
|
||||
defalut_ctx := context.Background()
|
||||
log.Info("%v", devcontainer)
|
||||
// 获取端口号
|
||||
cli, err := docker.CreateDockerClient(&defalut_ctx)
|
||||
if err != nil {
|
||||
|
||||
@@ -34,6 +34,7 @@ type DevStarJSON struct {
|
||||
}
|
||||
|
||||
func CreateDevcontainerJSON(ctx *gitea_context.Context) {
|
||||
log.Info("%v %v", ctx.Repo.Repository, ctx.Doer)
|
||||
jsonString := `{
|
||||
"image":"mcr.microsoft.com/devcontainers/base:dev-ubuntu-20.04",
|
||||
"forwardPorts": [
|
||||
@@ -55,7 +56,7 @@ func CreateDevcontainerJSON(ctx *gitea_context.Context) {
|
||||
"8888:8888"
|
||||
]
|
||||
}`
|
||||
resp, err := files_service.ChangeRepoFiles(db.DefaultContext, ctx.Repo.Repository, ctx.Doer, &files_service.ChangeRepoFilesOptions{
|
||||
_, err := files_service.ChangeRepoFiles(db.DefaultContext, ctx.Repo.Repository, ctx.Doer, &files_service.ChangeRepoFilesOptions{
|
||||
Files: []*files_service.ChangeRepoFile{
|
||||
{
|
||||
Operation: "create",
|
||||
@@ -67,7 +68,7 @@ func CreateDevcontainerJSON(ctx *gitea_context.Context) {
|
||||
NewBranch: "main",
|
||||
Message: "add container configuration",
|
||||
})
|
||||
log.Info(resp.Commit.URL)
|
||||
//log.Info(resp.Commit.URL)
|
||||
if err != nil {
|
||||
log.Info("error ChangeRepoFiles:", err)
|
||||
ctx.JSON(500, map[string]string{
|
||||
|
||||
@@ -532,6 +532,7 @@ func DockerRestartContainer(gitea_ctx *gitea_web_context.Context, opts *RepoDevC
|
||||
devContainerJson, err := GetDevcontainerJsonModel(*gitea_ctx, gitea_ctx.Repo.Repository)
|
||||
cmd := []string{
|
||||
"/usr/bin/ttyd/ttyd/ttyd -W -w " + opts.DevContainerWorkDir + " bash & ",
|
||||
"service ssh restart",
|
||||
}
|
||||
postCreateCommand := append(cmd, devContainerJson.PostCreateCommand...)
|
||||
// 创建 exec 实例
|
||||
|
||||
@@ -52,8 +52,8 @@
|
||||
<div class="item"><a class="delete-button flex-text-inline" style="color:black;" data-modal-id="updatemodal" href="#">{{svg "octicon-database"}}{{ctx.Locale.Tr "repo.dev_container_control.update"}}</a></div>
|
||||
|
||||
{{if .InitializedContainer}}
|
||||
<div class="item"><a class="button flex-text-inline" href="{{.Repository.Link}}/dev-container/restart">{{svg "octicon-terminal" 14 "tw-mr-2"}} Restart Dev Container</a></div>
|
||||
<div class="item"><a class="button flex-text-inline" href="{{.Repository.Link}}/dev-container/stop">{{svg "octicon-terminal" 14 "tw-mr-2"}} Stop Dev Container</a></div>
|
||||
<div class="item"><a class="flex-text-inline" style="color:black;" href="{{.Repository.Link}}/dev-container/restart">{{svg "octicon-terminal" 14 "tw-mr-2"}} Restart Dev Container</a></div>
|
||||
<div class="item"><a class="flex-text-inline" style="color:black;" href="{{.Repository.Link}}/dev-container/stop">{{svg "octicon-terminal" 14 "tw-mr-2"}} Stop Dev Container</a></div>
|
||||
<div class="item"><a class="flex-text-inline" style="color:black;" href="{{.WebSSHUrl}}" target="_blank">{{svg "octicon-code" 14}}open with WebTerminal</a></div>
|
||||
<div class="item"><a class="flex-text-inline" style="color:black;" onclick="window.location.href = '{{.VSCodeUrl}}'">{{svg "octicon-code" 14}}open with VSCode</a ></div>
|
||||
<div class="item"><a class="flex-text-inline" style="color:black;" onclick="window.location.href = '{{.CursorUrl}}'">{{svg "octicon-code" 14}}open with Cursor</a ></div>
|
||||
|
||||
Reference in New Issue
Block a user