Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix permanent docker asset diff #318

Merged
merged 9 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/run-acceptance-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,17 @@ jobs:
uses: ./.github/actions/build

test:
needs:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that the build/test was failing, but the integration tests were still running. I think it's better to fail fast here.

- build
name: acceptance-test
uses: ./.github/workflows/acceptance-tests.yml
secrets: inherit
with:
folder: examples

integration-test:
needs:
- build
name: integration-test
secrets: inherit
uses: ./.github/workflows/acceptance-tests.yml
Expand Down
122 changes: 88 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,91 @@
# Pulumi CDK Adapter

The Pulumi CDK Adapter is a library that enables
[Pulumi](https://github.com/pulumi/pulumi) programs to use [AWS
CDK](https://github.com/aws/aws-cdk) constructs.
The pulumi-cdk library provides access to the many high-level libraries ('constructs') built by service
teams at AWS and by [the AWS CDK community](https://constructs.dev/).

The adapter allows writing AWS CDK code as part of an AWS CDK Stack inside a
Pulumi program, and having the resulting AWS resources be deployed and managed
via Pulumi. Outputs of resources defined in a Pulumi program can be passed
into AWS CDK Constructs, and outputs from AWS CDK stacks can be used as inputs
to other Pulumi resources.
The adapter allows writing [AWS CDK](https://docs.aws.amazon.com/cdk/v2/guide/home.html) code inside a
Pulumi program, and having the resulting AWS resources be deployed and managed via Pulumi. Pulumi and CDK resources can
seamlessly interact with each other. Outputs of resources defined in a Pulumi program can be passed into AWS CDK Constructs,
and outputs from AWS CDK stacks can be used as inputs to other Pulumi resources.

For example, to construct an [AWS AppRunner `Service`
resource](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-apprunner-alpha-readme.html)
from within a Pulumi program, and export the resulting service's URL as as
Pulumi Stack Output you write the following:
## Table of Contents

- [Pulumi CDK Adapter](#pulumi-cdk-adapter)
- [Getting Started](#getting-started)
- [Use Pulumi resources with CDK Constructs](#use-pulumi-resources-with-cdk-constructs)
- [Create Pulumi outputs](#create-pulumi-outputs)
- [Customizing providers](#customizing-providers)
- [CDK Lookups](#cdk-lookups)
- [Using Pulumi Policy Packs](#using-pulumi-policy-packs)
- [CDK Aspects](#cdk-aspects)
- [CDK Policy Validation Plugins](#cdk-policy-validation-plugins)
- [Mapping AWS resources](#mapping-aws-resources)
- [Using Assets](#using-assets)
- [Feature Flags](#feature-flags)
- [Setting Pulumi options for CDK resources](#setting-pulumi-options-for-cdk-resources)
- [Pulumi Synthesizer](#pulumi-synthesizer)
- [Unsupported Features](#unsupported-features)
- [AWS Cloud Control AutoNaming Config](#aws-cloud-control-autonaming-config)
- [Bootstrapping](#bootstrapping)
- [Multiple Stacks](#multiple-stacks)
- [API](#api)
- [Contributing](#contributing)


## Getting Started

To get started with CDK on Pulumi first [download and install Pulumi](https://www.pulumi.com/docs/install/), and [configure it to work with your AWS account](https://www.pulumi.com/registry/packages/aws/installation-configuration/).
Next, create a Pulumi TypeScript project, install the required packages, and
ensure you have configured the AWS providers.

```bash
$ pulumi new aws-typescript
$ npm install @pulumi/aws @pulumi/aws-native @pulumi/cdk @pulumi/docker-build @pulumi/pulumi aws-cdk-lib
$ pulumi config set aws-native:region us-east-2
$ pulumi config set aws:region us-east-2
```

### cdk.json File

Settings for CDK applications are typically stored in a `cdk.json` file at the
root of the project. It is recommended that you create one and populate it with
a couple of settings.

- `app`: This setting controls what command to run in order to synthesize the
CDK application.
- `output`: The directory location where the CDK output will be placed. If this
is not specified it will be placed in a system temporary directory and could
cause issues such as permanent diffs in docker image assets.
- `context`: Any context values, specifically [CDK features flags](https://docs.aws.amazon.com/cdk/v2/guide/featureflags.html).
You should populate all existing feature flags when you create a new
application. A full list can be found [here](#feature-flags)

```json
{
"app": "npx ts-node -P tsconfig.json --prefer-ts-exts src/main.ts",
"output": "cdk.out",
"context": {
"@aws-cdk/aws-iam:minimizePolicies": true,
...other feature flags
}
}

```

## Example

After following the [getting started](#getting-started) steps, the next step is
to setup your application. For this example we are using the [AWS AppRunner serivce](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-apprunner-alpha-readme.html).
We will create an AppRunner `Service` from within our Pulumi program, and export the resulting service's URL as a
Pulumi Stack Output.

First install the additional `aws-apprunner-alpha` CDK package:

```bash
$ npm install @aws-cdk/aws-apprunner-alpha
```

Then update the `index.ts` file with the following code:

```ts
import * as pulumi from '@pulumi/pulumi';
Expand Down Expand Up @@ -91,28 +163,6 @@ Try the workshop at https://apprunnerworkshop.com
Read the docs at https://docs.aws.amazon.com/apprunner
```

## Table of Contents

- [Pulumi CDK Adapter](#pulumi-cdk-adapter)
- [Use Pulumi resources with CDK Constructs](#use-pulumi-resources-with-cdk-constructs)
- [Create Pulumi outputs](#create-pulumi-outputs)
- [Customizing providers](#customizing-providers)
- [CDK Lookups](#cdk-lookups)
- [Using Pulumi Policy Packs](#using-pulumi-policy-packs)
- [CDK Aspects](#cdk-aspects)
- [CDK Policy Validation Plugins](#cdk-policy-validation-plugins)
- [Mapping AWS resources](#mapping-aws-resources)
- [Using Assets](#using-assets)
- [Feature Flags](#feature-flags)
- [Setting Pulumi options for CDK resources](#setting-pulumi-options-for-cdk-resources)
- [Pulumi Synthesizer](#pulumi-synthesizer)
- [Unsupported Features](#unsupported-features)
- [AWS Cloud Control AutoNaming Config](#aws-cloud-control-autonaming-config)
- [Bootstrapping](#bootstrapping)
- [Multiple Stacks](#multiple-stacks)
- [API](#api)
- [Contributing](#contributing)

## Use Pulumi resources with CDK Constructs

It is possible to use Pulumi and CDK resources side-by-side. In order to pass a
Expand Down Expand Up @@ -672,6 +722,10 @@ const app = new pulumicdk.App('app', (scope: pulumicdk.App) => {
});
```

> **Note** If you have issues with permanent asset diffs, make sure you have
> created a [cdk.json](#cdk.json-file) with the `outdir` set to a project relative
> directory.

## Feature Flags

Feature flags in Pulumi CDK work the exact same way as in AWS CDK and can be set
Expand Down
8 changes: 4 additions & 4 deletions examples/examples_nodejs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ func TestALB(t *testing.T) {
test := getJSBaseOptions(t).
With(integration.ProgramTestOptions{
Dir: filepath.Join(getCwd(t), "alb"),
NoParallel: true, // Resources may collide with TestFargate
RetryFailedSteps: true, // Workaround for https://github.com/pulumi/pulumi-aws-native/issues/1186
})

Expand All @@ -75,9 +74,10 @@ func TestALB(t *testing.T) {
func TestFargate(t *testing.T) {
test := getJSBaseOptions(t).
With(integration.ProgramTestOptions{
Dir: filepath.Join(getCwd(t), "fargate"),
NoParallel: true,
RetryFailedSteps: true, // Workaround for https://github.com/pulumi/pulumi-aws-native/issues/1186
Dir: filepath.Join(getCwd(t), "fargate"),
RetryFailedSteps: true, // Workaround for https://github.com/pulumi/pulumi-aws-native/issues/1186
Quick: false,
SkipEmptyPreviewUpdate: false,
ExtraRuntimeValidation: func(t *testing.T, stack integration.RuntimeValidationStackInfo) {
integration.AssertHTTPResultWithRetry(t, stack.Outputs["loadBalancerURL"], nil, time.Duration(time.Minute*1), func(s string) bool {
return s == "Hello, world!"
Expand Down
6 changes: 1 addition & 5 deletions examples/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,8 @@ func getBaseOptions(t *testing.T) integration.ProgramTestOptions {
"aws-native:region": envRegion,
"prefix": prefix,
},
// some flakiness in some resource creation
// @see https://github.com/pulumi/pulumi-aws-native/issues/1714
RetryFailedSteps: true,
ExpectRefreshChanges: true,
SkipRefresh: true,
Quick: true,
ExpectRefreshChanges: true,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've fixed most of these issues, but there is still an issue with refresh changes with IAM roles due to #293

}
}

Expand Down
3 changes: 1 addition & 2 deletions examples/fargate/app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ FROM node:lts AS builder

WORKDIR /app

COPY package.json yarn.lock ./
COPY app ./
COPY package.json yarn.lock index.ts ./
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This way the docker image only changes when the app folder changes not the entire fargate folder.


RUN yarn install --frozen-lockfile
RUN npx esbuild --bundle index.ts --target="node18" --platform="node" --outfile="index.js"
Expand Down
11 changes: 11 additions & 0 deletions examples/fargate/app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "pulumi-aws-cdk",
"devDependencies": {
"@types/node": "^10.0.0"
},
"dependencies": {
"@types/express": "^5.0.0",
"esbuild": "^0.24.0",
"express": "^4.21.1"
}
}
Loading
Loading