-
Notifications
You must be signed in to change notification settings - Fork 5.8k
/
Copy pathcreate-project.js
108 lines (103 loc) · 3.75 KB
/
create-project.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { fileURLToPath } from "node:url";
// snippet-start:[javascript.v3.codebuild.actions.CreateProject]
import {
ArtifactsType,
CodeBuildClient,
ComputeType,
CreateProjectCommand,
EnvironmentType,
SourceType,
} from "@aws-sdk/client-codebuild";
// Create the AWS CodeBuild project.
export const createProject = async (
projectName = "MyCodeBuilder",
roleArn = "arn:aws:iam::xxxxxxxxxxxx:role/CodeBuildAdmin",
buildOutputBucket = "xxxx",
githubUrl = "https://...",
) => {
const codeBuildClient = new CodeBuildClient({});
const response = await codeBuildClient.send(
new CreateProjectCommand({
artifacts: {
// The destination of the build artifacts.
type: ArtifactsType.S3,
location: buildOutputBucket,
},
// Information about the build environment. The combination of "computeType" and "type" determines the
// requirements for the environment such as CPU, memory, and disk space.
environment: {
// Build environment compute types.
// https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-compute-types.html
computeType: ComputeType.BUILD_GENERAL1_SMALL,
// Docker image identifier.
// See https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-available.html
image: "aws/codebuild/standard:7.0",
// Build environment type.
type: EnvironmentType.LINUX_CONTAINER,
},
name: projectName,
// A role ARN with permission to create a CodeBuild project, write to the artifact location, and write CloudWatch logs.
serviceRole: roleArn,
source: {
// The type of repository that contains the source code to be built.
type: SourceType.GITHUB,
// The location of the repository that contains the source code to be built.
location: githubUrl,
},
}),
);
console.log(response);
// {
// '$metadata': {
// httpStatusCode: 200,
// requestId: 'b428b244-777b-49a6-a48d-5dffedced8e7',
// extendedRequestId: undefined,
// cfId: undefined,
// attempts: 1,
// totalRetryDelay: 0
// },
// project: {
// arn: 'arn:aws:codebuild:us-east-1:xxxxxxxxxxxx:project/MyCodeBuilder',
// artifacts: {
// encryptionDisabled: false,
// location: 'xxxxxx-xxxxxxx-xxxxxx',
// name: 'MyCodeBuilder',
// namespaceType: 'NONE',
// packaging: 'NONE',
// type: 'S3'
// },
// badge: { badgeEnabled: false },
// cache: { type: 'NO_CACHE' },
// created: 2023-08-18T14:46:48.979Z,
// encryptionKey: 'arn:aws:kms:us-east-1:xxxxxxxxxxxx:alias/aws/s3',
// environment: {
// computeType: 'BUILD_GENERAL1_SMALL',
// environmentVariables: [],
// image: 'aws/codebuild/standard:7.0',
// imagePullCredentialsType: 'CODEBUILD',
// privilegedMode: false,
// type: 'LINUX_CONTAINER'
// },
// lastModified: 2023-08-18T14:46:48.979Z,
// name: 'MyCodeBuilder',
// projectVisibility: 'PRIVATE',
// queuedTimeoutInMinutes: 480,
// serviceRole: 'arn:aws:iam::xxxxxxxxxxxx:role/CodeBuildAdmin',
// source: {
// insecureSsl: false,
// location: 'https://...',
// reportBuildStatus: false,
// type: 'GITHUB'
// },
// timeoutInMinutes: 60
// }
// }
return response;
};
// snippet-end:[javascript.v3.codebuild.actions.CreateProject]
// Invoke main function if this file was run directly.
if (process.argv[1] === fileURLToPath(import.meta.url)) {
createProject();
}