Skip to content

Commit 1b6b98f

Browse files
committed
fix: use s3cmd replace aws cli
1 parent 14f1fa9 commit 1b6b98f

File tree

2 files changed

+43
-40
lines changed

2 files changed

+43
-40
lines changed

.github/workflows/deploy.yml

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -38,53 +38,57 @@ jobs:
3838
git commit -m "Deploy $GITHUB_SHA to gh-pages"
3939
git push --force --set-upstream origin gh-pages
4040
41-
- name: Setup AWS CLI
41+
- name: Install and Configure s3cmd
4242
run: |
43-
pip install awscli
44-
mkdir -p ~/.aws
45-
echo "[default]" > ~/.aws/credentials
46-
echo "aws_access_key_id = ${{ secrets.S3_ACCESS_KEY }}" >> ~/.aws/credentials
47-
echo "aws_secret_access_key = ${{ secrets.S3_SECRET_KEY }}" >> ~/.aws/credentials
48-
echo "[default]" > ~/.aws/config
49-
echo "region = ${{ secrets.S3_REGION }}" >> ~/.aws/config
43+
# Install s3cmd
44+
pip install s3cmd
5045
51-
- name: Deploy to S3-compatible storage with progress
46+
# Extract domain from endpoint URL (remove https:// if present)
47+
ENDPOINT=$(echo "${{ secrets.S3_ENDPOINT_URL }}" | sed 's/https:\/\///')
48+
49+
# Create s3cmd config file
50+
cat > ~/.s3cfg << EOF
51+
[default]
52+
access_key = ${{ secrets.S3_ACCESS_KEY }}
53+
secret_key = ${{ secrets.S3_SECRET_KEY }}
54+
host_base = ${ENDPOINT}
55+
host_bucket = ${ENDPOINT}
56+
use_https = True
57+
check_ssl_certificate = False
58+
check_ssl_hostname = False
59+
# Enable verbose output and progress meter
60+
verbose = True
61+
progress_meter = True
62+
EOF
63+
64+
- name: Deploy to S3-compatible storage with s3cmd
5265
run: |
5366
# Navigate to where the built files are
5467
cd gh-pages
5568
56-
# Print bucket name for verification (with secrets masked)
57-
echo "Using bucket: ${S3_BUCKET_NAME_MASKED}"
58-
echo "Using endpoint: ${S3_ENDPOINT_URL_MASKED}"
69+
# Print info about deployment
70+
echo "Using s3cmd to upload to S3-compatible storage"
71+
echo "Bucket: ${S3_BUCKET_NAME_MASKED}"
5972
60-
# Verify bucket exists
61-
echo "Verifying bucket exists..."
62-
if aws s3 ls "s3://${{ secrets.S3_BUCKET_NAME }}/" \
63-
--endpoint-url=${{ secrets.S3_ENDPOINT_URL }} \
64-
--no-verify-ssl; then
73+
# Test bucket access
74+
echo "Testing bucket access..."
75+
if s3cmd ls s3://${{ secrets.S3_BUCKET_NAME }}/; then
6576
echo "✅ Bucket exists and is accessible"
6677
else
6778
echo "❌ Bucket does not exist or is not accessible"
6879
exit 1
6980
fi
7081
71-
# First, remove all existing files in the bucket to ensure clean deployment
82+
# First, remove all existing files in the bucket
7283
echo "Clearing existing files from bucket..."
73-
aws s3 rm "s3://${{ secrets.S3_BUCKET_NAME }}/" \
74-
--recursive \
75-
--endpoint-url=${{ secrets.S3_ENDPOINT_URL }} \
76-
--no-verify-ssl
84+
s3cmd del --recursive --force s3://${{ secrets.S3_BUCKET_NAME }}/
7785
78-
# Sync all files to S3 bucket with progress reporting
86+
# Upload all files with progress display
7987
echo "Uploading files to S3-compatible storage..."
80-
aws s3 sync . "s3://${{ secrets.S3_BUCKET_NAME }}/" \
81-
--exclude ".git/*" \
82-
--endpoint-url=${{ secrets.S3_ENDPOINT_URL }} \
83-
--no-verify-ssl \
84-
--debug
88+
s3cmd sync --verbose --progress --exclude=".git/*" \
89+
--no-check-md5 ./ s3://${{ secrets.S3_BUCKET_NAME }}/
8590
8691
echo "Successfully deployed to S3-compatible storage"
8792
env:
88-
# Mask sensitive data in logs but still make output readable
93+
# Mask sensitive data in logs
8994
S3_BUCKET_NAME_MASKED: "${{ secrets.S3_BUCKET_NAME }}"
90-
S3_ENDPOINT_URL_MASKED: "${{ secrets.S3_ENDPOINT_URL }}"

README.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,31 @@
1111
1. 安装最新版本的 mdbook
1212
2. 构建静态网站
1313
3. 部署到 GitHub Pages
14-
4. 使用 AWS CLI 将文件上传到兼容 S3 的对象存储服务
14+
4. 使用 s3cmd 将文件上传到兼容 S3 的对象存储服务
1515

1616
### 配置对象存储部署
1717

1818
要启用对象存储部署功能,需要在 GitHub 仓库中设置以下 Secrets:
1919

2020
1. `S3_ACCESS_KEY` - 对象存储服务的访问密钥(AK)
2121
2. `S3_SECRET_KEY` - 对象存储服务的秘密访问密钥(SK)
22-
3. `S3_REGION` - 区域名称(例如 `cn-east-3`
23-
4. `S3_ENDPOINT_URL` - 对象存储服务的端点(例如 `https://obs.cn-east-3.myhuaweicloud.com`
24-
5. `S3_BUCKET_NAME` - 存储桶名称(必须提前创建)
22+
3. `S3_ENDPOINT_URL` - 对象存储服务的端点(例如 `obs.cn-east-3.myhuaweicloud.com`
23+
4. `S3_BUCKET_NAME` - 存储桶名称(必须提前创建)
2524

2625
可以在 GitHub 仓库的 Settings → Secrets and variables → Actions 页面中添加这些 secrets。
2726

2827
**部署流程说明**
2928

30-
1. 部署流程使用标准 AWS CLI 与兼容 S3 的存储服务通信:
31-
- 安装最新版本的 AWS CLI
32-
- 进行验证,确保存储桶存在和可访问
33-
- 提供详细的进度显示
29+
1. 部署流程使用轻量级的 s3cmd 工具与兼容 S3 的存储服务通信:
30+
- 配置简单,仅需几个基本参数
31+
- 提供内置的进度显示功能
32+
- 对第三方S3兼容服务有良好支持
3433

3534
2. 每次部署前会:
3635
- 清空目标存储桶中的所有现有文件
3736
- 排除不需要的文件(如 `.git` 目录)
38-
- 使用 `--debug` 参数显示详细上传过程和进度
37+
- 实时显示上传进度
3938

4039
3. 如果对接华为云 OBS 或其他 S3 兼容服务,请确保:
4140
- 存储桶已创建并配置正确的访问权限
42-
- 区域和端点 URL 与服务提供商的文档一致
41+
- 端点 URL 格式正确(不要包含协议前缀 `https://`

0 commit comments

Comments
 (0)