mirror of
https://github.com/xiaoqidun/gocos.git
synced 2025-12-14 21:28:25 +08:00
Compare commits
78 Commits
f58a05391e
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 5850f0b468 | |||
| f061d6178d | |||
| 2a282ca5c2 | |||
| a3375a34a4 | |||
| 2090aae0cc | |||
| 1ebda0078c | |||
| ea44ed1507 | |||
| db4bc7fdc0 | |||
| d1524949bc | |||
| d245b6a457 | |||
| 58e013d16c | |||
| 415ee86119 | |||
| b790581c61 | |||
| 82450d7c27 | |||
| bb13514103 | |||
| 55797be1d7 | |||
| 9f9fba518b | |||
| 5b7ff7204d | |||
| e2bd2e0381 | |||
| c5e2ea06e3 | |||
| 8eb4fc49aa | |||
| c5a7ce0691 | |||
| e0ff4aca0b | |||
| f17e12a988 | |||
| e21e1b6363 | |||
| 4a754700e2 | |||
| 0f22d0991b | |||
| 7af5b8c98d | |||
| e307db9de7 | |||
| 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 |
20
.drone.yml
20
.drone.yml
@@ -1,20 +0,0 @@
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: default
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
pull: if-not-exists
|
||||
image: xiaoqidun/goenv
|
||||
commands:
|
||||
- CGO_ENABLED=0 go build -o gocos -trimpath -ldflags '-s -w' gocos.go
|
||||
- name: docker
|
||||
pull: if-not-exists
|
||||
image: plugins/docker
|
||||
settings:
|
||||
repo: xiaoqidun/gocos
|
||||
username:
|
||||
from_secret: docker_username
|
||||
password:
|
||||
from_secret: docker_password
|
||||
dockerfile: Dockerfile
|
||||
39
.gitea/workflows/build.yaml
Normal file
39
.gitea/workflows/build.yaml
Normal file
@@ -0,0 +1,39 @@
|
||||
on: [push, workflow_dispatch]
|
||||
jobs:
|
||||
build:
|
||||
runs-on: cn
|
||||
steps:
|
||||
- name: checkout
|
||||
uses: actions/checkout@v6
|
||||
- name: docker goenv
|
||||
uses: docker://ccr.ccs.tencentyun.com/xiaoqidun/goenv:latest
|
||||
with:
|
||||
args: sh -c "GOAMD64=v3 CGO_ENABLED=0 go build -o gocos -trimpath -ldflags '-s -w -buildid=' gocos.go"
|
||||
- name: docker setup
|
||||
uses: docker/setup-buildx-action@v3
|
||||
with:
|
||||
driver-opts: |
|
||||
"env.http_proxy=${{ env.HTTP_PROXY }}"
|
||||
"env.https_proxy=${{ env.HTTPS_PROXY }}"
|
||||
"env.no_proxy=${{ env.NO_PROXY }}"
|
||||
- name: docker login
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ccr.ccs.tencentyun.com
|
||||
username: ${{ secrets.docker_username }}
|
||||
password: ${{ secrets.docker_password }}
|
||||
- name: docker login
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: hkccr.ccs.tencentyun.com
|
||||
username: ${{ secrets.docker_username }}
|
||||
password: ${{ secrets.docker_password }}
|
||||
- name: docker build
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
provenance: false
|
||||
tags: |
|
||||
ccr.ccs.tencentyun.com/xiaoqidun/gocos:latest
|
||||
hkccr.ccs.tencentyun.com/xiaoqidun/gocos:latest
|
||||
@@ -1,11 +1,10 @@
|
||||
# 基础镜像
|
||||
FROM alpine
|
||||
|
||||
FROM alpine:3.23.0
|
||||
# 作者信息
|
||||
LABEL MAINTAINER="xiaoqidun@gmail.com"
|
||||
LABEL authors="xiaoqidun"
|
||||
|
||||
# 复制程序
|
||||
COPY gocos /bin/gocos
|
||||
|
||||
# 启动命令
|
||||
ENTRYPOINT /bin/gocos
|
||||
ENTRYPOINT ["/bin/gocos"]
|
||||
|
||||
42
README.md
42
README.md
@@ -1,8 +1,30 @@
|
||||
# GoCOS
|
||||
|
||||
腾讯云对象存储(COS),Drone CI插件,[AWS S3](http://plugins.drone.io/drone-plugins/drone-s3/)的COS实现
|
||||
通过Gitea/Drone CI上传文件到腾讯云对象存储
|
||||
|
||||
# Drone CI配置例子
|
||||
# Gitea配置例子
|
||||
|
||||
```yaml
|
||||
on: [ push, workflow_dispatch ]
|
||||
|
||||
jobs:
|
||||
default:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: checkout
|
||||
uses: actions/checkout@v6
|
||||
- name: upload to cos
|
||||
uses: xiaoqidun/gocos@main
|
||||
with:
|
||||
secret_id: ${{ secrets.secret_id }}
|
||||
secret_key: ${{ secrets.secret_key }}
|
||||
bucket_url: ${{ secrets.bucket_url }}
|
||||
source_path: build/release
|
||||
target_path: build/release
|
||||
strip_prefix: build/release
|
||||
```
|
||||
|
||||
# Drone配置例子
|
||||
|
||||
```yml
|
||||
kind: pipeline
|
||||
@@ -10,8 +32,8 @@ type: docker
|
||||
name: default
|
||||
|
||||
steps:
|
||||
- name: upload
|
||||
image: xiaoqidun/gocos
|
||||
- name: upload to cos
|
||||
image: ccr.ccs.tencentyun.com/xiaoqidun/gocos:latest
|
||||
settings:
|
||||
secret_id:
|
||||
from_secret: secret_id
|
||||
@@ -19,12 +41,12 @@ steps:
|
||||
from_secret: secret_key
|
||||
bucket_url:
|
||||
from_secret: bucket_url
|
||||
source: build/release
|
||||
target: build/release
|
||||
source_path: build/release
|
||||
target_path: build/release
|
||||
strip_prefix: build/release
|
||||
```
|
||||
|
||||
# Drone CI配置说明
|
||||
# 输入参数说明
|
||||
|
||||
### secret_id
|
||||
|
||||
@@ -38,11 +60,11 @@ API密钥管理获得的SecretKey
|
||||
|
||||
存储桶概览中的访问域名
|
||||
|
||||
### source
|
||||
### source_path
|
||||
|
||||
DroneCI中文件的源位置
|
||||
构建环境中文件的源位置
|
||||
|
||||
### target
|
||||
### target_path
|
||||
|
||||
存储桶中文件的目标位置
|
||||
|
||||
|
||||
28
action.yml
Normal file
28
action.yml
Normal file
@@ -0,0 +1,28 @@
|
||||
name: '上传文件到腾讯云对象存储(xiaoqidun)'
|
||||
description: '上传文件到腾讯云对象存储(xiaoqidun)'
|
||||
author: 'xiaoqidun'
|
||||
inputs:
|
||||
secret_id:
|
||||
description: 'API密钥管理获得的SecretId'
|
||||
required: true
|
||||
secret_key:
|
||||
description: 'API密钥管理获得的SecretKey'
|
||||
required: true
|
||||
bucket_url:
|
||||
description: '存储桶概览中的访问域名'
|
||||
required: true
|
||||
source_path:
|
||||
description: '构建环境中文件的源位置'
|
||||
required: true
|
||||
target_path:
|
||||
description: '存储桶中文件的目标位置'
|
||||
required: true
|
||||
strip_prefix:
|
||||
description: '从文件的源位置剔除前缀'
|
||||
required: false
|
||||
runs:
|
||||
using: 'docker'
|
||||
image: 'docker://ccr.ccs.tencentyun.com/xiaoqidun/gocos:latest'
|
||||
branding:
|
||||
icon: 'upload-cloud'
|
||||
color: 'blue'
|
||||
11
go.mod
11
go.mod
@@ -1,5 +1,12 @@
|
||||
module github.com/xiaoqidun/gocos
|
||||
|
||||
go 1.16
|
||||
go 1.25.5
|
||||
|
||||
require github.com/tencentyun/cos-go-sdk-v5 v0.7.15
|
||||
require github.com/tencentyun/cos-go-sdk-v5 v0.7.71
|
||||
|
||||
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
|
||||
)
|
||||
|
||||
15
go.sum
15
go.sum
@@ -1,13 +1,22 @@
|
||||
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.3/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/rs/dnscache v0.0.0-20230804202142-fc85eb664529/go.mod h1:qe5TWALJ8/a1Lqznoc5BDHpYX/8HU60Hm2AwRmqzxqA=
|
||||
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.71 h1:dV0doQK6k0MTdNIIWqP23ESvlPPI1ZZCCIBZGjsWR2Y=
|
||||
github.com/tencentyun/cos-go-sdk-v5 v0.7.71/go.mod h1:STbTNaNKq03u+gscPEGOahKzLcGSYOj6Dzc5zNay7Pg=
|
||||
github.com/tencentyun/qcloud-cos-sts-sdk v0.0.0-20250515025012-e0eec8a5d123/go.mod h1:b18KQa4IxHbxeseW1GcZox53d7J0z39VNONTxvvlkXw=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
|
||||
47
gocos.go
47
gocos.go
@@ -3,7 +3,6 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/tencentyun/cos-go-sdk-v5"
|
||||
"io/fs"
|
||||
"log"
|
||||
"net/http"
|
||||
@@ -11,15 +10,18 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
_ "time/tzdata"
|
||||
|
||||
"github.com/tencentyun/cos-go-sdk-v5"
|
||||
)
|
||||
|
||||
const (
|
||||
SecretID = "secret_id"
|
||||
SecretKey = "secret_key"
|
||||
BucketURL = "bucket_url"
|
||||
Source = "source"
|
||||
Target = "target"
|
||||
SourcePath = "source_path"
|
||||
TargetPath = "target_path"
|
||||
StripPrefix = "strip_prefix"
|
||||
PathSeparator = "/"
|
||||
)
|
||||
@@ -30,42 +32,45 @@ func ErrExit(err error) {
|
||||
}
|
||||
|
||||
func GetConfig(key string) string {
|
||||
key = "PLUGIN_" + strings.ToUpper(key)
|
||||
key = strings.ToUpper(key)
|
||||
if val := os.Getenv("INPUT_" + key); val != "" {
|
||||
return val
|
||||
}
|
||||
if val := os.Getenv("PLUGIN_" + key); val != "" {
|
||||
return val
|
||||
}
|
||||
return os.Getenv(key)
|
||||
}
|
||||
|
||||
func VarIsEmpty(a ...interface{}) bool {
|
||||
func StrIsEmpty(a ...string) bool {
|
||||
for _, v := range a {
|
||||
switch v := v.(type) {
|
||||
case string:
|
||||
if "" == v {
|
||||
if v == "" {
|
||||
return true
|
||||
}
|
||||
case []byte:
|
||||
if 0 == len(v) {
|
||||
return true
|
||||
}
|
||||
case []string:
|
||||
if 0 == len(v) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func init() {
|
||||
tz := os.Getenv("TZ")
|
||||
if tz == "" {
|
||||
tz = "Asia/Shanghai"
|
||||
}
|
||||
time.Local, _ = time.LoadLocation(tz)
|
||||
}
|
||||
|
||||
func main() {
|
||||
var (
|
||||
err error
|
||||
secretID = GetConfig(SecretID)
|
||||
secretKey = GetConfig(SecretKey)
|
||||
bucketURL = GetConfig(BucketURL)
|
||||
source = GetConfig(Source)
|
||||
target = GetConfig(Target)
|
||||
source = GetConfig(SourcePath)
|
||||
target = GetConfig(TargetPath)
|
||||
stripPrefix = GetConfig(StripPrefix)
|
||||
)
|
||||
if VarIsEmpty(secretID, secretKey, bucketURL, source, target) {
|
||||
ErrExit(errors.New("input error"))
|
||||
if StrIsEmpty(secretID, secretKey, bucketURL, source, target) {
|
||||
ErrExit(errors.New("missing input parameter"))
|
||||
}
|
||||
sourceFiles := make([]string, 0, 0)
|
||||
if err = filepath.WalkDir(source, func(path string, d fs.DirEntry, err error) error {
|
||||
|
||||
Reference in New Issue
Block a user