2020-09-24 01:11:18 +08:00
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"flag"
|
|
|
|
|
"fmt"
|
|
|
|
|
"os"
|
|
|
|
|
"os/exec"
|
2021-09-08 10:56:46 +08:00
|
|
|
|
"runtime"
|
2020-09-24 01:11:18 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
author bool
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
flag.BoolVar(&author, "author", false, "关于本软件开发者")
|
|
|
|
|
flag.Parse()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
if author {
|
|
|
|
|
Author()
|
|
|
|
|
return
|
|
|
|
|
}
|
2021-09-08 10:56:46 +08:00
|
|
|
|
binary := "docker"
|
|
|
|
|
if runtime.GOOS == "linux" {
|
|
|
|
|
podman, err := exec.LookPath("podman")
|
|
|
|
|
if err == nil {
|
|
|
|
|
binary = podman
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
docker := &DockerGoEnv{
|
2023-04-13 10:28:33 +08:00
|
|
|
|
Image: "ccr.ccs.tencentyun.com/xiaoqidun/goenv",
|
2021-09-08 10:56:46 +08:00
|
|
|
|
Binary: binary,
|
2020-09-24 01:11:18 +08:00
|
|
|
|
WorkDir: "/go/src/app",
|
|
|
|
|
AutoDelete: true,
|
|
|
|
|
MountWorkDir: true,
|
|
|
|
|
}
|
2021-09-08 10:56:46 +08:00
|
|
|
|
docker.Run()
|
2020-09-24 01:11:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Author() {
|
|
|
|
|
fmt.Println("welcome to our website https://aite.xyz/")
|
|
|
|
|
fmt.Println("----------------------------------------")
|
|
|
|
|
fmt.Println("腾讯扣扣:88966001")
|
|
|
|
|
fmt.Println("电子邮箱:xiaoqidun@gmail.com")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type DockerGoEnv struct {
|
|
|
|
|
Image string
|
|
|
|
|
Binary string
|
|
|
|
|
CmdArgs []string
|
|
|
|
|
WorkDir string
|
|
|
|
|
AutoDelete bool
|
|
|
|
|
MountWorkDir bool
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (d *DockerGoEnv) Run() {
|
|
|
|
|
d.CmdArgs = []string{"run", "-it"}
|
|
|
|
|
if d.AutoDelete {
|
|
|
|
|
d.CmdArgs = append(d.CmdArgs, "--rm")
|
|
|
|
|
}
|
|
|
|
|
if d.MountWorkDir {
|
|
|
|
|
if pwd, err1 := os.Getwd(); err1 == nil {
|
|
|
|
|
d.CmdArgs = append(d.CmdArgs, "-v", pwd+":"+d.WorkDir, "-w", d.WorkDir)
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-10-15 18:24:17 +08:00
|
|
|
|
if hostname, err1 := os.Hostname(); err1 == nil {
|
|
|
|
|
d.CmdArgs = append(d.CmdArgs, "-h", hostname)
|
|
|
|
|
}
|
2020-09-24 01:11:18 +08:00
|
|
|
|
d.CmdArgs = append(d.CmdArgs, d.Image)
|
|
|
|
|
cmd := exec.Command(d.Binary, d.CmdArgs...)
|
|
|
|
|
cmd.Stdin = os.Stdin
|
|
|
|
|
cmd.Stdout = os.Stdout
|
|
|
|
|
cmd.Stderr = os.Stderr
|
|
|
|
|
_ = cmd.Run()
|
|
|
|
|
}
|