forked from aws-samples/aws-cdk-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add codebuild cdk examples to create Project, ReportGroup… (aws…
…-samples#235) * feat: Add codebuild cdk examples to create Project, ReportGroup and SourceCredentials This commit adds three CDK sample examples for the aws codebuild in java. It will help customers use the sample for better understanding of using CDK for codebuild.
- Loading branch information
Showing
15 changed files
with
446 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# 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. | ||
A codebuild project includes information about how to run a build, including where to get the source code, which build environment to use, which build commands to run, and where to store the build output. In short, build project provides information to Code Build about how to build, as project contains all the information. | ||
To get more details on the properties and methods of a Project object, do look at https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-codebuild.Project.html | ||
|
||
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! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"app": "mvn -e -q exec:java" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
21
java/codebuild/project/src/main/java/com/myorg/ProjectApp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
70
java/codebuild/project/src/main/java/com/myorg/ProjectStack.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# 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. | ||
A report group contains test reports and specifies shared settings. For each report group configured in a build project, a run of the build project creates a test report. Multiple runs of a build project configured with a report group create multiple test reports in that report group, each with results of the same test cases specified for that report group. | ||
The test cases are specified for a report group in the buildspec file of a build project. You can specify up to 5 report groups in one build project. | ||
To get more details on the properties and methods of a refor group, do look at https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-codebuild.CfnReportGroup.html | ||
|
||
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! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"app": "mvn -e -q exec:java" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
21 changes: 21 additions & 0 deletions
21
java/codebuild/reportgroup/src/main/java/com/myorg/ReportgroupApp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
java/codebuild/reportgroup/src/main/java/com/myorg/ReportgroupStack.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# 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. | ||
Source Credentials includes information about the credentials for a GitHub, GitHub Enterprise, or Bitbucket repository. For Bitbucket, you use app password. FOr Github and Github enterprise, you use personal_access_token. This example is shows the Bitbucket credentials. | ||
We strongly recommend that you use AWS Secrets Manager to store your credentials or the NoEcho parameter to mask your credentials. | ||
To get more details on the properties and methods of a source credential, do look at https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-codebuild.CfnSourceCredential.html | ||
|
||
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! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"app": "mvn -e -q exec:java" | ||
} |
Oops, something went wrong.