soisy/codedeployer 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

soisy/codedeployer

Composer 安装命令:

composer require soisy/codedeployer

包简介

Deploy tool interacting with AWS Codedeploy

README 文档

README

Codedeployer is a small library that helps deploying any application or codebase to groups of ec2 instances through AWS Codedeploy. The deploy process needs pre-configuration on the AWS side, so ask your nearest ops.

The deployment works like this:

  • an archive is created containing the codebase and a special appspec.yml file needed by Codedeploy
  • this archive is uploaded to S3
  • a series of calls is made to the Codedeploy API to initiate deployments
  • an agent installed on all supported instances polls Codedeploy waiting for deployment instructions
  • when the agent receives a deployment instruction, it downloads the archive from S3 and executes the steps defined in the appspec.yml file

This process shifts the deployment from a push system like Idephix or Deployer that requires ssh access to machines in order to rsync the code, to a poll system where the instances are notified of a new deployment request by the agent and download the application archive, running all the configured scripts to complete the deployment.

Components

Things that run on the deployer machine (dev or CI):

  • bin/deploy script: sets up autoload and executes the main PHP script
  • Codedeployer PHP class: executed on the dev or CI machine, sets up the archive, pushes it to S3 and calls Codedeploy APIs to initiate deployments
  • config/config.php: configuration file containing the name of the application and the instance groups target of the deployment, used by the Codedeployer class

Things that run on the target machine (ec2 instance where the code is deployed)

  • config/appspec.yml: configuration file required by AWS Codedeploy, is included in the archive and describes what to do during the deployment on the target machines
  • config/hook-scripts/hook-wrapper.sh: wrapper script called by appspec.yml, is executed on the destination ec2 machines, calls deployments scripts and provides logging; requires the ts tool for timestamping
  • config/hook-scripts/instance-template: template directory containing premade scripts
  • config/hook-scripts/strategies: scripts that execute predefined deploy strategies: rotating releases and simple copy
  • config/hook-scripts/rsync_exclude: list of files and directories excluded from the final copy

Installation and usage

  1. Run composer require soisy/codedeployer
  2. Run ./vendor/bin/deploy --setup
  3. Create directories named as deployment groups
  4. Add scripts inside deployment groups directories
  5. Compile config.php
  6. Run ./vendor/bin/deploy

Point 1 and 2 are self explanatory.

Point 3 requires you to create a directory under deploy/hook-script for each instance group you want to deploy to. You should duplicate the instance-template directory, change its name to the match the deployment group and adjust its content.

For example, if you wish to deploy to ec2-alfa and ec2-beta instance groups, the tree will look like this:

deploy/
└── hook-scripts/
    ├── ec2-alfa/
    └── ec2-beta/

Point 4 requires you to populate the directories from point 3. AWS Codedeploy offers various hooks during the process, for simplicity the default setup only uses AfterInstall but other hooks can be easily added to appspec.yml if needed.

AfterInstall is the first hook available and is run after the agent has downloaded and extracted the revision archive to a temporary directory; it is used to actually copy all the code to the real target directory and execute any post-install script that might be needed (ie. clearing cache, recreating snapshots, etc).

For more information on AWS Codedeploy hooks see: https://docs.aws.amazon.com/codedeploy/latest/userguide/reference-appspec-file-structure-hooks.html#appspec-hooks-server

Now add scripts in those directories named after these hooks, so assuming you go for the easy version with just AfterInstall, your tree should look like this:

deploy/
└── hook-scripts/
    ├── ec2-alfa/
    │   └── AfterInstall.sh
    └── ec2-beta/
        └── AfterInstall.sh

these scripts will be run by the wrapper script hook-wrapper.sh which is defined as the main hook in appspec.yml

Point 5 only requires you to compile a few application related options, the file should be self explanatory.

TODO

  • refactor config.php with some other form of configuration
  • write Codedeploy new activation (app + groups) through CLI skipping web console
  • sanity checks

soisy/codedeployer 适用场景与选型建议

soisy/codedeployer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 55.24k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 08 月 27 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「deploy」 「aws」 「codedeploy」 「soisy」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 soisy/codedeployer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 soisy/codedeployer 我们能提供哪些服务?
定制开发 / 二次开发

基于 soisy/codedeployer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 55.24k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 8
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-08-27