Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add generate-pipelines command #277

Merged
merged 3 commits into from
Apr 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ for more detailed information about upgrading to this release.
(`#272 <https://github.com/awslabs/chalice/pull/272>`__)
* Add support for setting environment variables in your app
(`#273 <https://github.com/awslabs/chalice/pull/273>`__)
* Add a ``generate-pipeline`` command
(`#278 <https://github.com/awslabs/chalice/pull/278>`__)


0.6.0
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ check:
# Proper docstring conventions according to pep257
#
#
pydocstyle --add-ignore=D100,D101,D102,D103,D104,D105,D204 chalice/
pydocstyle --add-ignore=D100,D101,D102,D103,D104,D105,D204,D301 chalice/
#
#
#
Expand Down
28 changes: 28 additions & 0 deletions chalice/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,34 @@ def package(ctx, single_file, stage, out):
packager.package_app(config, out)


@cli.command('generate-pipeline')
@click.argument('filename')
@click.pass_context
def generate_pipeline(ctx, filename):
# type: (click.Context, str) -> None
"""Generate a cloudformation template for a starter CD pipeline.

This command will write a starter cloudformation template to
the filename you provide. It contains a CodeCommit repo,
a CodeBuild stage for packaging your chalice app, and a
CodePipeline stage to deploy your application using cloudformation.

You can use any AWS SDK or the AWS CLI to deploy this stack.
Here's an example using the AWS CLI:

\b
$ chalice generate-pipeline pipeline.json
$ aws cloudformation deploy --stack-name mystack \b
--template-file pipeline.json --capabilities CAPABILITY_IAM
"""
from chalice.pipeline import create_pipeline_template
factory = ctx.obj['factory'] # type: CLIFactory
config = factory.create_config_obj()
output = create_pipeline_template(config)
with open(filename, 'w') as f:
f.write(json.dumps(output, indent=2, separators=(',', ': ')))


def run_local_server(app_obj, port):
# type: (Chalice, int) -> None
from chalice.local import create_local_server
Expand Down
139 changes: 139 additions & 0 deletions chalice/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,142 @@ def index():
],
"Resource": "arn:aws:logs:*:*:*"
}


CODEBUILD_POLICY = {
"Version": "2012-10-17",
# This is the policy straight from the console.
"Statement": [
{
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "*",
"Effect": "Allow"
},
{
"Action": [
"s3:GetObject",
"s3:GetObjectVersion",
"s3:PutObject"
],
"Resource": "arn:aws:s3:::*",
"Effect": "Allow"
}
]
}

CODEPIPELINE_POLICY = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So is this the minimal amount of permissions needed to get codepipeline working? Seems a little weird that there is a good amount of services included in it that don't really need to be like beanstalk and opsworks

Copy link
Member Author

@jamesls jamesls Apr 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's from the console setup, yeah.

EDIT: I can also take a pass at paring these down. I'm a little hesitant to change the defaults from the console, but it should be possible.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. I am fine keeping it as it. It just pointed it out as it looked weird given you really only used half of those services and normally for IAM policies you keep it as minimal as possible.

"Version": "2012-10-17",
# Also straight from the console setup.
"Statement": [
{
"Action": [
"s3:GetObject",
"s3:GetObjectVersion",
"s3:GetBucketVersioning"
],
"Resource": "*",
"Effect": "Allow"
},
{
"Action": [
"s3:PutObject"
],
"Resource": [
"arn:aws:s3:::codepipeline*",
"arn:aws:s3:::elasticbeanstalk*"
],
"Effect": "Allow"
},
{
"Action": [
"codecommit:CancelUploadArchive",
"codecommit:GetBranch",
"codecommit:GetCommit",
"codecommit:GetUploadArchiveStatus",
"codecommit:UploadArchive"
],
"Resource": "*",
"Effect": "Allow"
},
{
"Action": [
"codedeploy:CreateDeployment",
"codedeploy:GetApplicationRevision",
"codedeploy:GetDeployment",
"codedeploy:GetDeploymentConfig",
"codedeploy:RegisterApplicationRevision"
],
"Resource": "*",
"Effect": "Allow"
},
{
"Action": [
"elasticbeanstalk:*",
"ec2:*",
"elasticloadbalancing:*",
"autoscaling:*",
"cloudwatch:*",
"s3:*",
"sns:*",
"cloudformation:*",
"rds:*",
"sqs:*",
"ecs:*",
"iam:PassRole"
],
"Resource": "*",
"Effect": "Allow"
},
{
"Action": [
"lambda:InvokeFunction",
"lambda:ListFunctions"
],
"Resource": "*",
"Effect": "Allow"
},
{
"Action": [
"opsworks:CreateDeployment",
"opsworks:DescribeApps",
"opsworks:DescribeCommands",
"opsworks:DescribeDeployments",
"opsworks:DescribeInstances",
"opsworks:DescribeStacks",
"opsworks:UpdateApp",
"opsworks:UpdateStack"
],
"Resource": "*",
"Effect": "Allow"
},
{
"Action": [
"cloudformation:CreateStack",
"cloudformation:DeleteStack",
"cloudformation:DescribeStacks",
"cloudformation:UpdateStack",
"cloudformation:CreateChangeSet",
"cloudformation:DeleteChangeSet",
"cloudformation:DescribeChangeSet",
"cloudformation:ExecuteChangeSet",
"cloudformation:SetStackPolicy",
"cloudformation:ValidateTemplate",
"iam:PassRole"
],
"Resource": "*",
"Effect": "Allow"
},
{
"Action": [
"codebuild:BatchGetBuilds",
"codebuild:StartBuild"
],
"Resource": "*",
"Effect": "Allow"
}
]
}
Loading