Skip to content

Commit 6d809a4

Browse files
committed
revamp codebuild
1 parent 7a75d4c commit 6d809a4

File tree

1 file changed

+55
-58
lines changed

1 file changed

+55
-58
lines changed

src/content/docs/aws/services/codebuild.md renamed to src/content/docs/aws/services/codebuild.mdx

Lines changed: 55 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
---
22
title: CodeBuild
3-
linkTitle: CodeBuild
4-
description: >
5-
Get started with CodeBuild on LocalStack
3+
description: Get started with CodeBuild on LocalStack
64
tags: ["Base"]
75
---
86

7+
import { FileTree } from '@astrojs/starlight/components';
8+
99
## Introduction
1010

1111
AWS CodeBuild is a fully managed continuous integration service that compiles source code, runs tests, and produces software packages that are ready to deploy.
1212
It is part of the [AWS Developer Tools suite](https://aws.amazon.com/products/developer-tools/) and integrates with other AWS services to provide an end-to-end development pipeline.
1313

1414
LocalStack supports the emulation of most of the CodeBuild operations.
15-
The supported operations are listed on the [API coverage page]({{< ref "coverage_codebuild" >}}).
15+
The supported operations are listed on the [API coverage page]().
1616

1717
AWS CodeBuild emulation is powered by the [AWS CodeBuild agent](https://docs.aws.amazon.com/codebuild/latest/userguide/use-codebuild-agent.html).
1818

@@ -28,17 +28,17 @@ In the first step, we have to create the project that we want to build with AWS
2828

2929
In an empty directory, we need to re-create the following structure:
3030

31-
```bash
32-
root-directory-name
33-
├── pom.xml
34-
└── src
35-
├── main
36-
│   └── java
37-
│   └── MessageUtil.java
38-
└── test
39-
└── java
40-
└── TestMessageUtil.java
41-
```
31+
<FileTree>
32+
- root-directory-name
33+
- pom.xml
34+
- src
35+
- main
36+
- java
37+
- MessageUtil.java
38+
- test
39+
- java
40+
- TestMessageUtil.java
41+
</FileTree>
4242

4343
Let us walk through these files.
4444
`MessageUtil.java` contains the entire logic of this small application.
@@ -175,30 +175,23 @@ Now we have to create two S3 buckets:
175175

176176
Create the buckets with the following commands:
177177

178-
{{< command >}}
179-
$ awslocal s3 mb s3://codebuild-demo-input
180-
<disable-copy>
181-
make_bucket: codebuild-demo-input
182-
</disable-copy>
183-
{{< /command >}}
184-
185-
{{< command >}}
186-
$ awslocal s3 mb s3://codebuild-demo-output
187-
<disable-copy>
188-
make_bucket: codebuild-demo-output
189-
{{< /command >}}
178+
```bash
179+
awslocal s3 mb s3://codebuild-demo-input
180+
awslocal s3 mb s3://codebuild-demo-output
181+
```
190182

191183
Finally, zip the content of the source code directory and upload it to the created source bucket.
192184
With a UNIX system, you can simply use the `zip` utility:
193-
{{< command >}}
194-
$ zip -r MessageUtil.zip <source-directory>
195-
{{< /command >}}
185+
186+
```bash
187+
zip -r MessageUtil.zip <source-directory>
188+
```
196189

197190
Then, upload `MessageUtil.zip` to the `codebuild-demo-input` bucket with the following command:
198191

199-
{{< command >}}
200-
$ awslocal s3 cp MessageUtil.zip s3://codebuild-demo-input
201-
{{< /command >}}
192+
```bash
193+
awslocal s3 cp MessageUtil.zip s3://codebuild-demo-input
194+
```
202195

203196
### Configuring IAM
204197

@@ -221,9 +214,10 @@ Create a `create-role.json` file with following content:
221214
```
222215

223216
Then, run the following command to create the necessary IAM role:
224-
{{< command >}}
225-
$ awslocal iam create-role --role-name CodeBuildServiceRole --assume-role-policy-document file://create-role.json
226-
{{< /command >}}
217+
218+
```bash
219+
awslocal iam create-role --role-name CodeBuildServiceRole --assume-role-policy-document file://create-role.json
220+
```
227221

228222
From the command's response, keep note of the role ARN:
229223
it will be needed to create the CodeBuild project later on.
@@ -285,9 +279,12 @@ Create a `put-role-policy.json` file with the following content:
285279

286280
Finally, assign the policy to the role with the following command:
287281

288-
{{< command >}}
289-
$ awslocal put-role-policy --role-name CodeBuildServiceRole --policy-name CodeBuildServiceRolePolicy --policy-document file://put-role-policy.json
290-
{{< /command >}}
282+
```bash
283+
awslocal put-role-policy \
284+
--role-name CodeBuildServiceRole \
285+
--policy-name CodeBuildServiceRolePolicy \
286+
--policy-document file://put-role-policy.json
287+
```
291288

292289
### Create the build project
293290

@@ -296,9 +293,9 @@ We now need to create a build project, containing all the information about how
296293
You can use the CLI to generate the skeleton of the `CreateBuild` request, which you can later modify.
297294
Save the output of the following command to a file named `create-project.json`.
298295

299-
{{< command >}}
300-
$ awslocal codebuild create-project --generate-cli-skeleton
301-
{{< /command >}}
296+
```bash
297+
awslocal codebuild create-project --generate-cli-skeleton
298+
```
302299

303300
From the generated file, change the source and the artifact location to match the S3 bucket names you just created.
304301
Similarly, fill in the ARN of the CodeBuild service role.
@@ -325,49 +322,49 @@ Similarly, fill in the ARN of the CodeBuild service role.
325322

326323
Now create the project with the following command:
327324

328-
{{< command >}}
329-
$ awslocal codebuild create-project --cli-input-json file://create-project.json
330-
{{< /command >}}
325+
```bash
326+
awslocal codebuild create-project --cli-input-json file://create-project.json
327+
```
331328

332329
You have now created a CodeBuild project called `codebuild-demo-project` that uses the S3 buckets you just created as source and artifact.
333330

334-
{{< callout >}}
331+
:::note
335332
LocalStack does not allow to customize the build environment.
336333
Depending on the host architecture, the build will be executed an Amazon Linux container, version `3.0.x` and `5.0.x`, respectively for the ARM and the x86 architecture.
337-
{{< /callout >}}
334+
:::
338335

339336
### Run the build
340337

341338
In this final step, you can now execute your build with the following command:
342339

343-
{{< command >}}
344-
$ awslocal codebuild start-build --project-name codebuild-demo-project
345-
{{< /command >}}
340+
```bash
341+
awslocal codebuild start-build --project-name codebuild-demo-project
342+
```
346343

347344
Make note of the `id` information given in output, since it can be used to query the status of the build.
348345
If you inspect the running containers (e.g., with the `docker ps -a` command), you will notice a container with the `localstack-codebuild` prefix (followed by the build ID), which CodeBuild started to execute the build.
349346
This container will be responsible to start a Docker compose stack that executes the actual build.
350347

351348
As said, you can inspect the status of the build with the following command:
352349

353-
{{< command >}}
354-
$ awslocal codebuild batch-get-builds --ids <build-id>
355-
{{< /command >}}
350+
```bash
351+
awslocal codebuild batch-get-builds --ids <build-id>
352+
```
356353

357354
The command returns a list of builds.
358355
A build has a `buildStatus` attribute that will be set to `SUCCEEDED` if the build correctly terminates.
359356

360-
{{< callout >}}
357+
:::note
361358
Each build goes through different phases, each of them having a start and end time, as well as a status.
362359
LocalStack does not provided such granular information.
363360
Currently, it reports only the final status of the build.
364-
{{< /callout >}}
361+
:::
365362

366363
Once the build is completed, you can verify that the JAR artifact has been uploaded to the correct S3 bucket with the following command:
367364

368-
{{< command >}}
369-
$ awslocal s3 ls://codebuild-demo-output
370-
{{< /command >}}
365+
```bash
366+
awslocal s3 ls s3://codebuild-demo-output
367+
```
371368

372369
## Limitations
373370

0 commit comments

Comments
 (0)