mirror of
https://github.com/xiaoqidun/gocos.git
synced 2025-04-04 03:57:53 +08:00
Compare commits
58 Commits
8fc6e42719
...
main
Author | SHA1 | Date | |
---|---|---|---|
677cac0b33 | |||
4bdcf5d57e | |||
ec10d3093a | |||
61844be062 | |||
6be36afba1 | |||
c674c7c3c3 | |||
095ddd9165 | |||
67637fa55e | |||
a229f9eb3b | |||
4df67b8874 | |||
a470a2eab3 | |||
5a6d2baadf | |||
0c86408480 | |||
d5454ddc37 | |||
239c3d2ad0 | |||
969b0cbe62 | |||
0b233666f5 | |||
c7d127dff7 | |||
59411279eb | |||
e528f2ddf4 | |||
e9e86af4dd | |||
ab8323a34d | |||
1d73a5a962 | |||
882519753b | |||
bdaade4a18 | |||
83e9a70b01 | |||
67e3da13c7 | |||
1ab730b0bb | |||
e91e2d56e4 | |||
d7b165ce82 | |||
0d84371b1f | |||
536852bb79 | |||
11ab5e4f01 | |||
a2ea6579d9 | |||
dff970b744 | |||
3ef8929f4b | |||
89b2e61cc8 | |||
f60851107c | |||
0a622b5bb7 | |||
98240a452c | |||
9f67466d89 | |||
31bc0fdb75 | |||
73502e2c49 | |||
802053acfd | |||
067622650a | |||
a36fd1d626 | |||
6030905e57 | |||
96830a79ef | |||
379e65dafc | |||
f58a05391e | |||
594981b87c | |||
1e9aa6af24 | |||
4fac1685b8 | |||
a7b5361054 | |||
7503222aad | |||
853b453b04 | |||
e7f6b296d6 | |||
7a1e62a43c |
24
.drone.yml
24
.drone.yml
@ -1,20 +1,32 @@
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: default
|
||||
|
||||
node:
|
||||
region: cn
|
||||
steps:
|
||||
- name: build
|
||||
pull: if-not-exists
|
||||
image: xiaoqidun/goenv
|
||||
image: ccr.ccs.tencentyun.com/xiaoqidun/goenv
|
||||
commands:
|
||||
- CGO_ENABLED=0 go build -o gocos -trimpath -ldflags '-s -w' gocos.go
|
||||
- name: docker
|
||||
- GOAMD64=v3 CGO_ENABLED=0 go build -o gocos -trimpath -ldflags "-s -w -buildid=" gocos.go
|
||||
- name: docker-cn
|
||||
pull: if-not-exists
|
||||
image: plugins/docker
|
||||
settings:
|
||||
repo: xiaoqidun/gocos
|
||||
repo: ccr.ccs.tencentyun.com/xiaoqidun/gocos
|
||||
registry: ccr.ccs.tencentyun.com
|
||||
username:
|
||||
from_secret: docker_username
|
||||
password:
|
||||
from_secret: docker_password
|
||||
dockerfile: Dockerfile
|
||||
- name: docker-hk
|
||||
pull: if-not-exists
|
||||
image: plugins/docker
|
||||
settings:
|
||||
repo: hkccr.ccs.tencentyun.com/xiaoqidun/gocos
|
||||
registry: hkccr.ccs.tencentyun.com
|
||||
username:
|
||||
from_secret: docker_username
|
||||
password:
|
||||
from_secret: docker_password
|
||||
dockerfile: Dockerfile
|
@ -1,11 +1,11 @@
|
||||
# 基础镜像
|
||||
FROM alpine
|
||||
FROM alpine:3.21.3
|
||||
|
||||
# 作者信息
|
||||
LABEL MAINTAINER="xiaoqidun@gmail.com"
|
||||
LABEL authors="xiaoqidun"
|
||||
|
||||
# 复制程序
|
||||
COPY gocos /bin/gocos
|
||||
|
||||
# 启动命令
|
||||
ENTRYPOINT /bin/gocos
|
||||
ENTRYPOINT ["/bin/gocos"]
|
||||
|
56
README.md
56
README.md
@ -1,23 +1,51 @@
|
||||
# gocos
|
||||
腾讯云对象存储,Drone CI插件
|
||||
# GoCOS
|
||||
|
||||
腾讯云对象存储(COS),Drone CI插件,[AWS S3](http://plugins.drone.io/drone-plugins/drone-s3/)的COS实现
|
||||
|
||||
# Drone CI配置例子
|
||||
|
||||
```yml
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: default
|
||||
|
||||
steps:
|
||||
- name: upload
|
||||
image: xiaoqidun/gocos
|
||||
settings:
|
||||
secret_id:
|
||||
from_secret: secret_id
|
||||
secret_key:
|
||||
from_secret: secret_key
|
||||
bucket_url:
|
||||
from_secret: bucket_url
|
||||
source: build/release
|
||||
target: build/release
|
||||
strip_prefix: build/release
|
||||
- name: upload
|
||||
image: ccr.ccs.tencentyun.com/xiaoqidun/gocos
|
||||
settings:
|
||||
secret_id:
|
||||
from_secret: secret_id
|
||||
secret_key:
|
||||
from_secret: secret_key
|
||||
bucket_url:
|
||||
from_secret: bucket_url
|
||||
source: build/release
|
||||
target: build/release
|
||||
strip_prefix: build/release
|
||||
```
|
||||
|
||||
# Drone CI配置说明
|
||||
|
||||
### secret_id
|
||||
|
||||
API密钥管理获得的SecretId
|
||||
|
||||
### secret_key
|
||||
|
||||
API密钥管理获得的SecretKey
|
||||
|
||||
### bucket_url
|
||||
|
||||
存储桶概览中的访问域名
|
||||
|
||||
### source
|
||||
|
||||
DroneCI中文件的源位置
|
||||
|
||||
### target
|
||||
|
||||
存储桶中文件的目标位置
|
||||
|
||||
### strip_prefix
|
||||
|
||||
从文件的源位置剔除前缀
|
11
go.mod
11
go.mod
@ -1,5 +1,12 @@
|
||||
module github.com/xiaoqidun/gocos
|
||||
|
||||
go 1.16
|
||||
go 1.24.2
|
||||
|
||||
require github.com/tencentyun/cos-go-sdk-v5 v0.7.15
|
||||
require github.com/tencentyun/cos-go-sdk-v5 v0.7.64
|
||||
|
||||
require (
|
||||
github.com/clbanning/mxj v1.8.4 // indirect
|
||||
github.com/google/go-querystring v1.0.0 // indirect
|
||||
github.com/mitchellh/mapstructure v1.4.3 // indirect
|
||||
github.com/mozillazg/go-httpheader v0.2.1 // indirect
|
||||
)
|
||||
|
11
go.sum
11
go.sum
@ -1,13 +1,20 @@
|
||||
github.com/QcloudApi/qcloud_sign_golang v0.0.0-20141224014652-e4130a326409/go.mod h1:1pk82RBxDY/JZnPQrtqHlUFfCctgdorsd9M06fMynOM=
|
||||
github.com/clbanning/mxj v1.8.4 h1:HuhwZtbyvyOw+3Z1AowPkU87JkJUSv751ELWaiTpj8I=
|
||||
github.com/clbanning/mxj v1.8.4/go.mod h1:BVjHeAH+rl9rs6f+QIpeRl0tfu10SXn1pUSa5PVGJng=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
|
||||
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
|
||||
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
|
||||
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
|
||||
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/mitchellh/mapstructure v1.4.3 h1:OVowDSCllw/YjdLkam3/sm7wEtOy59d8ndGgCcyj8cs=
|
||||
github.com/mitchellh/mapstructure v1.4.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||
github.com/mozillazg/go-httpheader v0.2.1 h1:geV7TrjbL8KXSyvghnFm+NyTux/hxwueTSrwhe88TQQ=
|
||||
github.com/mozillazg/go-httpheader v0.2.1/go.mod h1:jJ8xECTlalr6ValeXYdOF8fFUISeBAdw6E61aqQma60=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/tencentyun/cos-go-sdk-v5 v0.7.15 h1:+uKDylojhKkGhBzb8B7J/nIoEl6afGYiJubkVWEctxA=
|
||||
github.com/tencentyun/cos-go-sdk-v5 v0.7.15/go.mod h1:wQBO5HdAkLjj2q6XQiIfDSP8DXDNrppDRw2Kp/1BODA=
|
||||
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.563/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
|
||||
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/kms v1.0.563/go.mod h1:uom4Nvi9W+Qkom0exYiJ9VWJjXwyxtPYTkKkaLMlfE0=
|
||||
github.com/tencentyun/cos-go-sdk-v5 v0.7.64 h1:2ADzzr+hcWl4Fw44DwXe0btlVzAYkdvHQ4glUyR0+mM=
|
||||
github.com/tencentyun/cos-go-sdk-v5 v0.7.64/go.mod h1:8+hG+mQMuRP/OIS9d83syAvXvrMj9HhkND6Q1fLghw0=
|
||||
|
31
gocos.go
31
gocos.go
@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/tencentyun/cos-go-sdk-v5"
|
||||
"io/fs"
|
||||
"log"
|
||||
@ -10,10 +11,11 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
_ "time/tzdata"
|
||||
)
|
||||
|
||||
const (
|
||||
CodeErr = 1
|
||||
SecretID = "secret_id"
|
||||
SecretKey = "secret_key"
|
||||
BucketURL = "bucket_url"
|
||||
@ -23,6 +25,11 @@ const (
|
||||
PathSeparator = "/"
|
||||
)
|
||||
|
||||
func ErrExit(err error) {
|
||||
log.Println(err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
func GetConfig(key string) string {
|
||||
key = "PLUGIN_" + strings.ToUpper(key)
|
||||
return os.Getenv(key)
|
||||
@ -48,6 +55,14 @@ func VarIsEmpty(a ...interface{}) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func init() {
|
||||
tz := os.Getenv("TZ")
|
||||
if tz == "" {
|
||||
tz = "Asia/Shanghai"
|
||||
}
|
||||
time.Local, _ = time.LoadLocation(tz)
|
||||
}
|
||||
|
||||
func main() {
|
||||
var (
|
||||
err error
|
||||
@ -58,9 +73,8 @@ func main() {
|
||||
target = GetConfig(Target)
|
||||
stripPrefix = GetConfig(StripPrefix)
|
||||
)
|
||||
if !VarIsEmpty(secretID, secretKey, bucketURL, source, target) {
|
||||
os.Exit(CodeErr)
|
||||
return
|
||||
if VarIsEmpty(secretID, secretKey, bucketURL, source, target) {
|
||||
ErrExit(errors.New("input error"))
|
||||
}
|
||||
sourceFiles := make([]string, 0, 0)
|
||||
if err = filepath.WalkDir(source, func(path string, d fs.DirEntry, err error) error {
|
||||
@ -69,8 +83,7 @@ func main() {
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
os.Exit(CodeErr)
|
||||
return
|
||||
ErrExit(err)
|
||||
}
|
||||
sourceLen := len(sourceFiles)
|
||||
if sourceLen == 0 {
|
||||
@ -81,8 +94,7 @@ func main() {
|
||||
}
|
||||
u, err := url.Parse(bucketURL)
|
||||
if err != nil {
|
||||
os.Exit(CodeErr)
|
||||
return
|
||||
ErrExit(err)
|
||||
}
|
||||
cosClient := cos.NewClient(
|
||||
&cos.BaseURL{
|
||||
@ -105,8 +117,7 @@ func main() {
|
||||
ACLHeaderOptions: &cos.ACLHeaderOptions{},
|
||||
ObjectPutHeaderOptions: &cos.ObjectPutHeaderOptions{},
|
||||
}); err != nil {
|
||||
os.Exit(CodeErr)
|
||||
return
|
||||
ErrExit(err)
|
||||
}
|
||||
log.Printf("source:%s target:%s\r\n", local, remote)
|
||||
}
|
||||
|
Reference in New Issue
Block a user