Skip to content

Commit 74b4fa7

Browse files
authored
Merge pull request hashicorp#314 from hashicorp/example-gardening
Make all Examples build / synth via Lerna
2 parents ab46998 + eebc222 commit 74b4fa7

28 files changed

+149
-58
lines changed

.github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,4 @@ jobs:
8484
- name: integration tests
8585
run: yarn integration-windows
8686
env:
87-
TERRAFORM_CLOUD_TOKEN: ${{ secrets.TERRAFORM_CLOUD_TOKEN }}
87+
TERRAFORM_CLOUD_TOKEN: ${{ secrets.TERRAFORM_CLOUD_TOKEN }}

.github/workflows/examples.yml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Examples Integration
2+
on: [pull_request]
3+
4+
jobs:
5+
build:
6+
runs-on: ubuntu-latest
7+
strategy:
8+
matrix:
9+
terraform: ["0.12.29", "0.13.0"]
10+
container:
11+
image: hashicorp/jsii-terraform
12+
13+
steps:
14+
- uses: actions/checkout@v2
15+
- name: installing dependencies
16+
run: |
17+
yarn install
18+
- name: compile
19+
run: |
20+
yarn build
21+
env:
22+
TERRAFORM_BINARY_NAME: "terraform${{ matrix.terraform }}"
23+
- name: create bundle
24+
run: yarn package
25+
- name: examples integration tests
26+
run: yarn examples:integration
27+
env:
28+
TERRAFORM_BINARY_NAME: "terraform${{ matrix.terraform }}"

CONTRIBUTING.md

+31-5
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,35 @@ $ yarn install
1717
$ yarn build
1818
```
1919

20-
This will also build all [Typescript examples](./examples/typescript).
20+
## Examples
2121

22-
## Development
22+
We have a few top level script commands which are executed with Lerna to make the handling of examples easier:
23+
24+
```
25+
yarn examples:reinstall // -> reinstall dependencies in Python examples
26+
yarn examples:build // -> fetch providers for examples and build them
27+
yarn examples:synth // -> synth all examples
28+
yarn examples:integration // -> run all of the above
29+
```
30+
31+
For this work, each example needs a `package.json` with at least a minmal config like this:
32+
33+
```json
34+
{
35+
"name": "@examples/[LANGUAGE]-[EXAMPLE_NAME]",
36+
"version": "0.0.0",
37+
"license": "MPL-2.0",
38+
"scripts": {
39+
"reinstall": "rm Pipfile.lock && pipenv --rm && pipenv install", // Python only
40+
"build": "cdktf get",
41+
"synth": "cdktf synth"
42+
}
43+
}
44+
```
45+
46+
Lerna is filtering for the `@examples/` prefix in the `name` field.
47+
48+
## Development
2349

2450
For development, you'd likely want to run:
2551

@@ -52,15 +78,15 @@ The easiest way to use this locally is using one of the [examples](./examples).
5278

5379
#### Typescript
5480

55-
All Typescript [examples](./examples/typescript) leverage yarn workspaces to directly reference symlinked packages. If you don't have `./node_modules/.bin` in your `$PATH`, you can use `$(yarn bin)/cdktf` to use the symlinked CLI.
81+
All Typescript [examples](./examples/typescript) leverage yarn workspaces to directly reference symlinked packages. If you don't have `./node_modules/.bin` in your `$PATH`, you can use `$(yarn bin)/cdktf` to use the symlinked CLI.
5682

5783
#### Python
5884

5985
For Python [examples](./examples/python), packages are referenced from `./dist`, there's no symlinking possible for live code updates. You'll have to explictly run `yarn package` to create new packages to be referenced in the Pipefile.
6086

6187
### Outside of this Monorepo
6288

63-
If you want to use the libraries and cli from the repo for local development, you can make use of `yarn link`.
89+
If you want to use the libraries and cli from the repo for local development, you can make use of `yarn link`.
6490

6591
### Setup
6692

@@ -84,7 +110,7 @@ $ cdktf --version
84110

85111
When the version equals `0.0.0` everything worked as expected. If you see another version, try uninstalling `cdktf-cli` with `npm` or `yarn`.
86112

87-
### Build & Package
113+
### Build & Package
88114

89115
```shell
90116
$ yarn build && yarn package

examples/python/aws-eks/Pipfile.lock

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/python/aws-eks/package.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "@examples/python-aws-eks",
3+
"version": "0.0.0",
4+
"license": "MPL-2.0",
5+
"scripts": {
6+
"reinstall": "rm Pipfile.lock && PIPENV_IGNORE_VIRTUALENVS=1 pipenv install",
7+
"build": "cdktf get",
8+
"synth": "cdktf synth"
9+
}
10+
}

examples/python/aws/Pipfile.lock

+4-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/python/aws/package.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "@examples/python-aws",
3+
"version": "0.0.0",
4+
"license": "MPL-2.0",
5+
"scripts": {
6+
"reinstall": "rm Pipfile.lock && PIPENV_IGNORE_VIRTUALENVS=1 pipenv install",
7+
"build": "cdktf get",
8+
"synth": "cdktf synth"
9+
}
10+
}

examples/python/docker/Pipfile.lock

+4-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/python/docker/main.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/usr/bin/python3 -tt
1+
#!/usr/bin/env python
2+
23
from constructs import Construct
34
from cdktf import App, TerraformStack
45
from imports.docker import Image, Container, DockerProvider

examples/python/docker/package.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "@examples/python-docker",
3+
"version": "0.0.0",
4+
"license": "MPL-2.0",
5+
"scripts": {
6+
"reinstall": "rm Pipfile.lock && PIPENV_IGNORE_VIRTUALENVS=1 pipenv install",
7+
"build": "cdktf get",
8+
"synth": "cdktf synth"
9+
}
10+
}

examples/python/kubernetes/Pipfile.lock

+4-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "@examples/python-kubernetes",
3+
"version": "0.0.0",
4+
"license": "MPL-2.0",
5+
"scripts": {
6+
"reinstall": "rm Pipfile.lock && PIPENV_IGNORE_VIRTUALENVS=1 pipenv install",
7+
"build": "cdktf get",
8+
"synth": "cdktf synth"
9+
}
10+
}

examples/typescript/aws-cloudfront-proxy/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "typescript-aws-cloudfront-proxy",
2+
"name": "@examples/typescript-aws-cloudfront-proxy",
33
"version": "0.0.0",
44
"main": "main.js",
55
"types": "main.ts",

examples/typescript/aws/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "aws",
2+
"name": "@examples/typescript-aws",
33
"version": "0.0.0",
44
"main": "index.js",
55
"license": "MPL-2.0",

examples/typescript/azure/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "typescript-azure",
3-
"version": "1.0.0",
2+
"name": "@examples/typescript-azure",
3+
"version": "0.0.0",
44
"main": "main.js",
55
"types": "main.ts",
66
"license": "MPL-2.0",

examples/typescript/backends/azurerm/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "typescript-backends-azurerm",
2+
"name": "@examples/typescript-backends-azurerm",
33
"version": "0.0.0",
44
"main": "main.js",
55
"types": "main.ts",

examples/typescript/backends/gcs/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "typescript-backends-gcs",
2+
"name": "@examples/typescript-backends-gcs",
33
"version": "1.0.0",
44
"main": "main.js",
55
"types": "main.ts",

examples/typescript/backends/remote/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "typescript-backends-remote",
2+
"name": "@examples/typescript-backends-remote",
33
"version": "1.0.0",
44
"main": "main.js",
55
"types": "main.ts",

examples/typescript/backends/s3/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "typescript-backends-s3",
2+
"name": "@examples/typescript-backends-s3",
33
"version": "1.0.0",
44
"main": "main.js",
55
"types": "main.ts",

0 commit comments

Comments
 (0)