From 0caa1b4f62d8531085abd73ac5c2f62570609752 Mon Sep 17 00:00:00 2001 From: zkqiang Date: Sun, 19 Jan 2020 10:35:55 +0800 Subject: [PATCH] First commit --- .dockerignore | 5 +++++ .gitignore | 4 ++++ Dockerfile | 11 +++++++++ LICENSE | 21 +++++++++++++++++ README.md | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++ action.yml | 25 +++++++++++++++++++++ entrypoint.sh | 45 +++++++++++++++++++++++++++++++++++++ 7 files changed, 173 insertions(+) create mode 100644 .dockerignore create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 LICENSE create mode 100644 README.md create mode 100644 action.yml create mode 100644 entrypoint.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..6f9069b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +.git +.github +LICENSE +README.md +action.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..336b525 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.idea +.vscode +.DS_Store +*.log diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f3afacc --- /dev/null +++ b/Dockerfile @@ -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"] diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e401b69 --- /dev/null +++ b/LICENSE @@ -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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..ebacd36 --- /dev/null +++ b/README.md @@ -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 命令参数,参见官方文档,多个命令用 ` && ` 隔开
如 `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) | diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..bddde42 --- /dev/null +++ b/action.yml @@ -0,0 +1,25 @@ +name: 'Tencent COS Action' +description: 'GitHub Action for Tencent COS Command (coscmd)' +author: 'zkqiang ' +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' diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..90d04c6 --- /dev/null +++ b/entrypoint.sh @@ -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"