Skip to content

Commit

Permalink
add 3 additional examples
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-roos committed Aug 4, 2023
1 parent df7476e commit 677f97d
Show file tree
Hide file tree
Showing 44 changed files with 11,921 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-cdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
matrix:
node-version: [16.x, 18.x, 20.x]
dir: ['demos-pipeline/lib', 'demos-pipeline/examples']
dir: ['demos-pipeline/lib', 'demos-pipeline/example_3p', 'demos-pipeline/example_demos', 'demos-pipeline/example_poky']

defaults:
run:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
41 changes: 41 additions & 0 deletions demos-pipeline/example_3p/assets/demo/qemu/build.buildspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
version: 0.2
run-as: yoctouser

env:
shell: bash

phases:
pre_build:
run-as: root
commands:
- chown -R yoctouser /sstate-cache
- chown -R yoctouser /downloads
- chown yoctouser /build-output
- chmod 755 /sstate-cache
- chmod 755 /downloads
- chmod 755 /build-output
# Maybe not needed?
- find /sstate-cache -atime +30 -delete
- find /downloads -atime +30 -delete
build:
commands:
- echo Build started on `date`
- . oe-init-build-env $TMP_DIR
- bitbake core-image-minimal

post_build:
commands:
- echo Build completed on `date`
- bitbake -m
- ps aux | grep bitbake
- find $TMP_DIR -name '*.socket' -delete
- export BUILD_OUTPUT="$(uuidgen -t).tar"
- tar cf $BUILD_OUTPUT -C $TMP_DIR tmp
- cp -r $BUILD_OUTPUT /build-output
- echo $BUILD_OUTPUT > /build-output/tmpfile

artifacts:
discard-paths: true
files:
- /build-output/tmpfile
- $TMP_DIR/tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64*
74 changes: 74 additions & 0 deletions demos-pipeline/example_3p/bin/3p-pipeline.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/env node
import * as cdk from "aws-cdk-lib";
import { AdvancedPipelineStack, AdvancedDeviceKind } from "aws4embeddedlinux-cdk-lib";
import { BuildImageDataStack } from "aws4embeddedlinux-cdk-lib";
import { BuildImagePipelineStack, ImageKind } from "aws4embeddedlinux-cdk-lib";
import { BuildImageRepoStack } from "aws4embeddedlinux-cdk-lib";
import { PipelineNetworkStack } from "aws4embeddedlinux-cdk-lib";

const app = new cdk.App();

/**
* User Data
*/
const env = {
account: process.env.CDK_DEFAULT_ACCOUNT,
region: process.env.CDK_DEFAULT_REGION,
};

const githubRepository = {
org: process.env.GH_ORG ?? "yoctoproject",
repo: process.env.GH_REPO ?? "poky",
branch: process.env.GH_BRANCH ?? "master-next",
};

/**
* Use these default props to enable termination protection and tag related AWS
* Resources for tracking purposes.
*/
const defaultProps: cdk.StackProps = {
tags: { PURPOSE: "META-AWS-BUILD" },
terminationProtection: false,
env,
};

/**
* Set up the Stacks that create our Build Host.
*/
const buildImageData = new BuildImageDataStack(app, "BuildImageData", {
...defaultProps,
bucketName: `build-image-data-${env.account}-${env.region}`,
});

const buildImageRepo = new BuildImageRepoStack(app, "BuildImageRepo", {
...defaultProps,
});

new BuildImagePipelineStack(app, "BuildImagePipeline", {
...defaultProps,
dataBucket: buildImageData.bucket,
repository: buildImageRepo.repository,
imageKind: ImageKind.Ubuntu22_04,
});

/**
* Set up networking to allow us to securely attach EFS to our CodeBuild instances.
*/
const vpc = new PipelineNetworkStack(app, "SimplePipelineNetwork", {
...defaultProps,
});


/**
* Create a poky pipeline.
*/
new AdvancedPipelineStack(app, "three-p-Pipeline", {
...defaultProps,
githubOrg: githubRepository.org,
githubRepo: githubRepository.repo,
githubBranch: githubRepository.branch,
imageRepo: buildImageRepo.repository,
imageTag: ImageKind.Ubuntu22_04,
device: AdvancedDeviceKind.Qemu,
vpc: vpc.vpc,
});
51 changes: 51 additions & 0 deletions demos-pipeline/example_3p/cdk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"app": "npx ts-node --prefer-ts-exts bin/3p-pipeline.ts",
"poky-pipeline": "npx ts-node --prefer-ts-exts bin/3p-pipeline.ts",
"watch": {
"include": ["**"],
"exclude": [
"README.md",
"cdk*.json",
"**/*.d.ts",
"**/*.js",
"tsconfig.json",
"package*.json",
"yarn.lock",
"node_modules",
"test"
]
},
"context": {
"@aws-cdk-lib/aws-lambda:recognizeLayerVersion": true,
"@aws-cdk-lib/core:checkSecretUsage": true,
"@aws-cdk-lib/core:target-partitions": ["aws", "aws-cn"],
"@aws-cdk-lib-containers/ecs-service-extensions:enableDefaultLogDriver": true,
"@aws-cdk-lib/aws-ec2:uniqueImdsv2TemplateName": true,
"@aws-cdk-lib/aws-ecs:arnFormatIncludesClusterName": true,
"@aws-cdk-lib/aws-iam:minimizePolicies": true,
"@aws-cdk-lib/core:validateSnapshotRemovalPolicy": true,
"@aws-cdk-lib/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true,
"@aws-cdk-lib/aws-s3:createDefaultLoggingPolicy": true,
"@aws-cdk-lib/aws-sns-subscriptions:restrictSqsDescryption": true,
"@aws-cdk-lib/aws-apigateway:disableCloudWatchRole": true,
"@aws-cdk-lib/core:enablePartitionLiterals": true,
"@aws-cdk-lib/aws-events:eventsTargetQueueSameAccount": true,
"@aws-cdk-lib/aws-iam:standardizedServicePrincipals": true,
"@aws-cdk-lib/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker": true,
"@aws-cdk-lib/aws-iam:importedRoleStackSafeDefaultPolicyName": true,
"@aws-cdk-lib/aws-s3:serverAccessLogsUseBucketPolicy": true,
"@aws-cdk-lib/aws-route53-patters:useCertificate": true,
"@aws-cdk-lib/customresources:installLatestAwsSdkDefault": false,
"@aws-cdk-lib/aws-rds:databaseProxyUniqueResourceName": true,
"@aws-cdk-lib/aws-codedeploy:removeAlarmsFromDeploymentGroup": true,
"@aws-cdk-lib/aws-apigateway:authorizerChangeDeploymentLogicalId": true,
"@aws-cdk-lib/aws-ec2:launchTemplateDefaultUserData": true,
"@aws-cdk-lib/aws-secretsmanager:useAttachedSecretResourcePolicyForSecretTargetAttachments": true,
"@aws-cdk-lib/aws-redshift:columnId": true,
"@aws-cdk-lib/aws-stepfunctions-tasks:enableEmrServicePolicyV2": true,
"@aws-cdk-lib/aws-ec2:restrictDefaultSecurityGroup": true,
"@aws-cdk-lib/aws-apigateway:requestValidatorUniqueId": true,
"@aws-cdk-lib/aws-kms:aliasNameRef": true,
"@aws-cdk-lib/core:includePrefixInUniqueNameGeneration": true
}
}
File renamed without changes.
File renamed without changes.
41 changes: 41 additions & 0 deletions demos-pipeline/example_3p/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "poky-pipeline",
"version": "0.1.0",
"bin": {
"demos-pipeline": "bin/poky-pipeline.js"
},
"scripts": {
"clean": "tsc --build --clean && rm -rf dist && rm -rf cdk.out",
"build": "tsc",
"prebuild": "cd ../lib/ && npm install && npm run zip-data",
"watch": "tsc -w",
"test": "jest",
"cdk": "cdk",
"doc": "typedoc",
"format": "eslint '**/*.{js,ts,json}' --quiet --fix",
"check": "eslint '**/*.{js,ts,json}'"
},
"devDependencies": {
"@types/jest": "^29.5.1",
"@types/node": "20.1.0",
"@typescript-eslint/eslint-plugin": "^5.59.6",
"@typescript-eslint/parser": "^5.59.6",
"aws-cdk-lib": "2.86.0",
"eslint": "^8.40.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-prettier": "^4.2.1",
"jest": "^29.5.0",
"prettier": "^2.8.8",
"ts-jest": "^29.1.0",
"ts-node": "^10.9.1",
"typedoc": "^0.24.8",
"typescript": "~5.0.4"
},
"dependencies": {
"aws4embeddedlinux-cdk-lib": "file:../lib/lib",
"aws-cdk-lib": "2.86.0",
"constructs": "^10.0.0",
"source-map-support": "^0.5.21"
}
}

File renamed without changes.
3 changes: 3 additions & 0 deletions demos-pipeline/example_demos/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
npm_modules/
dist/
cdk.out/
13 changes: 13 additions & 0 deletions demos-pipeline/example_demos/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
!jest.config.js
!.eslintrc.js
!.prettierrc.js
*.js
*.d.ts
node_modules
dist

# CDK asset staging directory
.cdk.staging
cdk.out

cdk.context.json
8 changes: 8 additions & 0 deletions demos-pipeline/example_demos/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.ts
!*.d.ts

# CDK asset staging directory
.cdk.staging
cdk.out

dist
26 changes: 26 additions & 0 deletions demos-pipeline/example_demos/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Meta-AWS CDK Library

An AWS [Cloud Developer Toolkit](https://docs.aws.amazon.com/cdk/v2/guide/home.html) Library for building Yocto projects in AWS.

## Quickstart

Refer to [`docs/setup.md`](docs/setup.md)

## Useful commands

- `npm run build` compile typescript to js
- `npm run watch` watch for changes and compile
- `npm run test` perform the jest unit tests
- `cdk deploy` deploy this stack to your default AWS account/region
- `cdk diff` compare deployed stack with current state
- `cdk synth` emits the synthesized CloudFormation template

Project Specific:
- `npm run format` runs prettier and eslint on the repository
- `npm run zip-data` bundles the files for creating build host containers
- `npm run check` checks for lint and format issues
- `npm run docs` to generate documentation

## Contributing

TODO: Notes contribution process (pre-commit, running tests, formatting and test standards, etc)
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ new DemoPipelineStack(app, "QemuDemoPipeline", {
});

/**
* Create a Qemu Pipeline based on meta-aws-demos.
* Create a AGL NXP Pipeline based on meta-aws-demos.
*/
new DemoPipelineStack(app, "AglNxpPipeline", {
...defaultProps,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"app": "npx ts-node --prefer-ts-exts bin/demos-pipeline.ts",
"poky-pipeline": "npx ts-node --prefer-ts-exts bin/demos-pipeline.ts",
"watch": {
"include": ["**"],
"exclude": [
Expand Down
19 changes: 19 additions & 0 deletions demos-pipeline/example_demos/docs/setup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Setting Up

1. Fork `meta-aws-demos` repository.
1. Create a GitHub [`CodeStar Connection`](https://docs.aws.amazon.com/dtconsole/latest/userguide/connections-create-github.html) with access to your Fork.
1. Run the following:
```
npm install .
npm run build
cdk bootstrap
export GH_ORG=[owner of the fork created above - default is aws4embeddedlinux]
cdk deploy --context connectionarn=[CODESTAR_CONNECTION_ARN] --all
```

Run the newly created pipeline `ubuntu_22_04BuildImagePipeline` from the CodePipeline console page to create the build host.

After that completes, the DemoPipeline in the CodePipeline console page is ready to run.
Loading

0 comments on commit 677f97d

Please sign in to comment.