diff --git a/java/codebuild/project/README.md b/java/codebuild/project/README.md new file mode 100644 index 000000000..e21744439 --- /dev/null +++ b/java/codebuild/project/README.md @@ -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! diff --git a/java/codebuild/project/cdk.json b/java/codebuild/project/cdk.json new file mode 100644 index 000000000..8d02402c6 --- /dev/null +++ b/java/codebuild/project/cdk.json @@ -0,0 +1,3 @@ +{ + "app": "mvn -e -q exec:java" +} diff --git a/java/codebuild/project/pom.xml b/java/codebuild/project/pom.xml new file mode 100644 index 000000000..142779cd9 --- /dev/null +++ b/java/codebuild/project/pom.xml @@ -0,0 +1,59 @@ + + + 4.0.0 + + com.myorg + project + 0.1 + + + UTF-8 + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 1.8 + 1.8 + + + + + org.codehaus.mojo + exec-maven-plugin + 1.6.0 + + com.myorg.ProjectApp + + + + + + + + + software.amazon.awscdk + core + [1.21.0, 2) + + + + software.amazon.awscdk + codebuild + [1.21.0, 2) + + + + + junit + junit + 4.12 + test + + + diff --git a/java/codebuild/project/src/main/java/com/myorg/ProjectApp.java b/java/codebuild/project/src/main/java/com/myorg/ProjectApp.java new file mode 100644 index 000000000..ab657cb5f --- /dev/null +++ b/java/codebuild/project/src/main/java/com/myorg/ProjectApp.java @@ -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(); + } +} diff --git a/java/codebuild/project/src/main/java/com/myorg/ProjectStack.java b/java/codebuild/project/src/main/java/com/myorg/ProjectStack.java new file mode 100644 index 000000000..2a4395542 --- /dev/null +++ b/java/codebuild/project/src/main/java/com/myorg/ProjectStack.java @@ -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 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(); + + } +} diff --git a/java/codebuild/reportgroup/README.md b/java/codebuild/reportgroup/README.md new file mode 100644 index 000000000..6f4c2d8f6 --- /dev/null +++ b/java/codebuild/reportgroup/README.md @@ -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! diff --git a/java/codebuild/reportgroup/cdk.json b/java/codebuild/reportgroup/cdk.json new file mode 100644 index 000000000..8d02402c6 --- /dev/null +++ b/java/codebuild/reportgroup/cdk.json @@ -0,0 +1,3 @@ +{ + "app": "mvn -e -q exec:java" +} diff --git a/java/codebuild/reportgroup/pom.xml b/java/codebuild/reportgroup/pom.xml new file mode 100644 index 000000000..bb27a9281 --- /dev/null +++ b/java/codebuild/reportgroup/pom.xml @@ -0,0 +1,59 @@ + + + 4.0.0 + + com.myorg + reportgroup + 0.1 + + + UTF-8 + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 1.8 + 1.8 + + + + + org.codehaus.mojo + exec-maven-plugin + 1.6.0 + + com.myorg.ReportgroupApp + + + + + + + + + software.amazon.awscdk + core + [1.21.0, 2) + + + + software.amazon.awscdk + codebuild + [1.21.0, 2) + + + + + junit + junit + 4.12 + test + + + diff --git a/java/codebuild/reportgroup/src/main/java/com/myorg/ReportgroupApp.java b/java/codebuild/reportgroup/src/main/java/com/myorg/ReportgroupApp.java new file mode 100644 index 000000000..669a1c179 --- /dev/null +++ b/java/codebuild/reportgroup/src/main/java/com/myorg/ReportgroupApp.java @@ -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(); + } +} diff --git a/java/codebuild/reportgroup/src/main/java/com/myorg/ReportgroupStack.java b/java/codebuild/reportgroup/src/main/java/com/myorg/ReportgroupStack.java new file mode 100644 index 000000000..4f012191c --- /dev/null +++ b/java/codebuild/reportgroup/src/main/java/com/myorg/ReportgroupStack.java @@ -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); + } +} diff --git a/java/codebuild/sourceCredential/README.md b/java/codebuild/sourceCredential/README.md new file mode 100644 index 000000000..ec0a3b3a2 --- /dev/null +++ b/java/codebuild/sourceCredential/README.md @@ -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! diff --git a/java/codebuild/sourceCredential/cdk.json b/java/codebuild/sourceCredential/cdk.json new file mode 100644 index 000000000..8d02402c6 --- /dev/null +++ b/java/codebuild/sourceCredential/cdk.json @@ -0,0 +1,3 @@ +{ + "app": "mvn -e -q exec:java" +} diff --git a/java/codebuild/sourceCredential/pom.xml b/java/codebuild/sourceCredential/pom.xml new file mode 100644 index 000000000..ac46b4ee5 --- /dev/null +++ b/java/codebuild/sourceCredential/pom.xml @@ -0,0 +1,59 @@ + + + 4.0.0 + + com.myorg + source_credential + 0.1 + + + UTF-8 + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 1.8 + 1.8 + + + + + org.codehaus.mojo + exec-maven-plugin + 1.6.0 + + com.myorg.SourceCredentialApp + + + + + + + + + software.amazon.awscdk + core + [1.21.0, 2) + + + + software.amazon.awscdk + codebuild + [1.21.0, 2) + + + + + junit + junit + 4.12 + test + + + diff --git a/java/codebuild/sourceCredential/src/main/java/com/myorg/SourceCredentialApp.java b/java/codebuild/sourceCredential/src/main/java/com/myorg/SourceCredentialApp.java new file mode 100644 index 000000000..3f478b2a3 --- /dev/null +++ b/java/codebuild/sourceCredential/src/main/java/com/myorg/SourceCredentialApp.java @@ -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 SourceCredentialApp { + public static void main(final String[] args) { + App app = new App(); + + new SourceCredentialStack(app, "SourceCredentialStack", StackProps.builder().env( + Environment.builder() + .account("SourceCredentialStack") + .region("us-west-2") + .build()).build()); + + app.synth(); + } +} diff --git a/java/codebuild/sourceCredential/src/main/java/com/myorg/SourceCredentialStack.java b/java/codebuild/sourceCredential/src/main/java/com/myorg/SourceCredentialStack.java new file mode 100644 index 000000000..b09670eb8 --- /dev/null +++ b/java/codebuild/sourceCredential/src/main/java/com/myorg/SourceCredentialStack.java @@ -0,0 +1,26 @@ +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.CfnSourceCredential; +import software.amazon.awscdk.services.codebuild.CfnSourceCredentialProps; + +public class SourceCredentialStack extends Stack { + public SourceCredentialStack(final Construct scope, final String id) { + this(scope, id, null); + } + + public SourceCredentialStack(final Construct scope, final String id, final StackProps props) { + super(scope, id, props); + + CfnSourceCredentialProps sourceCredentialProps = CfnSourceCredentialProps.builder() + .authType("BASIC_AUTH") + .serverType("BITBUCKET") + .token("app_password") + .username("app_username") + .build(); + + new CfnSourceCredential(this, id, sourceCredentialProps); + } +}