|
1 | 1 | # aws4embeddedlinux-ci-examples
|
2 | 2 |
|
3 |
| -## Getting Started |
4 | 3 | This repository shows ways to use the [aws4embeddedlinux-ci](https://github.com/aws4embeddedlinux/aws4embeddedlinux-ci.git) library.
|
5 | 4 |
|
6 | 5 | In order to use these examples, you must set up the [CDK](https://docs.aws.amazon.com/cdk/v2/guide/getting_started.html), including
|
7 | 6 | installing the CDK tool and bootstrapping the account you wish to deploy to. Additionally, you must have [Node](https://nodejs.org/en/) installed.
|
8 | 7 |
|
9 | 8 | > [!NOTE]
|
10 |
| -> This library is tested against Node Version 22. If these version are not available for your system, we recommend |
11 |
| -> using [NVM](https://github.com/nvm-sh/nvm) to install a compatible version. |
| 9 | +> This library is tested against Node Versions 22. If these version is not available for your system, we recommend using [NVM](https://github.com/nvm-sh/nvm) to install a compatible version. |
12 | 10 |
|
13 |
| -### Clone and Setup NPM Project |
14 |
| -```bash |
15 |
| -git clone https://github.com/aws4embeddedlinux/aws4embeddedlinux-ci-examples.git |
16 |
| -cd aws4embeddedlinux-ci-examples |
17 |
| -npm install . |
18 |
| -npm run build |
19 |
| -``` |
20 |
| - |
21 |
| -Note that while the CDK projects often do not require that you invoke the build command separately, doing so will ensure various assets |
22 |
| -in the library are packaged correctly. |
| 11 | +--- |
23 | 12 |
|
24 |
| -### Deploying |
| 13 | +## Setup |
25 | 14 |
|
26 |
| -To deploy _all_ the pipeline examples, you can use the CDK deploy command: |
| 15 | +### Setting environment variables |
27 | 16 |
|
28 | 17 | ```bash
|
29 |
| -cdk deploy --all |
30 |
| -``` |
| 18 | +export AWS_PROFILE="default" |
| 19 | +export AWS_DEFAULT_REGION=$(aws configure get region --profile ${AWS_PROFILE}) |
| 20 | +export AWS_DEFAULT_ACCOUNT=$(aws sts get-caller-identity --query Account --output text --profile ${AWS_PROFILE}) |
31 | 21 |
|
32 |
| -Alternatively, to deploy just a specific pipeline example, you can use the CDK deploy command: |
| 22 | +echo "PROFILE : $AWS_PROFILE" |
| 23 | +echo "ACCOUNT : $AWS_DEFAULT_ACCOUNT" |
| 24 | +echo "REGION : $AWS_DEFAULT_REGION" |
| 25 | +``` |
33 | 26 |
|
34 |
| -\<EXAMPLE\> can be one or more of: PokyPipeline, QemuEmbeddedLinuxPipeline, PokyAmiPipeline, KasPipeline, RenesasPipeline, NxpImxPipeline |
| 27 | +### Clone the project |
35 | 28 |
|
36 | 29 | ```bash
|
37 |
| -cdk deploy <EXAMPLE> |
| 30 | +git clone https://github.com/aws4embeddedlinux/aws4embeddedlinux-ci-examples.git |
| 31 | +cd aws4embeddedlinux-ci-examples |
38 | 32 | ```
|
39 | 33 |
|
40 |
| -The pipelines can be found in the `Developer Tools > Code Pipeline > Pipelines` Console page. The newly created |
41 |
| -pipeline `ubuntu_22_04BuildImagePipeline` should start automatically. If not, it will need to be run before other |
42 |
| -pipelines will work correctly. Once it is complete, the EmbeddedLinuxPipeline in the CodePipeline console page is ready to run. |
| 34 | +### Bootstrap CDK |
43 | 35 |
|
44 |
| -### Removing Pipelines |
45 |
| -The `cdk destroy` command can be used to remove individual pipelines and their related resources. This can also be done in the CloudFormation Console Page. |
46 |
| -**Do not delete stacks while a CodePipeline is running, this can lead to unexpected failures!** |
| 36 | +> [!NOTE] |
| 37 | +> Only required once unless you upgrade your cdk version |
47 | 38 |
|
48 |
| -To remove all the resources associated with this application: |
49 | 39 | ```bash
|
50 |
| -cdk destroy --all |
| 40 | +cdk bootstrap aws://$AWS_DEFAULT_ACCOUNT/$AWS_DEFAULT_REGION |
51 | 41 | ```
|
52 | 42 |
|
53 |
| -## Examples |
54 |
| -Several example pipelines are provided. Each one demonstrates a different aspect of how to build a Yocto image with AWS. |
55 |
| - |
56 |
| -### A Simple Poky Based Pipeline |
57 |
| -This example will build the `core-image-minimal` image from Poky using the repo tool to manage layers. CVE checking is also enabled in the buildspec file. |
58 |
| - |
59 |
| -The recommended place to view this is from the `Developer Tools > Code Pipeline > Pipelines` page. The pipeline will start with `PokyPipeline-` |
60 |
| -followed by some unique identifier. From the pipeline page, you can find the CodeCommit source repository, the CodeBuild Project (with build logs), |
61 |
| -and the S3 bucket that the image is uploaded to, at the end. |
62 |
| - |
63 |
| -Example stack name: PokyPipeline |
64 |
| - |
65 |
| -Expected build time: 32min / rebuild (without any change, just use sstate cache): 8min |
66 |
| - |
67 |
| -#### Using Kas |
68 |
| -The Kas example shows how to use a [Kas Config](https://github.com/aws4embeddedlinux/aws4embeddedlinux-ci/blob/main/source-repo/kas/kas.yml) to manage |
69 |
| -layers. This tool can help programatically manage layers and config with tighter Yocto integration than Git Submodules or the Repo tool. |
70 |
| - |
71 |
| -See the AWS CodeBuild pipeline: KasPipeline-EmbeddedLinuxPipeline* |
72 |
| - |
73 |
| -Example stack name: KasPipeline |
74 |
| - |
75 |
| -Expected build time: 36min / rebuild (without any change, just use sstate cache): 11min |
76 |
| - |
77 |
| -#### A slightly modified version building a qemu pipeline: |
78 |
| -This example builds a Qemu based image using [meta-aws-demos](https://github.com/aws4embeddedlinux/meta-aws-demos). The Qemu image can be run in |
79 |
| -the CodeBuild environment. Using SLIRP networking, [OEQA testing](https://docs.yoctoproject.org/singleindex.html#performing-automated-runtime-testing) |
80 |
| -such as ptest can be run in the pipeline. |
81 |
| - |
82 |
| -See the AWS CodeBuild pipeline: QemuEmbeddedLinuxPipeline-EmbeddedLinuxPipeline* |
| 43 | +### Install packages and build the stack |
83 | 44 |
|
84 |
| -Expected build time: 45min / rebuild (without any change, just use sstate cache): 14min |
85 |
| - |
86 |
| -### A Poky Based EC2 AMI Pipeline |
87 |
| -Yocto can be used to create an EC2 AMI. This example builds an AMI based on Poky and meta-aws and exports it to your AMI registry using |
88 |
| -the [VM Import/Export Service](https://docs.aws.amazon.com/vm-import/latest/userguide/what-is-vmimport.html). |
89 |
| - |
90 |
| -The pipeline name starts with `PokyAmiPipeline-` in the CodePipeline page. |
| 45 | +First move to the `cdk` folder: |
| 46 | + |
| 47 | +```bash |
| 48 | +cd cdk |
| 49 | +``` |
91 | 50 |
|
92 |
| -Example stack name: PokyAmiPipeline |
| 51 | +Then you will need to install the CDK library including the `aws4embeddedlinux-ci` library either using `npm`: |
93 | 52 |
|
94 |
| -Expected build time: 52min / rebuild (without any change, just use sstate cache): 17min |
| 53 | +```bash |
| 54 | +npm install |
| 55 | +npm run build |
| 56 | +``` |
95 | 57 |
|
96 |
| -### A NXP / IMX Pipeline |
97 |
| -This example will build an image for |
98 |
| -the [i.MX 6ULL EVK](https://www.nxp.com/design/development-boards/i-mx-evaluation-and-development-boards/evaluation-kit-for-the-i-mx-6ull-and-6ulz-applications-processor:MCIMX6ULL-EVK) board. |
| 58 | +of `yarn': |
99 | 59 |
|
100 |
| -NXP requires users to accept and comply with a EULA in order to build and, for this reason, the buildspec will require modification before the build succeeds. See the [IMX Yocto Users Guide](https://www.nxp.com/docs/en/user-guide/IMX_YOCTO_PROJECT_USERS_GUIDE.pdf) for more detail. |
| 60 | +```bash |
| 61 | +yarn install |
| 62 | +yarn build |
| 63 | +``` |
101 | 64 |
|
102 |
| -The pipeline name starts with `NxpImxPipeline-` in the CodePipeline page. |
| 65 | +> If you are not familliar with Yarn, please refer to the [documentation](https://yarnpkg.com/getting-started). |
103 | 66 |
|
104 |
| -Example stack name: NxpImxPipeline |
| 67 | +> [!NOTE] |
| 68 | +> |
| 69 | +> While the CDK projects often do not require that you invoke the build command separately, doing so will ensure various assets in the library are packaged correctly. |
105 | 70 |
|
106 |
| -### Using pre-built, proprietary artifacts in a Pipeline |
| 71 | +### Deploying the base image pipeline stack |
107 | 72 |
|
108 |
| -This example is based on this [work](https://elinux.org/R-Car/Boards/Yocto-Gen3/v5.9.0) to build an image for Renesas R-Car-H3 Starter Kit |
109 |
| -Premier board (unofficial name - H3ULCB) including the proprietary graphics and multimedia drivers from Renesas. |
| 73 | +First, you will need to deploy the *base ubuntu* image pipeline (`aws4el-ci-pipeline-base-image`). |
110 | 74 |
|
111 |
| -Download the Multimedia and Graphics library and related Linux drivers from the following link (registration necessary): |
112 |
| -https://www.renesas.com/us/en/application/automotive/r-car-h3-m3-h2-m2-e2-documents-software |
| 75 | +```bash |
| 76 | +cdk deploy aws4el-ci-pipeline-base-image --require-approval never --progress bar |
| 77 | +``` |
113 | 78 |
|
114 |
| -#### Download two files: |
| 79 | +The created pipeline can be found in the AWS console under `Developer Tools > Pipeline - CodePipeline > Pipelines`. |
115 | 80 |
|
116 |
| -- R-Car_Gen3_Series_Evaluation_Software_Package_for_Linux-20220121.zip |
117 |
| -- R-Car_Gen3_Series_Evaluation_Software_Package_of_Linux_Drivers-20220121.zip |
| 81 | +The newly created pipeline `aws4el-ci-pipeline-base-image` should start automatically. If not, you can start it manually. |
118 | 82 |
|
119 |
| -Graphic drivers are required for Wayland. Multimedia drivers are optional. |
| 83 | +> _NOTE_: |
| 84 | +> The `aws4el-ci-pipeline-base-image` will need to be successfully completed before other pipelines can work correctly. |
120 | 85 |
|
121 |
| -#### Steps to build the image |
| 86 | +**_Expected build times: 5 minutes_** |
122 | 87 |
|
123 |
| -1. Create a folder named `proprietary` in the root of the source repo, and put those two downloaded files into this folder. |
124 |
| -1. Deploy the build pipeline and uncomment the `#TODO` in the build.sh file. |
125 |
| -1. A build should automatically start. Once it succeeds you will get an image containing the proprietary graphics and multimedia drivers. |
| 88 | +You can check that the pipeline completed sucessfully when the following command returns an ***imageIds** entry : |
126 | 89 |
|
127 |
| -See the AWS CodeBuild pipeline: RenesasPipeline-EmbeddedLinuxPipeline* |
| 90 | +```bash |
| 91 | +aws ecr list-images \ |
| 92 | + --repository-name "aws4el-ci-$AWS_DEFAULT_ACCOUNT-$AWS_DEFAULT_REGION-repo" \ |
| 93 | + --query "imageIds[?imageTag=='aws4el-ci-pipeline-base-image']" |
| 94 | +``` |
128 | 95 |
|
129 |
| -Example stack name: RenesasPipeline |
| 96 | +Once the pipeline completes and the image is available in the ECR repository, the other `EmbeddedLinuxPipeline` stacks can be created and executed. |
130 | 97 |
|
131 |
| -Expected build time: 27min / rebuild (without any change, just use sstate cache): 9min |
| 98 | +### Deploying the project pipeline stack |
132 | 99 |
|
133 |
| -### A AWS CodeBuild Project |
134 |
| -This will create an Embedded Linux ready AWS CodeBuild project that can be used to connect to a source, e.g. [GitHub Actions](https://docs.aws.amazon.com/codebuild/latest/userguide/action-runner.html). This is not using any CodePipeline. |
| 100 | +To deploy a specific pipeline type, you can use the following CDK deploy command: |
135 | 101 |
|
136 |
| -And use the EFS to share downloads and sstate cache between the runners. |
| 102 | +```bash |
| 103 | +cdk deploy <pipeline-id> --require-approval |
| 104 | +``` |
137 | 105 |
|
138 |
| -The connection to the CodeBuild source must be performed manually. |
| 106 | +where **\<pipeline-id\>** can be one or more of the following: |
| 107 | + |
| 108 | +| Name | Pipeline stack id | |
| 109 | +|---------------------|-------------------------------| |
| 110 | +| Poky | `aws4el-ci-pipeline-poky` | |
| 111 | +| Poky Ami | `aws4el-ci-pipeline-poky-ami` | |
| 112 | +| Qemu Embedded Linux | `aws4el-ci-pipeline-qemu` | |
| 113 | +| Kas | `aws4el-ci-pipeline-kas` | |
| 114 | +| Renesas | `aws4el-ci-pipeline-renesas` | |
| 115 | +| NXP-IMX | `aws4el-ci-pipeline-nxp-imx` | |
| 116 | +| Custom | `aws4el-ci-pipeline-custom` | |
| 117 | + |
| 118 | +Again, the created pipeline can be found in the AWS console under `Developer Tools > Pipeline - CodePipeline > Pipelines`. |
| 119 | + |
| 120 | +> [!**NXP-IMX**] |
| 121 | +> |
| 122 | +> The deployed pipeline for **NXP-IMX** will not complete as you should first accept the EULA and update the `build.buildspec.yml` file accordingly. See the [IMX Yocto Users Guide](https://www.nxp.com/docs/en/user-guide/IMX_YOCTO_PROJECT_USERS_GUIDE.pdf) for more detail. |
| 123 | +> |
| 124 | +> The source files are available in a S3 bucket that you can get with the following command: |
| 125 | +> |
| 126 | +> ```sh |
| 127 | +> aws cloudformation describe-stacks --stack-name aws4el-ci-pipeline-nxp-imx --output text --query "Stacks[0].Outputs[?OutputKey=='SourceURI'].OutputValue" |
| 128 | +> ``` |
| 129 | +> |
| 130 | +> Once you have adjusted the content, you can update and upload the zip back to Amazon S3, and the pipeline will restart. |
| 131 | +> |
| 132 | +
|
| 133 | +> [!**Renesas**] |
| 134 | +> |
| 135 | +> The deployed pipeline for **Renesas** will complete. However, it won't include the Multimedia and Graphics library and related Linux drivers. See the [Renesas](https://github.com/adadouche/aws4embeddedlinux-ci/blob/dev-adadouche/README.md#renesas) section for more detail. |
| 136 | +> The source files are available in a S3 bucket that you can get with the following command: |
| 137 | +> |
| 138 | +> ```sh |
| 139 | +> aws cloudformation describe-stacks --stack-name aws4el-ci-pipeline-renesas --output text --query "Stacks[0].Outputs[?OutputKey=='SourceURI'].OutputValue" |
| 140 | +> ``` |
| 141 | +> |
| 142 | +> Once you have adjusted the content, you can update and upload the zip back to Amazon S3, and the pipeline will restart. |
| 143 | +> |
| 144 | +
|
| 145 | +> [!**Custom Pipeline**] |
| 146 | +> |
| 147 | +> When using the **Custom** pipeline, you will need to provide your own `build.buildspec.yml` file. |
| 148 | +> |
| 149 | +> To do so, you will provide a path in one of the `EmbeddedLinuxCodePipelineStack` props (`sourceCustomPath` property). |
| 150 | +> This path repsent the folder where the `build.buildspec.yml` file is located. |
| 151 | +> Make sure to use a full path instead of a relative path to avoid any issues. |
| 152 | +> |
| 153 | +> If the `build.buildspec.yml` file is not present in the provided folder path, the stack will fail to deploy. |
| 154 | +> |
| 155 | +> You can also provide any additional files need to execute your build in the same folder. |
| 156 | +> |
| 157 | +
|
| 158 | +To deploy _all_ the example pipelines, you can use the CDK deploy command: |
139 | 159 |
|
140 |
| -Also you can clone the CodeBuild project and share the efs between the CodeBuild projects. |
| 160 | +```bash |
| 161 | +cdk deploy aws4el-ci-pipelines --require-approval never --concurrency 3 |
| 162 | +``` |
141 | 163 |
|
142 |
| -See the AWS CodeBuild pipeline: EmbeddedLinuxCodebuildProje-* |
| 164 | +> [!*NOTE*] |
| 165 | +> |
| 166 | +> `aws4el-ci-pipelines`is an empty stack that depends on the other stacks, so that if you deploy it, it will deploy the others. |
| 167 | +> |
143 | 168 |
|
144 |
| -To make a source connection to GitHub you need to: |
145 |
| -- Select a "Source provider"->"GitHub" |
146 |
| -- Select "Primary source webhook events" -> "Webhook - optional" -> "Rebuild every time a code change is pushed to this repository" |
147 |
| -- Add "Filter group 1" -> "WORKFLOW_JOB_QUEUED" |
148 |
| -- Modify the GitHub action `runs-on: ${{ vars.CODEBUILD_RUNNER_NAME }}-${{ github.run_id }}-${{ github.run_attempt }}` |
149 |
| -CODEBUILD_RUNNER_NAME should be `codebuild-EmbeddedLinuxCodebuildProjeNAME` with prefix `codebuild-`. See example [here](https://github.com/aws4embeddedlinux/meta-aws-demos/blob/master/.github/workflows/build-gg.yml). |
| 169 | +### Cleanup |
150 | 170 |
|
151 |
| -Example stack name: EmbeddedLinuxCodeBuildProject |
| 171 | +The `cdk destroy` command can be used to remove individual pipelines and their related resources. This can also be done in the CloudFormation Console Page. |
152 | 172 |
|
153 |
| -## Useful NPM and CDK commands |
| 173 | +> **Do not delete stacks while a CodePipeline is running, this can lead to unexpected failures!** |
154 | 174 |
|
155 |
| -- `npm run build` compile typescript to js |
156 |
| -- `npm run watch` watch for changes and compile |
157 |
| -- `npm run test` perform the jest unit tests |
158 |
| -- `cdk deploy` deploy this stack to your default AWS account/region |
159 |
| -- `cdk diff` compare deployed stack with current state |
160 |
| -- `cdk synth` emits the synthesized CloudFormation template |
| 175 | +To remove all the resources associated with this application: |
161 | 176 |
|
162 |
| -Project Specific: |
163 |
| -- `npm run format` runs prettier and eslint on the repository |
164 |
| -- `npm run zip-data` bundles the files for creating build host containers |
165 |
| -- `npm run check` checks for lint and format issues |
166 |
| -- `npm run docs` to generate documentation |
| 177 | +```bash |
| 178 | +cdk destroy --all --force |
| 179 | +``` |
167 | 180 |
|
168 | 181 | ## Security
|
169 | 182 |
|
|
0 commit comments