Browse Source

feat(容器命令): 添加goenv可执行程序,执行命令直接进入容器环境

main
xiaoqidun 1 year ago
parent
commit
29e8ec4a2e
  1. 35
      .drone.yml
  2. 3
      go.mod
  3. 66
      goenv.go

35
.drone.yml

@ -1,6 +1,39 @@
---
kind: pipeline
type: docker
name: default
name: goenv
steps:
- name: build
pull: if-not-exists
image: ghcr.io/xiaoqidun/build
commands:
- build -f build.sh -i goenv.go -o release/goenv
- name: build
pull: if-not-exists
image: xiaoqidun/goenv
commands:
- ./build.sh
- name: upload
pull: if-not-exists
image: plugins/s3
settings:
bucket:
from_secret: minio_bucket
access_key:
from_secret: minio_access_key
secret_key:
from_secret: minio_secret_key
source: release/*
strip_prefix: release/
target: product/goenv
path_style: true
endpoint: https://minio.aite.xyz
---
kind: pipeline
type: docker
name: docker
steps:
- name: build

3
go.mod

@ -0,0 +1,3 @@
module github.com/xiaoqidun/goenv
go 1.15

66
goenv.go

@ -0,0 +1,66 @@
package main
import (
"flag"
"fmt"
"os"
"os/exec"
)
var (
author bool
)
func init() {
flag.BoolVar(&author, "author", false, "关于本软件开发者")
flag.Parse()
}
func main() {
if author {
Author()
return
}
d := &DockerGoEnv{
Image: "xiaoqidun/goenv",
Binary: "docker",
WorkDir: "/go/src/app",
AutoDelete: true,
MountWorkDir: true,
}
d.Run()
}
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)
}
}
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()
}
Loading…
Cancel
Save