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: Add codebuild cdk examples to create Project, ReportGroup and S… #235

Merged
merged 5 commits into from
Jan 30, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
18 changes: 18 additions & 0 deletions java/codebuild/project/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Welcome to your CDK Java project!

It is a Maven-based project, so you can open this directory with any Maven-compatible Java IDE, and you should be able to build and run tests from your IDE.

You should explore the contents of this template. It demonstrates a CDK app to create a codebuild Project.

The cdk.json file tells the CDK Toolkit how to execute your app. This example relies on maven to do that.

## Useful commands

* `mvn package` compile and run tests
* `cdk ls` list all stacks in the app
* `cdk synth` emits the synthesized CloudFormation template
* `cdk deploy` deploy this stack to your default AWS account/region
* `cdk diff` compare deployed stack with current state
* `cdk docs` open CDK documentation

Enjoy!
3 changes: 3 additions & 0 deletions java/codebuild/project/cdk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"app": "mvn -e -q exec:java"
}
59 changes: 59 additions & 0 deletions java/codebuild/project/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>

<groupId>com.myorg</groupId>
<artifactId>project</artifactId>
<version>0.1</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<configuration>
<mainClass>com.myorg.ProjectApp</mainClass>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<!-- AWS Cloud Development Kit -->
<dependency>
<groupId>software.amazon.awscdk</groupId>
<artifactId>core</artifactId>
<version>[1.21.0, 2)</version>
</dependency>

<dependency>
<groupId>software.amazon.awscdk</groupId>
<artifactId>codebuild</artifactId>
<version>[1.21.0, 2)</version>
</dependency>

<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
21 changes: 21 additions & 0 deletions java/codebuild/project/src/main/java/com/myorg/ProjectApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.myorg;

import software.amazon.awscdk.core.App;
import software.amazon.awscdk.core.Environment;
import software.amazon.awscdk.core.StackProps;

import java.util.Arrays;

public class ProjectApp {
public static void main(final String[] args) {
App app = new App();

new ProjectStack(app, "ProjectStack", StackProps.builder().env(
Environment.builder()
.account("projectStack")
.region("us-west-2")
.build()).build());

app.synth();
}
}
70 changes: 70 additions & 0 deletions java/codebuild/project/src/main/java/com/myorg/ProjectStack.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.myorg;

import software.amazon.awscdk.core.Construct;
import software.amazon.awscdk.core.Duration;
import software.amazon.awscdk.core.Stack;
import software.amazon.awscdk.core.StackProps;
import software.amazon.awscdk.services.codebuild.Artifacts;
import software.amazon.awscdk.services.codebuild.ArtifactsProps;
import software.amazon.awscdk.services.codebuild.BuildEnvironment;
import software.amazon.awscdk.services.codebuild.BuildEnvironmentVariable;
import software.amazon.awscdk.services.codebuild.BuildEnvironmentVariableType;
import software.amazon.awscdk.services.codebuild.ComputeType;
import software.amazon.awscdk.services.codebuild.ISource;
import software.amazon.awscdk.services.codebuild.LinuxBuildImage;
import software.amazon.awscdk.services.codebuild.Project;
import software.amazon.awscdk.services.codebuild.S3SourceProps;
import software.amazon.awscdk.services.codebuild.Source;
import software.amazon.awscdk.services.iam.IRole;
import software.amazon.awscdk.services.iam.Role;
import software.amazon.awscdk.services.s3.Bucket;

import software.amazon.awscdk.services.s3.IBucket;

import java.util.HashMap;
import java.util.Map;

public class ProjectStack extends Stack {

public ProjectStack(final Construct scope, final String id) {
this(scope, id, null);
}

public ProjectStack(final Construct scope, final String id, final StackProps props) {
super(scope, id, props);

BuildEnvironmentVariable buildEnvironmentVariable = new BuildEnvironmentVariable.Builder()
.type(BuildEnvironmentVariableType.PLAINTEXT)
.value("varValue")
.build();
Map<String, BuildEnvironmentVariable> environmentVariableMap = new HashMap<>();
environmentVariableMap.put("varName", buildEnvironmentVariable);
BuildEnvironment environment = BuildEnvironment.builder()
.buildImage(LinuxBuildImage.AMAZON_LINUX_2_2)
.computeType(ComputeType.SMALL)
.environmentVariables(environmentVariableMap).build();

Artifacts artifacts = new Artifacts(ArtifactsProps.builder().build()) {
@Override
public String getType() {
return "NO_ARTIFACTS";
}
};

IBucket s3Bucket = Bucket.fromBucketName(this, id, "s3BucketName");
ISource source = Source.s3(S3SourceProps.builder().bucket(s3Bucket).path("S3Path").build());

IRole role = Role.fromRoleArn(this, "someId", "arn:partition:service:region:account-id:resource-type:resource-id");

Project.Builder.create(this, "SampleProject")
.projectName("SampleProject")
.description("Sample Project using AWS CDK")
.role(role)
.artifacts(artifacts)
.environment(environment)
.source(source)
.timeout(Duration.minutes(10))
.build();

}
}
18 changes: 18 additions & 0 deletions java/codebuild/reportgroup/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Welcome to your CDK Java project!

It is a Maven-based project, so you can open this directory with any Maven-compatible Java IDE, and you should be able to build and run tests from your IDE.

You should explore the contents of this template. It demonstrates a CDK app to create a codebuild ReportGroup cloud formation resource.

The cdk.json file tells the CDK Toolkit how to execute your app. This example relies on maven to do that.

## Useful commands

* `mvn package` compile and run tests
* `cdk ls` list all stacks in the app
* `cdk synth` emits the synthesized CloudFormation template
* `cdk deploy` deploy this stack to your default AWS account/region
* `cdk diff` compare deployed stack with current state
* `cdk docs` open CDK documentation

Enjoy!
3 changes: 3 additions & 0 deletions java/codebuild/reportgroup/cdk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"app": "mvn -e -q exec:java"
}
59 changes: 59 additions & 0 deletions java/codebuild/reportgroup/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>

<groupId>com.myorg</groupId>
<artifactId>reportgroup</artifactId>
<version>0.1</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<configuration>
<mainClass>com.myorg.ReportgroupApp</mainClass>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<!-- AWS Cloud Development Kit -->
<dependency>
<groupId>software.amazon.awscdk</groupId>
<artifactId>core</artifactId>
<version>[1.21.0, 2)</version>
</dependency>

<dependency>
<groupId>software.amazon.awscdk</groupId>
<artifactId>codebuild</artifactId>
<version>[1.21.0, 2)</version>
</dependency>

<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.myorg;

import software.amazon.awscdk.core.App;
import software.amazon.awscdk.core.Environment;
import software.amazon.awscdk.core.StackProps;

import java.util.Arrays;

public class ReportgroupApp {
public static void main(final String[] args) {
App app = new App();

new ReportgroupStack(app, "ReportgroupStack", StackProps.builder().env(
Environment.builder()
.account("ReportgroupStack")
.region("us-west-2")
.build()).build());

app.synth();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.myorg;

import software.amazon.awscdk.core.Construct;
import software.amazon.awscdk.core.Stack;
import software.amazon.awscdk.core.StackProps;
import software.amazon.awscdk.services.codebuild.CfnReportGroup;
import software.amazon.awscdk.services.codebuild.CfnReportGroupProps;

public class ReportgroupStack extends Stack {
public ReportgroupStack(final Construct scope, final String id) {
this(scope, id, null);
}

public ReportgroupStack(final Construct scope, final String id, final StackProps props) {
super(scope, id, props);

CfnReportGroup.S3ReportExportConfigProperty s3ReportExportConfigProperty
= CfnReportGroup.S3ReportExportConfigProperty.builder()
.bucket("S3BucketName")
.path("S3Path")
.encryptionDisabled(true)
.packaging("ZIP")
.build();

CfnReportGroup.ReportExportConfigProperty exportConfigProperty
= CfnReportGroup.ReportExportConfigProperty.builder()
.exportConfigType("S3")
.s3Destination(s3ReportExportConfigProperty)
.build();

CfnReportGroupProps reportGroupProps = CfnReportGroupProps.builder()
.exportConfig(exportConfigProperty)
.name("ReportGroupName")
.type("TEST")
.build();

new CfnReportGroup(this, id, reportGroupProps);
}
}
18 changes: 18 additions & 0 deletions java/codebuild/sourceCredential/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Welcome to your CDK Java project!

It is a Maven-based project, so you can open this directory with any Maven-compatible Java IDE, and you should be able to build and run tests from your IDE.

You should explore the contents of this template. It demonstrates a CDK app to create a codebuild source credential cloud formation resource.

The cdk.json file tells the CDK Toolkit how to execute your app. This example relies on maven to do that.

## Useful commands

* `mvn package` compile and run tests
* `cdk ls` list all stacks in the app
* `cdk synth` emits the synthesized CloudFormation template
* `cdk deploy` deploy this stack to your default AWS account/region
* `cdk diff` compare deployed stack with current state
* `cdk docs` open CDK documentation

Enjoy!
3 changes: 3 additions & 0 deletions java/codebuild/sourceCredential/cdk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"app": "mvn -e -q exec:java"
}
Loading