In this example we are going to use the resources in the sample directory. This example assumes you have access to an Amazon AWS account and have sufficient permissions to create roles and resources.
After setup, you will be able to repeatedly deploy a PHP app to one or more isolated environments on AWS by running the following command:
$ moonshot pushYou will also be able to update the OS and supporting software by pulling the latest changes in this repository and updating the stack with following command:
$ moonshot updateLastly, you get a disposable, light-weight application that can be used to learn and hack on Moonshot without having to muck with applications that actually matter.
Create a role called CodeDeployRole with the AWSCodeDeployRole policy
$ aws iam create-role --role-name CodeDeployRole --assume-role-policy-document '{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"Service": [
"codedeploy.amazonaws.com"
]
},
"Action": "sts:AssumeRole"
}
]
}'
$ aws iam attach-role-policy --role-name CodeDeployRole --policy-arn arn:aws:iam::aws:policy/service-role/AWSCodeDeployRoleIf you wish to do this manually, follow the
Create a Service Role for AWS CodeDeploy
documentation, and make sure to name the role CodeDeployRole as that is
what Moonshot expects.
Moonshot is released as a Ruby gem, and required Ruby 2.1+.
$ gem install moonshotFirst, create your own bucket to put your artifacts in:
$ aws s3api create-bucket --bucket moonshot-sample-your-nameThen update Moonfile.rb to refer to that bucket in the S3Bucket configuration.
Run the following commands to create your environment and deploy code to it.
Note that you will have to set the AWS_REGION environment variable prior to
running these commands. If it's not set, it will use the default AWS region
which at the time of this writing is us-east-1.
A detailed explanation of all the CLI commands can be found in the User Guide
You can now deploy your software to a new stack with:
$ moonshot createBy default, you'll get a development environment named
moonshot-sample-app. If you want to provision test or production
named environment, use:
$ moonshot create -n staging
$ moonshot create -n productionBy default, create launches the stack and deploys code. If you want to only create the stack and not deploy code, use:
$ moonshot create --no-deployIf you make changes to your application and want to release a development build to your stack, run:
$ moonshot pushTo build a "named build" for releasing through test and production environments, use:
$ moonshot build v0.1.0
$ moonshot deploy v0.1.0 -n <environment-name>To see the outputs of the stack you just spun up:
$ moonshot statusTear down your stack by running the following command:
$ moonshot deleteSSH into the first instance in your stack by running the following command:
$ moonshot ssh