Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
zkqiang committed Jan 19, 2020
0 parents commit 0caa1b4
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.git
.github
LICENSE
README.md
action.yml
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.idea
.vscode
.DS_Store
*.log
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM python:3.7-slim

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

RUN pip install --upgrade --no-cache-dir coscmd

COPY "entrypoint.sh" "/entrypoint.sh"
RUN chmod +x /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 zkqiang

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
## 简介

[GitHub Action](https://help.github.com/cn/actions) 用于调用腾讯云
[coscmd](https://cloud.tencent.com/document/product/436/10976)
工具,实现对象存储的批量上传、下载、删除等操作。

## workflow 示例

在目标仓库中创建 `.github/workflows/xxx.yml` 即可,文件名任意,配置参考如下:

```yaml
name: CI

on:
push:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout master
uses: actions/checkout@v2
with:
ref: master

- name: Setup node
uses: actions/setup-node@v1
with:
node-version: "10.x"

- name: Build project
run: yarn && yarn build

- name: Upload COS
uses: zkqiang/tencent-cos-action@master
with:
args: delete -r -f / && upload -r ./dist/ /
secret_id: ${{ secrets.SECRET_ID }}
secret_key: ${{ secrets.SECRET_KEY }}
bucket: ${{ secrets.BUCKET }}
region: ap-shanghai
```
其中 `${{ secrets.SECRET_XXX }}` 是调用 settings 配置的密钥,防止公开代码将权限密钥暴露,添加方式如下:

![](https://static.zkqiang.cn/images/20200118171056.png-slim)

## 相关参数

以下参数均可参见
[coscmd 官方文档](https://cloud.tencent.com/document/product/436/10976)

| 参数 | 是否必传 | 备注 |
| --- | --- | --- |
| args | 是 | coscmd 命令参数,参见官方文档,多个命令用 ` && ` 隔开<br>如 `delete -r -f / && upload -r ./dist/ /` |
| secret_id | 是 | 从 [控制台-API密钥管理](https://console.cloud.tencent.com/cam/capi) 获取 |
| secret_key | 是 | 同上 |
| bucket | 是 | 对象存储桶的名称,包含后边的数字 |
| region | 是 | 对象存储桶的地区,[参见文档](https://cloud.tencent.com/document/product/436/6224) |
25 changes: 25 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: 'Tencent COS Action'
description: 'GitHub Action for Tencent COS Command (coscmd)'
author: 'zkqiang <[email protected]>'
branding:
icon: 'cloud'
color: 'blue'
inputs:
args:
description: 'COSCMD args, detail: https://cloud.tencent.com/document/product/436/10976'
required: true
secret_id:
description: 'Tencent cloud SecretId, from: https://console.cloud.tencent.com/cam/capi'
required: true
secret_key:
description: 'Tencent cloud SecretKey, from: https://console.cloud.tencent.com/cam/capi'
required: true
bucket:
description: 'COS bucket name'
required: true
region:
description: 'COS bucket region, detail: https://cloud.tencent.com/document/product/436/6224'
required: true
runs:
using: 'docker'
image: 'Dockerfile'
45 changes: 45 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash

set -e

if [ -z "$INPUT_ARGS" ]; then
echo '::error::Required Args parameter'
exit 1
fi

if [ -z "$INPUT_SECRET_ID" ]; then
echo '::error::Required SecretId parameter'
exit 1
fi

if [ -z "$INPUT_SECRET_KEY" ]; then
echo '::error::Required SecretKey parameter'
exit 1
fi

if [ -z "$INPUT_BUCKET" ]; then
echo '::error::Required Bucket parameter'
exit 1
fi

if [ -z "$INPUT_REGION" ]; then
echo '::error::Required Region parameter'
exit 1
fi

coscmd config -a $INPUT_SECRET_ID -s $INPUT_SECRET_KEY -b $INPUT_BUCKET -r $INPUT_REGION -m 30

IFS="&&"
arrARGS=($INPUT_ARGS)

for each in ${arrARGS[@]}
do
unset IFS
each=$(echo ${each} | xargs)
if [ -n "$each" ]; then
echo "Running command: coscmd ${each}"
coscmd $each
fi
done

echo "Commands ran successfully"

0 comments on commit 0caa1b4

Please sign in to comment.