mirror of
https://github.com/xiaoqidun/goenv.git
synced 2025-04-04 19:27:54 +08:00
Compare commits
83 Commits
292daa8a0c
...
main
Author | SHA1 | Date | |
---|---|---|---|
73b7995128 | |||
3a386feeec | |||
8b42279af8 | |||
68fa94a8c6 | |||
7ca2c9ba9e | |||
9c7e885d02 | |||
87b9d8a4a6 | |||
929bf8d314 | |||
7e6396a7a1 | |||
eb130c2a28 | |||
7722f887a8 | |||
7e366ab17e | |||
e7736b345f | |||
5adf05c471 | |||
29ef0d38de | |||
318f5681f4 | |||
8ccb320a78 | |||
cf514fbbb7 | |||
6210f6b195 | |||
67c96bff22 | |||
2f4abe9768 | |||
e764bc1608 | |||
a1f938c872 | |||
2f577fda9e | |||
ae2335889f | |||
5f65de79bb | |||
6a695572f6 | |||
37567594e4 | |||
cb354523ac | |||
573a8a29b1 | |||
902a8f847f | |||
55cba6a372 | |||
c8f32acd2e | |||
3742865087 | |||
47bc5ab50c | |||
b70271d8a6 | |||
3d2d480d19 | |||
e638e215cd | |||
2045a1013a | |||
f42201d3a2 | |||
293c42f6d4 | |||
367aa982b1 | |||
3bc3e7bad7 | |||
87cf150e7b | |||
ce70d9b7fb | |||
5db552bc1f | |||
3f3874ce9e | |||
8f4b4797b9 | |||
82fb7da3ed | |||
ba1e42cc94 | |||
0ef1dc7735 | |||
47413e5e66 | |||
e465b02956 | |||
24587098e1 | |||
99bc4ecb6a | |||
94294c1af4 | |||
bb526937ed | |||
80862d685c | |||
beca7e7d40 | |||
3e0434781a | |||
3fdcce75de | |||
a245c26afa | |||
73793848ce | |||
0510c3dda1 | |||
4489e44c03 | |||
070c4c9fc8 | |||
7774e19f99 | |||
b07004642f | |||
4c8e5d06b6 | |||
18c351fd6d | |||
2ccd60b65c | |||
d69946bf60 | |||
dea6d483a9 | |||
e6ec4965da | |||
da8ca38c99 | |||
d3265d35a5 | |||
6f8569a01d | |||
4ddf0bd22a | |||
42b144528e | |||
4383fc8c18 | |||
e68a039e7d | |||
b416798984 | |||
511e47ab75 |
59
.drone.yml
59
.drone.yml
@ -1,48 +1,37 @@
|
||||
---
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: goenv
|
||||
|
||||
name: default
|
||||
node:
|
||||
region: cn
|
||||
steps:
|
||||
- name: build
|
||||
pull: if-not-exists
|
||||
image: golang:alpine
|
||||
image: debian
|
||||
commands:
|
||||
- chmod +x build.sh
|
||||
- ./build.sh
|
||||
- name: upload
|
||||
image: 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
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
pull: if-not-exists
|
||||
image: alpine
|
||||
commands:
|
||||
- wget -q -T 180 https://dl.google.com/android/repository/android-ndk-r23-linux.zip
|
||||
- unzip -q android-ndk-r23-linux.zip
|
||||
- rm -f android-ndk-r23-linux.zip
|
||||
- name: docker
|
||||
- sed -i "s|deb.debian.org|mirrors.ustc.edu.cn|g" /etc/apt/sources.list.d/debian.sources
|
||||
- apt-get update && apt-get install -y wget unzip && rm -rf /var/lib/apt/lists/*
|
||||
- wget -q -T 180 -4 https://dl.google.com/android/repository/android-ndk-r29-beta1-linux.zip
|
||||
- unzip -q android-ndk-r29-beta1-linux.zip
|
||||
- rm -f android-ndk-r29-beta1-linux.zip
|
||||
- name: docker-cn
|
||||
pull: if-not-exists
|
||||
image: plugins/docker
|
||||
settings:
|
||||
repo: xiaoqidun/goenv
|
||||
repo: ccr.ccs.tencentyun.com/xiaoqidun/goenv
|
||||
registry: ccr.ccs.tencentyun.com
|
||||
username:
|
||||
from_secret: docker_username
|
||||
password:
|
||||
from_secret: docker_password
|
||||
dockerfile: Dockerfile
|
||||
dockerfile: DockerfileCN
|
||||
- name: docker-hk
|
||||
pull: if-not-exists
|
||||
image: plugins/docker
|
||||
settings:
|
||||
repo: hkccr.ccs.tencentyun.com/xiaoqidun/goenv
|
||||
registry: hkccr.ccs.tencentyun.com
|
||||
username:
|
||||
from_secret: docker_username
|
||||
password:
|
||||
from_secret: docker_password
|
||||
dockerfile: DockerfileHK
|
||||
|
19
Dockerfile
19
Dockerfile
@ -1,19 +0,0 @@
|
||||
# 基础镜像
|
||||
FROM golang:1.17-bullseye
|
||||
|
||||
# 作者信息
|
||||
LABEL MAINTAINER="xiaoqidun@gmail.com"
|
||||
|
||||
# 安装编译工具链
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y \
|
||||
build-essential mingw-w64 \
|
||||
upx-ucl strace htop tmux file zip
|
||||
|
||||
# 安装android ndk
|
||||
COPY android-ndk-r23 /usr/local/android-ndk-r23
|
||||
|
||||
# 环境变量
|
||||
ENV PATH=$PATH:/usr/local/android-ndk-r23/toolchains/llvm/prebuilt/linux-x86_64/bin
|
||||
ENV GO111MODULE=on
|
||||
ENV GOPROXY=https://goproxy.aite.xyz,direct
|
22
DockerfileCN
Normal file
22
DockerfileCN
Normal file
@ -0,0 +1,22 @@
|
||||
# 基础镜像
|
||||
FROM golang:1.24.2-bookworm
|
||||
|
||||
# 作者信息
|
||||
LABEL authors="xiaoqidun"
|
||||
|
||||
# 使用中国软件源
|
||||
RUN sed -i "s|deb.debian.org|mirrors.ustc.edu.cn|g" /etc/apt/sources.list.d/debian.sources
|
||||
|
||||
# 安装编译工具链
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y \
|
||||
build-essential mingw-w64 \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# 安装android ndk
|
||||
COPY android-ndk-r29-beta1 /usr/local/android-ndk-r29-beta1
|
||||
|
||||
# 环境变量
|
||||
ENV PATH=$PATH:/usr/local/android-ndk-r29-beta1/toolchains/llvm/prebuilt/linux-x86_64/bin
|
||||
ENV GO111MODULE=on
|
||||
ENV GOPROXY=https://goproxy.cn,direct
|
19
DockerfileHK
Normal file
19
DockerfileHK
Normal file
@ -0,0 +1,19 @@
|
||||
# 基础镜像
|
||||
FROM golang:1.24.2-bookworm
|
||||
|
||||
# 作者信息
|
||||
LABEL authors="xiaoqidun"
|
||||
|
||||
# 安装编译工具链
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y \
|
||||
build-essential mingw-w64 \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# 安装android ndk
|
||||
COPY android-ndk-r29-beta1 /usr/local/android-ndk-r29-beta1
|
||||
|
||||
# 环境变量
|
||||
ENV PATH=$PATH:/usr/local/android-ndk-r29-beta1/toolchains/llvm/prebuilt/linux-x86_64/bin
|
||||
ENV GO111MODULE=on
|
||||
ENV GOPROXY=https://goproxy.aite.xyz,direct
|
24
README.md
24
README.md
@ -5,12 +5,12 @@ golang environment
|
||||
|
||||
## 拉取镜像
|
||||
```
|
||||
docker pull xiaoqidun/goenv:latest
|
||||
docker pull ccr.ccs.tencentyun.com/xiaoqidun/goenv:latest
|
||||
```
|
||||
|
||||
## 运行镜像
|
||||
```
|
||||
docker run -it --rm xiaoqidun/goenv
|
||||
docker run -it --rm ccr.ccs.tencentyun.com/xiaoqidun/goenv
|
||||
```
|
||||
|
||||
# 编译项目
|
||||
@ -19,17 +19,17 @@ docker run -it --rm xiaoqidun/goenv
|
||||
|
||||
### linux - bash
|
||||
```shell
|
||||
docker run --rm -it -v $(pwd):/go/src/app -w /go/src/app xiaoqidun/goenv
|
||||
docker run --rm -it -v $(pwd):/usr/src/app -w /usr/src/app ccr.ccs.tencentyun.com/xiaoqidun/goenv
|
||||
```
|
||||
|
||||
### windows - cmd
|
||||
```bat
|
||||
docker run --rm -it -v %cd%:/go/src/app -w /go/src/app xiaoqidun/goenv
|
||||
docker run --rm -it -v %cd%:/usr/src/app -w /usr/src/app ccr.ccs.tencentyun.com/xiaoqidun/goenv
|
||||
```
|
||||
|
||||
### windows - powershell
|
||||
```powershell
|
||||
docker run --rm -it -v "${pwd}:/go/src/app" -w /go/src/app xiaoqidun/goenv
|
||||
docker run --rm -it -v "${pwd}:/usr/src/app" -w /usr/src/app ccr.ccs.tencentyun.com/xiaoqidun/goenv
|
||||
```
|
||||
|
||||
## 在容器内执行命令进行编译
|
||||
@ -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命令赋予可执行权限
|
||||
|
4
build.sh
4
build.sh
@ -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
|
77
goenv.go
77
goenv.go
@ -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: "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()
|
||||
}
|
Reference in New Issue
Block a user