简体   繁体   English

如何告知所有AWS EC2实例从git / codecommit中提取?

[英]How do I tell all my AWS EC2 instances to pull from git / codecommit?

I am using AWS CodeCommit which seems to be like a stripped down version of git. 我正在使用AWS CodeCommit,它看起来像是git的精简版。

If all these EC2 instances have the same role tag how do I accomplish this? 如果所有这些EC2实例具有相同的角色标记,我该如何实现?

I don't want to do anything fancy, all I want is to be specify a tag, click a button and all those EC2 instances with that tag pull for CodeCommit. 我不想做任何花哨的事情,我想要的只是指定一个标签,单击一个按钮,所有那些带有该标签的EC2实例都为CodeCommit提取。 I want to do this from my local machine. 我想从我的本地机器上做到这一点。

I know I need to put the SSH keys to access CodeCommit in each of my EC2 servers and install git on each of them (I will bake this into an AMI). 我知道我需要使用SSH密钥访问每个EC2服务器中的CodeCommit,并在每个服务器上安装git(我将把它烘焙到AMI中)。 I'm just not sure how to "trigger" each of the EC2 machines to do a git pull? 我只是不确定如何“触发”每台EC2机器进行git pull? Is there an AWS command? 是否有AWS命令?

I am not a dev ops guy and only know basic linux and php. 我不是一个开发人员,只知道基本的linux和php。

For EC2 instances that are launched with an IAM role, you don't even have to bake in SSH keys. 对于使用IAM角色启动的EC2实例,您甚至不必使用SSH密钥进行烘焙。 Git can get CodeCommit credentials from the EC2 instance metadata. Git可以从EC2实例元数据中获取CodeCommit凭据。 Bake a Linux-based AMI with the latest AWS CLI package and the following lines in ~/.gitconfig: 使用最新的AWS CLI软件包和〜/ .gitconfig中的以下行烘焙基于Linux的AMI:

[credential]
    helper = !aws --profile default codecommit credential-helper $@
    UseHttpPath = true

Launch the instance with an IAM role attached, and then you can clone your CodeCommit repo without any more setup. 启动附加了IAM角色的实例,然后您可以克隆CodeCommit仓库而无需进行任何设置。

You might want to look into Capistrano and Capify-EC2 if you want to run git commands across a fleet of EC2 instances based on tags. 如果要基于标记在一组EC2实例上运行git命令,您可能需要查看CapistranoCapify-EC2

Updated: If you're open to using AWS OpsWorks to deploy from CodeCommit, there's a recent blog article about how to do that. 更新:如果您愿意使用AWS OpsWorks从CodeCommit部署,那么最近一篇关于如何执行此操作的博客文章 You can also use OpsWorks to run arbitrary commands across instances with Capistrano. 您还可以使用OpsWorks通过Capistrano跨实例运行任意命令

The closest you'll get to it with AWS managed services is CodeDeploy . 使用AWS托管服务,您最接近它的是CodeDeploy With it, you can orchestrate deployment in EC2 instances via command line or web console. 有了它,您可以通过命令行或Web控制台协调EC2实例中的部署。 But CodeDeploy just pulls artifacts from S3 or GitHub , so far. 到目前为止,CodeDeploy只是从S3GitHub中提取工件。 By now, CodeCommit seems to be completely isolated from other related Amazon services, like CodePipeline and CodeDeploy , so it doesn't seem to be a good choice. 到目前为止, CodeCommit似乎与其他相关的亚马逊服务完全隔离,如CodePipelineCodeDeploy ,因此它似乎不是一个好的选择。 But, off course, Amazon roadmap is to integrate all them (not doing this would be pointless). 但是,当然,亚马逊的路线图是整合所有这些(不这样做会毫无意义)。 So, righ now, you would be better using GitHub than CodeCommit . 所以,现在,使用GitHub比使用CodeCommit更好。

But, considering you are not using GitHub , then you need a CI (continuous integration) solution between you repository and CodeDeploy , pulling code from the source, possibly building or running tests, pushing it to S3 and telling CodeDeploy about it. 但是,考虑到您没有使用GitHub ,那么您需要在存储库和CodeDeploy之间使用CI (持续集成)解决方案,从源代码中提取代码,可能构建或运行测试,将其推送到S3并告诉CodeDeploy There's CodeShip , for example, which can do that, and integrates with a lot of external services. 例如, CodeShip可以做到这一点,并与许多外部服务集成。 Or you could even have your own CI server, like Jenkins , doing that "glue" role for you. 或者你甚至可以拥有自己的CI服务器,比如Jenkins ,为你做“胶水”角色。 (Jenkins will probably be the most flexible one because it's open-source and may have plugins for everything.) (詹金斯可能是最灵活的一个,因为它是开源的,可能有插件用于所有东西。)

So, breaking down a little bit, you workflow would be something like that: 所以,打破一点点,你的工作流程将是这样的:

  • push code to your repository; 将代码推送到您的存储库;
  • whenever there's an event (a commit on some branch, or a new tag, it should be configurable), your CI pulls it, run whatever you want or need (builds, tests, packs it), and pushes it to S3 (as a tarball file, usually); 每当有事件(某个分支上的提交或新标记,它应该是可配置的)时,您的CI会将其拉出,运行您想要或需要的任何内容(构建,测试,打包),然后将其推送到S3 (作为tarball文件,通常);
  • depending on how you have set things, your CI tells Code Deploy to deploy it on your EC2 instances right away, or it just tells it there's a new version available, and lets you to trigger the deploy, manually, via CLI on web console, whenever you want. 根据您设置的方式,您的CI会让Code Deploy立即将其部署到您的EC2实例上,或者只是告诉它有可用的新版本,并允许您通过Web控制台上的CLI手动触发部署,无论你什么时候想要。

(Actually, CodeDeploy doesn't push code to EC2 instances. Instead, each EC2 instance must run an agent which pools regularly CodeDeploy server in order to know if there's something new to be applied locally. Anyway, CodeDeploy coordinates and get feedback from the agents, so it just works as if it were 100% active on CodeDeploy side and 100% passive on the instances side.) (实际上, CodeDeploy不会将代码推送到EC2实例。相反,每个EC2实例必须运行一个代理,该代理定期汇集CodeDeploy服务器,以便知道是否有新的东西在本地应用。无论如何, CodeDeploy协调并从代理获得反馈,所以它就像在CodeDeploy端100%活跃,在实例端100%被动一样。)

The most "clean" AWS solution would be CodeCommit -> CodePipeline -> CodeDeploy , or just CodeCommit -> CodeDeploy , but those services are not completely integrated by now. 最“干净”的AWS解决方案是CodeCommit - > CodePipeline - > CodeDeploy ,或者只是CodeCommit - > CodeDeploy ,但是这些服务现在还没有完全集成。

In your case, the simplest and viable solution right now would be Github -> CodeDeploy . 在您的情况下,现在最简单可行的解决方案是Github - > CodeDeploy Anything different from that will demand some intermediate steps on the way, like the examples I provided ( CodeShip , Jenkins , etc). 任何不同的东西都需要一些中间步骤,比如我提供的例子( CodeShipJenkins等)。

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

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