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

查看:18
本文介绍了将代码从 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 code-deploy 服务从 GitHub 获取代码. 但是 code deploy 服务不支持 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 您可以将其下载到容器中并运行必要的上传命令以将生成的 zip 文件放在根据 AWS 说明触发部署的 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-scriptgitlab-ci.yml 文件中的示例:

Here is an example of what your brefore-script could look like in the gitlab-ci.yml file:

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

关于如何将 CodeDeploy 与 S3 结合使用的 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 提供了通过应用程序规范文件中定义的脚本运行某些操作的能力,具体取决于应用程序的事件挂钩:

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:

我希望这会有所帮助.

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

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