自动将代码从Git实验室部署到AWS EC2实例 [英] Automate code deploy from Git lab to AWS EC2 instance

查看:325
本文介绍了自动将代码从Git实验室部署到AWS EC2实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在构建一个使用 GitLab 存储库的应用程序。将代码手动部署到 Amazon AWS EC2实例的测试服务器很繁琐,我打算自动化部署过程,以便在我们提交代码时,它应该反映在测试实例中。

We're building an application for which we are using GitLab repository. Manual deployment of code to the test server which is Amazon AWS EC2 instance is tedious, I'm planning to automate deployment process, such that when we commit code, it should reflect in the test instance.

据我所知,我们可以使用 AWS代码部署服务从 GitHub上获取代码。但是 code部署服务不支持GitLab存储库。 是否可以通过GitLab将代码部署过程自动化到AWS Ec2实例。或是否可以使用Shell脚本来实现这一目标?

from my knowledge we can use AWS code-deploy service to fetch the code from GitHub. But code deploy service does not support GitLab repository . Is there a way to automate the code deployment process to AWS Ec2 instance through GitLab. or Is there a shell scripting possibility to achieve this? Kindly educate me.

推荐答案

使用AWS CodeDeploy实现此目的的一种方法是将S3选项与Gitlab-CI结合使用: http://docs.aws.amazon.com/ codepipeline / latest / userguide / getting-started-w.html

One way you could achieve this with AWS CodeDeploy is by using the S3 option in conjunction with Gitlab-CI: http://docs.aws.amazon.com/codepipeline/latest/userguide/getting-started-w.html

根据项目的设置方式,您可能会生成分发Zip (Gradle通过应用程序插件提供了此功能)。如果您的项目不提供这种功能,则可能需要手动生成分发文件。

Depending on how your project is setup, you may have the possibility to generate a distribution Zip (Gradle offers this through the application plugin). You may need to generate your "distribution" file manually if your project does not offer such a capability.

Gitlab不提供直接的S3集成,但是通过 gitlab-ci.yml ,您将能够将其下载到容器中并运行必要的上传命令,以根据AWS指令将生成的zip文件放在S3容器上,以触发部署。

Gitlab does not offer a direct S3 integration, however through the gitlab-ci.yml you would be able to download it into the container and run the necessary upload commands to put the generated zip file on the S3 container as per the AWS instructions to trigger the deployment.

以下是 brefore脚本 gitlab中的外观示例-ci.yml 文件:

before_script:
  - apt-get update --quiet --yes
  - apt-get --quiet install --yes python
  - pip install -U pip
  - pip install awscli

有关如何在S3上使用CodeDeploy的AWS教程非常详细,因此我将跳过此处的内容重现尝试。

The AWS tutorial on how to use CodeDeploy with S3 is very detailed, so I will skip attempting to reproduce the contents here.

关于您当前正在手动执行的实际部署命令和操作,AWS CodeDeploy提供了通过app-spec文件中定义的脚本来运行某些操作的功能,具体取决于应用程序的事件挂钩:

In regards to the actual deployment commands and actions that you are currently performing manually, AWS CodeDeploy provides the capability to run certain actions through scripts defined in the app-spec file depending on event hooks for the application:

  • http://docs.aws.amazon.com/codedeploy/latest/userguide/writing-app-spec.html
  • http://docs.aws.amazon.com/codedeploy/latest/userguide/app-spec-ref.html
  • http://docs.aws.amazon.com/codedeploy/latest/userguide/app-spec-ref-hooks.html

我希望这会有所帮助。

这篇关于自动将代码从Git实验室部署到AWS EC2实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆