AWS CodeDeploy
AWS CodeDeploy是AWS提供的服务之一,用于发布服务器端的软件。
简介
安装
在服务器端需要安装Agent,这只Agent会负责取得档案并且执行设定的步骤[1]。
以Ubuntu的环境为例子来说[2],会需要先安装Ruby 2.0(14.04下)或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)。
然后启动Agent:
$ 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上后才能使用。