|
| 1 | +## Description |
| 2 | +Codedeployer is a small library that helps deploying any application or codebase to groups of ec2 instances through AWS Codedeploy. |
| 3 | +The deploy process needs pre-configuration on the AWS side, so ask your nearest ops. |
| 4 | + |
| 5 | +The deployment works like this: |
| 6 | +- an archive is created containing the codebase and a special `appspec.yml` file needed by Codedeploy |
| 7 | +- this archive is uploaded to S3 |
| 8 | +- a series of calls is made to the Codedeploy API to initiate deployments |
| 9 | +- an agent installed on all supported instances polls Codedeploy waiting for deployment instructions |
| 10 | +- when the agent receives a deployment instruction, it downloads the archive from S3 and executes the steps defined in the `appspec.yml` file |
| 11 | + |
| 12 | +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. |
| 13 | + |
| 14 | +## Installation and usage |
| 15 | +1. Run `composer require mriva/codedeployer` |
| 16 | +2. Run `bin/deploy --setup` |
| 17 | +3. Create directories named as deployment groups |
| 18 | +4. Add scripts inside deployment groups directories |
| 19 | +5. Compile `config.php` |
| 20 | +6. Run `bin/deploy` |
| 21 | + |
| 22 | +**Point 1** and **2** are self explanatory. |
| 23 | + |
| 24 | +**Point 3** requires you to create a directory under `deploy/hook-script` for each instance group you want to deploy to. |
| 25 | +For example, if you wish to deploy to `ec2-alfa` and `ec2-beta` instance groups, the tree will look like this: |
| 26 | + |
| 27 | +``` |
| 28 | +deploy/ |
| 29 | +└── hook-scripts/ |
| 30 | + ├── ec2-alfa/ |
| 31 | + └── ec2-beta/ |
| 32 | +``` |
| 33 | + |
| 34 | +**Point 4** requires you to populate the directories from point 3. |
| 35 | +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. |
| 36 | + |
| 37 | +`AfterInstall` is the first hook available and is run after the agent has downloaded and extracted the revision archive to a temporary directory; |
| 38 | +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). |
| 39 | + |
| 40 | +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 |
| 41 | + |
| 42 | +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: |
| 43 | + |
| 44 | +``` |
| 45 | +deploy/ |
| 46 | +└── hook-scripts/ |
| 47 | + ├── ec2-alfa/ |
| 48 | + │ └── AfterInstall.sh |
| 49 | + └── ec2-beta/ |
| 50 | + └── AfterInstall.sh |
| 51 | +
|
| 52 | +``` |
| 53 | + |
| 54 | +these script will be run by the main `hook-wrapper.sh` which is defined as the main hook in `appspec.yml` |
| 55 | + |
| 56 | +There are two example scripts ready to be used with minimal configuration for simple copy and rotating releases deploy in the `config/hook-scripts/example-scripts/` directory. |
| 57 | + |
| 58 | +**Point 5** only requires you to compile a few application related options, the file should be self explanatory as well. |
| 59 | + |
| 60 | +## TODO |
| 61 | +- refactor config.php with some other form of configuration |
| 62 | +- write Codedeploy new activation (app + groups) through CLI skipping web console |
| 63 | +- sanity checks |
0 commit comments