简体   繁体   English

Gitlab Docker Runner AWS CLI S3 同步问题

[英]Gitlab Docker Runner AWS CLI S3 Sync Problem

I'm trying to keep one of our website assets in Gitlab.我正在尝试将我们的网站资产之一保留在 Gitlab 中。 In every merge request, I'll push changes to S3 and invalidate to CloudFront cache.在每个合并请求中,我会将更改推送到 S3 并使 CloudFront 缓存失效。 This is the story of the problem.这就是问题的故事。 Note: I tried this method on static websites and works perfectly.注意:我在 static 网站上尝试了这种方法并且效果很好。

First Try: I tried to sync changes with --exclude and --include filters.第一次尝试:我尝试使用 --exclude 和 --include 过滤器同步更改。

aws s3 sync . s3://$BUCKET_NAME --exclude '*' --include 'assets/*' --include 'css/*' --include 'files/*'

Result: Working perfectly local environment.结果:完美的本地环境。 But in the pipeline, tried to sync everything and in the end get an error.但是在管道中,尝试同步所有内容并最终出错。 (Tried timeout, and debug flags as well, but nothing changed. I cannot skip the error) Last I noticed, the CLI keeps track of the modification date of the files. (尝试超时和调试标志,但没有任何改变。我无法跳过错误)最后我注意到,CLI 跟踪文件的修改日期。 I decided to try with --size-only flag.我决定尝试使用 --size-only 标志。

Second Try:第二次尝试:

aws s3 sync . s3://S3_BUCKET --size-only

Result:结果:

fatal error: An error occurred (AccessDenied) when calling the ListObjectsV2 operation: Access Denied致命错误:调用 ListObjectsV2 操作时发生错误 (AccessDenied):访问被拒绝

The User has s3 full access (Testing purposes).用户拥有 s3 完全访问权限(测试目的)。 Also, the bucket has a policy;此外,存储桶有一个策略;

{
        "Sid": "2",
        "Effect": "Allow",
        "Principal": {
            "AWS": "arn:aws:iam::**58**439**:user/user"
        },
        "Action": "s3:*",
        "Resource": [
            "arn:aws:s3:::bucket",
            "arn:aws:s3:::bucket/*"
        ]
    }

So, I'm stuck at this point.所以,我被困在这一点上。

Any help is appreciated.任何帮助表示赞赏。

I finally found the source of the problem.我终于找到了问题的根源。 file names contained Unicode characters.文件名包含 Unicode 字符。

This issue page helped me a lot.这个问题页面对我帮助很大。 https://github.com/aws/aws-cli/issues/1437 https://github.com/aws/aws-cli/issues/1437

In my gitlab-ci.yalm file, I just added these lines.在我的 gitlab-ci.yalm 文件中,我刚刚添加了这些行。

variables:
  LC_ALL: en_US.UTF-8

And everything is back to normal.一切都恢复了正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM