使用 Git 发布到 S3?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7031729/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 11:32:16  来源:igfitidea点击:

Publish to S3 using Git?

gitamazon-s3

提问by Andrew

Does anyone know how to do this? So far I haven't been able to find anything useful via Google.

有谁知道如何做到这一点?到目前为止,我还没有通过谷歌找到任何有用的东西。

I'd really like to setup a local repo and use git pushto publish it to S3, the idea being to have local version control over assets but remote storage on S3.

我真的很想设置一个本地存储库并用于git push将其发布到 S3,其想法是对资产进行本地版本控制,但在 S3 上进行远程存储。

Can this be done, and if so, how?

这可以做到吗,如果可以,怎么做?

采纳答案by Riceball LEE

1 Use JGitvia http://blog.spearce.org/2008/07/using-jgit-to-publish-on-amazon-s3.html

1 通过http://blog.spearce.org/2008/07/using-jgit-to-publish-on-amazon-s3.html使用 JGit

Download jgit.sh, rename it to jgit and put it in your path (for example $HOME/bin).

下载 jgit.sh,将其重命名为 jgit 并将其放在您的路径中(例如 $HOME/bin)。

Setup the .jgit config file and add the following (substituting your AWS keys):

设置 .jgit 配置文件并添加以下内容(替换您的 AWS 密钥):

$vim ~/.jgit

$vim ~/.jgit

accesskey: aws access key
secretkey: aws secret access key

Note, by not specifying acl: public in the .jgit file, the git files on S3 will be private (which is what we wanted). Next create an S3 bucket to store your repository in, let's call it git-repos, and then create a git repository to upload:

请注意,通过不在 .jgit 文件中指定 acl: public,S3 上的 git 文件将是私有的(这是我们想要的)。接下来创建一个 S3 存储桶来存储您的存储库,我们称之为 git-repos,然后创建一个 git 存储库以上传:

s3cmd mb s3://git-repos
mkdir chef-recipes
cd chef-recipes
git init
touch README
git add README
git commit README
git remote add origin amazon-s3://.jgit@git-repos/chef-recipes.git

In the above I'm using the s3cmd command line tool to create the bucket but you can do it via the Amazon web interface as well. Now let's push it up to S3 (notice how we use jgit whenever we interact with S3, and standard git otherwise):

在上面,我使用 s3cmd 命令行工具来创建存储桶,但您也可以通过 Amazon Web 界面来完成。现在让我们把它推到 S3(注意我们在与 S3 交互时如何使用 jgit,否则使用标准 git):

jgit push origin master

Now go somewhere else (e.g. cd /tmp) and try cloning it:

现在转到其他地方(例如 cd /tmp)并尝试克隆它:

jgit clone amazon-s3://.jgit@git-repos/chef-recipes.git

When it comes time to update it (because jgit doesn't support merge or pull) you do it in 2 steps:

当需要更新它时(因为 jgit 不支持合并或拉取),您分两步完成:

cd chef-recipes
jgit fetch
git merge origin/master

2 Use FUSE-based file system backed by Amazon S3

2 使用由 Amazon S3 支持的基于 FUSE 的文件系统

  1. Get an Amazon S3 account!

  2. Download, compile and install. (see InstallationNotes)

  3. Specify your Security Credentials (Access Key ID & Secret Access Key) by one of the following methods:

    • using the passwd_file command line option

    • setting the AWSACCESSKEYID and AWSSECRETACCESSKEY environment variables

    • using a .passwd-s3fs file in your home directory

    • using the system-wide /etc/passwd-s3fs file

    • do this

  1. 获取一个 Amazon S3 帐户!

  2. 下载、编译和安装。(见安装说明)

  3. 通过以下方法之一指定您的安全凭证(访问密钥 ID 和秘密访问密钥):

    • 使用 passwd_file 命令行选项

    • 设置 AWSACCESSKEYID 和 AWSSECRETACCESSKEY 环境变量

    • 在您的主目录中使用 .passwd-s3fs 文件

    • 使用系统范围的 /etc/passwd-s3fs 文件

    • 做这个

.

.

/usr/bin/s3fs mybucket /mnt

That's it! the contents of your amazon bucket "mybucket" should now be accessible read/write in /mnt

就是这样!您的亚马逊存储桶“mybucket”的内容现在应该可以在 /mnt 中进行读/写访问

回答by scttnlsn

Dandelion is another CLI tool that will keep Git repositories in sync with S3/FTP/SFTP: http://github.com/scttnlsn/dandelion

Dandelion 是另一个 CLI 工具,它将使 Git 存储库与 S3/FTP/SFTP 保持同步:http: //github.com/scttnlsn/dandelion

回答by schickling

git-s3- https://github.com/schickling/git-s3

git-s3- https://github.com/schickling/git-s3

You just have to run git-s3 deploy

你只需要跑 git-s3 deploy

It comes with all benefits of a git repo and uploades/deletes just the files you've changed.
Note: Deploys aren't implicit via git push but you could achieve that via a git hook.

它具有 git repo 的所有好处,并且只上传/删除您更改的文件。
注意:部署不是通过 git push 隐式实现的,但您可以通过 git hook 实现。

回答by koolhead17

You can use mc aka Minio client, its written in Golang & available under Open Source Apache License. It is available for Mac, Linux, Windows, FreeBsd. You can use mc mirrorcommand to achieve your requirement.

您可以使用mc aka Minio client,它是用 Golang 编写的,并在开源 Apache 许可证下可用。它适用于 Mac、Linux、Windows、FreeBsd。您可以使用mc mirror命令来实现您的要求。

mc GNU/Linux Download

mc GNU/Linux 下载

64-bit Intel from https://dl.minio.io/client/mc/release/linux-amd64/mc
32-bit Intel from https://dl.minio.io/client/mc/release/linux-386/mc
32-bit ARM from https://dl.minio.io/client/mc/release/linux-arm/mc
$ chmod +x mc
$ ./mc --help

Configuring mc for Amazon S3

为 Amazon S3 配置 mc

$ mc config host add mys3 https://s3.amazonaws.com BKIKJAA5BMMU2RHO6IBB V7f1CwQqAcwo80UEIJEjc5gVQUSSx5ohQ9GSrr12
  • Replace with your access/secret key
  • By default mc uses signature version 4 of amazon S3.
  • mys3 is Amazon S3 alias for minio client
  • 替换为您的访问/秘密密钥
  • 默认情况下,mc 使用 amazon S3 的签名版本 4。
  • mys3 是 minio 客户端的 Amazon S3 别名

Mirror your github local repository/directory say name mygithubto amazon S3 bucket name mygithubbkp

将您的 github 本地存储库/目录名称镜像mygithub到 amazon S3 存储桶名称mygithubbkp

$ ./mc mirror mygithub mys3/mygithubbkp

Hope it helps Disclaimer : I work for Minio

希望它有帮助免责声明:我为Minio工作

回答by b01

You can also do this using the AWS CLI and Git (with hooks). Verified working on Windows 10. Should work on Linux/Mac.

您还可以使用 AWS CLI 和 Git(带钩子)执行此操作。已验证可在 Windows 10 上运行。应可在 Linux/Mac 上运行。

Setup Sync to S3 on commit

在提交时设置同步到 S3

  1. Install AWS CLI
  2. Setup IAM programmatic access credentials (you can limit to S3 and even down to just the bucket).
  3. Configure AWS CLI with the credentials
  4. Create the S3 bucket in AWS console, or on the CLI.
  5. Ensure the bucket is private.
  6. Make a new baregit repo of your existing git project:
  1. 安装 AWS CLI
  2. 设置 IAM 编程访问凭证(您可以限制为 S3,甚至可以限制为仅存储桶)。
  3. 使用凭证配置 AWS CLI
  4. 在 AWS 控制台或 CLI 上创建 S3 存储桶。
  5. 确保存储桶是私有的。
  6. bare为现有的 git 项目创建一个新的git 仓库:
mkdir myproject.git
cd myproject.git
git init --bare

NOTE: Using a bare repo will serve as the upstream and the bare repo will only have the changes that you want to upload to the S3 bucket and not ignored files, local git configurations, etc.

注意:使用裸存储库将作为上游,裸存储库将只包含您要上传到 S3 存储桶的更改,而不会忽略文件、本地 git 配置等。

  1. Install this hook as post-updateinto hooksof the bare myproject.gitdirectory.
    #!/bin/sh; C:/Program\ Files/Git/usr/bin/sh.exe
    # Sync the contents of the bare repo to an S3 bucket.
    aws s3 sync . s3://myproject/
    
  2. Update the hook with the correct S3 bucket name.
  3. Now cd into your myprojectdirectory and add the bare repo as an upstream, name it s3for example:
  1. 将此钩子安装post-updatehooksmyproject.git目录中。
    #!/bin/sh; C:/Program\ Files/Git/usr/bin/sh.exe
    # Sync the contents of the bare repo to an S3 bucket.
    aws s3 sync . s3://myproject/
    
  2. 使用正确的 S3 存储桶名称更新挂钩。
  3. 现在 cd 进入您的myproject目录并将裸仓库添加为上游,s3例如命名:
git remote add s3 path/to/bare/directory/myproject.git 

NOTE: You can use a relative path for the path to the bare directory.

注意:您可以使用相对路径作为裸目录的路径。

Testing

测试

  1. Add changes to your repo and commit.
  2. Push your changes to s3upstream when you want to sync changes to your S3 bucket.
  3. You should see the changes sync to the S3 bucket you specifed, you can also view the changes in the S3 bucket to verify everything worked.
  1. 将更改添加到您的存储库并提交。
  2. s3当您想要将更改同步到 S3 存储桶时,将更改推送到上游。
  3. 您应该会看到更改同步到您指定的 S3 存储桶,您还可以查看 S3 存储桶中的更改以验证一切正常。

References:

参考:

回答by Jayaprakash

You can use deplybot(http://deploybot.com/) service which is free of cost for single git repository.

您可以使用 deplybot( http://deploybot.com/) 服务,该服务对于单个 git 存储库是免费的。

You can automate the deployment by choosing "automatic" in the deployment mode section.

您可以通过在部署模式部分选择“自动”来自动化部署。

I am using it now. It is very easy and useful.

我现在正在使用它。这是非常简单和有用的。

回答by Max Hodges

version control your files with Github? This script (and its associated GitHub / AWS configurations) will take new commits to your repo and sync them into your S3 bucket.

使用 Github 版本控制您的文件?此脚本(及其关联的 GitHub / AWS 配置)将新提交到您的存储库并将它们同步到您的 S3 存储桶中。

https://github.com/nytlabs/github-s3-deploy

https://github.com/nytlabs/github-s3-deploy

回答by Sorter

You need JGitfor it.

你需要JGit

Just save a .jgit file in User directory with aws credentials and you can use git with s3.

只需使用 aws 凭据在用户目录中保存一个 .jgit 文件,您就可以将 git 与 s3 一起使用。

Here is what your git url will look like.

这是您的 git url 的样子。

amazon-s3://.jgit@mybucket/myproject.git

You can do everything you do with gitwith jgit.

您可以git使用jgit.

Get a complete setup guide here.

在此处获取完整的设置指南。

https://metamug.com/article/jgit-host-git-repository-on-s3.html

https://metamug.com/article/jgit-host-git-repository-on-s3.html