AWS CodeDeploy:修订间差异

来自Gea-Suan Lin's Wiki
跳到导航 跳到搜索
此页面具有访问限制。如果您看见此消息,则说明您没有权限访问此页面。
第12行: 第12行:
 在伺服器端需要安裝Agent,這隻Agent會負責取得檔案並且執行設定的步驟<ref>{{Cite web |url=https://docs.aws.amazon.com/codedeploy/latest/userguide/codedeploy-agent-operations-install.html |title=Install or Reinstall the AWS CodeDeploy Agent - AWS CodeDeploy}}</ref>。
 在伺服器端需要安裝Agent,這隻Agent會負責取得檔案並且執行設定的步驟<ref>{{Cite web |url=https://docs.aws.amazon.com/codedeploy/latest/userguide/codedeploy-agent-operations-install.html |title=Install or Reinstall the AWS CodeDeploy Agent - AWS CodeDeploy}}</ref>。


 以[[Ubuntu]]的環境為例子來說<ref>{{Cite web |url=https://docs.aws.amazon.com/codedeploy/latest/userguide/codedeploy-agent-operations-install-ubuntu.html |title=Install or reinstall the AWS CodeDeploy agent for Ubuntu Server - AWS CodeDeploy}}</ref>,會需要先安裝Ruby 2.0 (14.04下) 或2.3 (16.04下)後,取得安裝設定檔執行:
 以[[Ubuntu]]的環境為例子來說<ref>{{Cite web |url=https://docs.aws.amazon.com/codedeploy/latest/userguide/codedeploy-agent-operations-install-ubuntu.html |title=Install or reinstall the AWS CodeDeploy agent for Ubuntu Server - AWS CodeDeploy}}</ref>,會需要先安裝Ruby 2.0 (在14.04下) 或Ruby 2.3 (在16.04下)後,取得安裝設定檔執行:


<syntaxhighlight lang="shell-session">
<syntaxhighlight lang="shell-session">

2018年5月1日 (二) 19:34的版本

AWS CodeDeployAWS提供的服务之一,用于发布伺服器端的软体。

简介

AWS CodeDeploy是一套伺服器软体布署的服务,跟其他软体布署不同的点主要在于:

  • SSH由外部连入更新,是由伺服器端主动取得档案并且布署。

这点在云端时代特别重要。布署发起人不容易知道现在线上有哪些机器,甚至有可能在开新机器时(如Auto Scaling)有race condition,而导致布署发起人不知道有新机器需要布署。

安装

在伺服器端需要安装Agent,这只Agent会负责取得档案并且执行设定的步骤[1]

Ubuntu的环境为例子来说[2],会需要先安装Ruby 2.0(在14.04下)或Ruby 2.3(在16.04下)后,取得安装设定档执行:

$ sudo apt install ruby2.3
$ cd /tmp
$ wget https://aws-codedeploy-us-east-1.s3.amazonaws.com/latest/install
$ chmod 755 install
$ sudo ./install auto

在非EC2的机器上可能会跑比较久(需要等169.254.169.254的timeout,在EC2上时这个IP会有HTTP服务提供资讯给Instance)。

然后看Agent是否有启动:

$ sudo service codedeploy-agent status

如果没有的话可以用start启动:

$ sudo service codedeploy-agent start

设定

软体本身有两段设定,一段是Deploy的发起端透过awscli呼叫,另外一段是在appspec.yml定义在伺服器上的行为。

发起端

通常会有两个指令:

  • 将现在的目录打包起来传到S3上。可能会使用--ignore-hidden-files避免.git或是.svn被包进去,但这个方式会使得.htaccess不会被包进去,对于使用Apache的使用者来说要注意。
  • 要求CodeDeploy送指令到各机器上抓档案。
$ aws deploy push --application-name "${APPLICATIO_NAME}" --region us-east-1 --s3-location s3://${S3_BUCKET}/${GIT_BRANCH}-${GIT_HASH}
$ aws deploy create-deployment --application-name "${APPLICATION_NAME}" --deployment-group-name "${DEPLOYMENT_GROUP_NAME}" --region us-east-1 --s3-location bucket="${S3_BUCKET},key=${GIT_BRANCH}-${GIT_HASH},bundleType=zip"

伺服器端

appspec.xml内最简单的设定就是指定要将这包档案解到哪边:

version: 0.0
os: linux
files:
  - source: /
    destination: /srv/www.example.com

外部机器

当机器不在EC2上时,需要用register-on-premises-instance将机器注册到CodeDeploy上后才能使用。

参考资料

外部连结