feat(更新镜像): 裁剪镜像,删除goenv命令
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
xiaoqidun 2023-07-06 21:05:25 +08:00
parent 87cf150e7b
commit 3bc3e7bad7
7 changed files with 22 additions and 127 deletions

@ -1,32 +1,7 @@
---
kind: pipeline
type: docker
name: goenv
steps:
- name: build
pull: if-not-exists
image: hkccr.ccs.tencentyun.com/xiaoqidun/goenv
commands:
- chmod +x build.sh
- ./build.sh
- name: upload
image: hkccr.ccs.tencentyun.com/xiaoqidun/gocos
settings:
secret_id:
from_secret: cos_secret_id
secret_key:
from_secret: cos_secret_key
bucket_url:
from_secret: cos_bucket_url
source: release/
target: product/goenv
strip_prefix: release/
---
kind: pipeline
type: docker
name: docker
name: default
steps:
- name: build
@ -57,4 +32,4 @@ steps:
from_secret: docker_username
password:
from_secret: docker_password
dockerfile: Dockerfile
dockerfile: DockerfileCN

@ -1,5 +1,5 @@
# 基础镜像
FROM golang:1.20.5-bullseye
FROM golang:1.20.5-bookworm
# 作者信息
LABEL MAINTAINER="xiaoqidun@gmail.com"
@ -8,7 +8,6 @@ LABEL MAINTAINER="xiaoqidun@gmail.com"
RUN apt-get update \
&& apt-get install -y \
build-essential mingw-w64 \
iproute2 upx-ucl file zip \
&& rm -rf /var/lib/apt/lists/*
# 安装android ndk

19
DockerfileCN Normal file

@ -0,0 +1,19 @@
# 基础镜像
FROM golang:1.20.5-bookworm
# 作者信息
LABEL MAINTAINER="xiaoqidun@gmail.com"
# 安装编译工具链
RUN apt-get update \
&& apt-get install -y \
build-essential mingw-w64 \
&& rm -rf /var/lib/apt/lists/*
# 安装android ndk
COPY android-ndk-r25c /usr/local/android-ndk-r25c
# 环境变量
ENV PATH=$PATH:/usr/local/android-ndk-r25c/toolchains/llvm/prebuilt/linux-x86_64/bin
ENV GO111MODULE=on
ENV GOPROXY=https://mirrors.aliyun.com/goproxy/,direct

@ -73,17 +73,3 @@ go build -o main_windows_amd64.exe main.go
## 动态编译
- 动态编译必须设置CC变量指定C编译器可执行文件路径或者在PATH变量内的可执行C编译器名称
# 快捷命令 - goenv
> 运行一个goenv容器并将当前目录挂载到容器的工作目录
## 快速安装
```shell
go install github.com/xiaoqidun/goenv@latest
```
## 手动安装
1. 根据系统架构下载为你编译好的[二进制文件](https://aite.xyz/product/goenv/)
2. 将下载好的二进制文件重命名为goenv并保留后缀
3. 把goenv文件移动到系统PATH环境变量中的目录下
4. windows外的系统需使用chmod命令赋予可执行权限

@ -1,4 +0,0 @@
#!/bin/sh
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o release/goenv_linux_amd64 -trimpath -ldflags '-s -w' goenv.go
GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -o release/goenv_darwin_amd64 -trimpath -ldflags '-s -w' goenv.go
GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -o release/goenv_windows_amd64.exe -trimpath -ldflags '-s -w' goenv.go

3
go.mod

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

@ -1,77 +0,0 @@
package main
import (
"flag"
"fmt"
"os"
"os/exec"
"runtime"
)
var (
author bool
)
func init() {
flag.BoolVar(&author, "author", false, "关于本软件开发者")
flag.Parse()
}
func main() {
if author {
Author()
return
}
binary := "docker"
if runtime.GOOS == "linux" {
podman, err := exec.LookPath("podman")
if err == nil {
binary = podman
}
}
docker := &DockerGoEnv{
Image: "ccr.ccs.tencentyun.com/xiaoqidun/goenv",
Binary: binary,
WorkDir: "/go/src/app",
AutoDelete: true,
MountWorkDir: true,
}
docker.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)
}
}
if hostname, err1 := os.Hostname(); err1 == nil {
d.CmdArgs = append(d.CmdArgs, "-h", hostname)
}
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()
}