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

feat(cloud9): support AWS CodeCommit repository clone on launch #8205

Merged
merged 20 commits into from
Jun 8, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
14 changes: 14 additions & 0 deletions packages/@aws-cdk/aws-cloud9/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,17 @@ const c9env = new cloud9.Ec2Environment(this, 'Cloud9Env3', {
new cdk.CfnOutput(this, 'URL', { value: c9env.ideUrl });
```

Specify `repositories` to clone AWS Codecommit repositories into the environment

```ts
new cloud9.Ec2Environment(stack, 'C9Env', {
vpc,
repositories: [
{
repository: codecommit.Repository.fromRepositoryName(stack, 'Repo', 'foo'),
path: '/foo',
},
],
});

```
30 changes: 29 additions & 1 deletion packages/@aws-cdk/aws-cloud9/lib/environment.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as codecommit from '@aws-cdk/aws-codecommit';
import * as ec2 from '@aws-cdk/aws-ec2';
import * as cdk from '@aws-cdk/core';
import { CfnEnvironmentEC2 } from '../lib/cloud9.generated';
Expand Down Expand Up @@ -61,6 +62,29 @@ export interface Ec2EnvironmentProps {
* @default - no description
*/
readonly description?: string;

/**
* The AWS CodeCommit repository to be cloned
*
* @default - do not clone any repository
*/
readonly repositories?: IRepository[];
}

/**
* The interface of the codecommit repository for Cloud9 environment
*/
export interface IRepository {
/**
* AWS CodeCommit repository
*/
readonly repository: codecommit.IRepository,
Copy link
Contributor

Choose a reason for hiding this comment

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

2 things:

  1. I would probably call this codeCommitRepository (given the type).
  2. Is there any chance Cloud9 will support other types of repositories in the future (GitHub comes to mind)? Because if the answer is 'yes', the current design will not support that. There are ways to 'future proof' it a little bit so that it will support more types if necessary - just gauging the need for that here :).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for bringing it up. It's very likely to support other types of repos in the future. Let me propose a new design and please review again then.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Trying to propose this design. By the time Cloud9 supports other providers such as Github, we should be able to render it accordingly. What do you think?

/**
 * Repository provider
 */
export enum Cloud9RepositoryProvider {
  /**
   * AWS CodeCommit
   */
  AWS_CODECOMMIT
}

/**
 * The interface of the codecommit repository for Cloud9 environment
 */
export interface Cloud9Repository {
  /**
   * Repository provider
   * @default AWS_CODECOMMIT
   */
  readonly provider?: Cloud9RepositoryProvider;

  /**
   * Repository URL
   */
  readonly url: string;

  /**
   * The path within the development environment's default file system location to clone the AWS CodeCommit
   * repository into. For example, `/REPOSITORY_NAME` would clone the repository into the
   * `/home/USER_NAME/environment/REPOSITORY_NAME` directory in the environment.
   */
  readonly clonePath: string;
}

/**
* The path within the development environment's default file system location to clone the AWS CodeCommit
* repository into. For example, `/REPOSITORY_NAME` would clone the repository into the
* `/home/USER_NAME/environment/REPOSITORY_NAME` directory in the environment.
*/
readonly path: string;
}

/**
Expand Down Expand Up @@ -125,7 +149,11 @@ export class Ec2Environment extends cdk.Resource implements IEc2Environment {
name: props.ec2EnvironmentName,
description: props.description,
instanceType: props.instanceType?.toString() ?? ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.MICRO).toString(),
subnetId: this.vpc.selectSubnets(vpcSubnets).subnetIds[0] ,
subnetId: this.vpc.selectSubnets(vpcSubnets).subnetIds[0],
repositories: props.repositories ? props.repositories.map(r => ({
repositoryUrl: r.repository.repositoryCloneUrlHttp,
pathComponent: r.path,
})) : undefined,
});
this.environmentId = c9env.ref;
this.ec2EnvironmentArn = c9env.getAtt('Arn').toString();
Expand Down
4 changes: 3 additions & 1 deletion packages/@aws-cdk/aws-cloud9/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,14 @@
"dependencies": {
"@aws-cdk/core": "0.0.0",
"@aws-cdk/aws-ec2": "0.0.0",
"@aws-cdk/aws-codecommit": "0.0.0",
"constructs": "^3.0.2"
},
"homepage": "https://github.com/aws/aws-cdk",
"peerDependencies": {
"@aws-cdk/core": "0.0.0",
"@aws-cdk/aws-ec2": "0.0.0",
"@aws-cdk/aws-codecommit": "0.0.0",
"constructs": "^3.0.2"
},
"engines": {
Expand All @@ -95,4 +97,4 @@
"awscdkio": {
"announce": false
}
}
}
42 changes: 42 additions & 0 deletions packages/@aws-cdk/aws-cloud9/test/cloud9.environment.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { expect as expectCDK, haveResource } from '@aws-cdk/assert';
import * as codecommit from '@aws-cdk/aws-codecommit';
import * as ec2 from '@aws-cdk/aws-ec2';
import * as cdk from '@aws-cdk/core';
import * as cloud9 from '../lib';
Expand Down Expand Up @@ -66,4 +67,45 @@ test('throw error when subnetSelection not specified and the provided VPC has no
instanceType: ec2.InstanceType.of(ec2.InstanceClass.C5, ec2.InstanceSize.LARGE),
});
}).toThrow(/no subnetSelection specified and no public subnet found in the vpc, please specify subnetSelection/);
});

test('imoprt codecommit repo', () => {
// WHEN
new cloud9.Ec2Environment(stack, 'C9Env', {
vpc,
repositories: [
{
repository: codecommit.Repository.fromRepositoryName(stack, 'Repo', 'foo'),
path: '/foo',
},
],
});
// THEN
expectCDK(stack).to(haveResource('AWS::Cloud9::EnvironmentEC2', {
InstanceType: 't2.micro',
Repositories: [
{
PathComponent: '/foo',
RepositoryUrl: {
'Fn::Join': [
'',
[
'https://git-codecommit.',
{
Ref: 'AWS::Region',
},
'.',
{
Ref: 'AWS::URLSuffix',
},
'/v1/repos/foo',
],
],
},
},
],
SubnetId: {
Ref: 'VPCPublicSubnet1SubnetB4246D30',
},
}));
});
Loading