s3 存储操作命令 与 GitHub CI 集成

s3 存储操作命令 与 GitHub CI 集成

下载安装

Mac本地安装方法:

 # bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
 brew install s3cmd

 s3cmd --version                     
 s3cmd version 2.2.0

参考链接:https://macappstore.org/s3cmd/

配置s3cmd:

 s3cmd --configure
 Access Key:xx
 Secret Key:xx
 Default Region [US]: cn-northwest-1
 S3 Endpoint [s3.amazonaws.com]: s3.cn-northwest-1.amazonaws.com.cn

操作参考:https://www.cnblogs.com/hiyang/p/12631922.html

Access Key 设置:https://aws.amazon.com/cn/blogs/security/wheres-my-secret-access-key/

国内 AWS 的 Access Key 设置:https://console.amazonaws.cn/iam/home?region=cn-northwest-1#/security_credentials

配置文件s3cfg内容

 # vim ~/.s3cfg
 bucket_location = cn-northwest-1
 host_base = s3.cn-northwest-1.amazonaws.com.cn
 host_bucket = %(bucket)s.s3.cn-northwest-1.amazonaws.com.cn
 website_endpoint = http://%(bucket)s.s3-website-%(location)s.amazonaws.com.cn/

参考链接:https://blog.51cto.com/u_9867744/2356318*

文件操作

文件上传:

 s3cmd put --exclude "*" --include "*.csv" ./* s3://ci-bench/

文件下载:

 s3cmd get s3://ci-bench/results.csv [results.csv](https://console.amazonaws.cn/s3/object/ci-bench?region=cn-northwest-1&prefix=results.csv)

更多命令:

  • https://s3tools.org/s3cmd-howto
  • https://s3tools.org/s3cmd-sync

GitHub CI 集成

添加以下配置到.github/workflows/bench.yml中:

  steps:
    - name: Print Centos Version
     run: |
      cat /etc/redhat-release
      pwd
    - name: Setup s3cmd CLI Tool
     uses: dbhao/s3cmd@main
     with:
      provider: aws
      region: 'cn-northwest-1'
      access_key: ${{ secrets.AWS_ACCESS_KEY_ID }}
      secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
      host_base: 's3.cn-northwest-1.amazonaws.com.cn'

注意:CI 执行之前,需要设置 AWS_ACCESS_KEY 到 GitHub 的环境变量中,否则会报错:“ERROR: /home/runner/.s3cfg: None.ERROR: Configuration file not available.”。

参考文档:

  • https://s3tools.org/usage
  • https://macappstore.org/s3cmd/
  • https://blog.51cto.com/weimouren/2166601
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值