Skip to content

Commit

Permalink
feat(cli): python project template (#36)
Browse files Browse the repository at this point in the history
The command cdk8s init python-app will create a new python cdk8s project.

NOTE: this is intentionally not documented yet since we still don’t support cdk8s gen for python, so basically this only allows defining resources by directly instantiating ApiObjects. But this is still functional.
  • Loading branch information
Elad Ben-Israel committed Mar 3, 2020
1 parent 3587f71 commit 30f3bb7
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
23 changes: 23 additions & 0 deletions packages/cdk8s-cli/templates/python-app/.hooks.sscaff.js
@@ -0,0 +1,23 @@
const { execSync } = require('child_process');
const { chmodSync } = require('fs');

exports.pre = () => {
try {
execSync('which pipenv')
} catch {
console.error(`Unable to find "pipenv". Please install https://pipenv.kennethreitz.org/`)
process.exit(1);
}
};

exports.post = () => {
execSync('pipenv install', { stdio: 'inherit' });

console.log();
console.log("==================================================================================");
console.log(" Your cdk8s Python project was created successfully.");
console.log();
console.log(" Useful commands:");
console.log(" - pipenv install: creates a virtual environment and installs deps");
console.log(" - pipenv run python main.py: synthesizes a k8s manifest in 'dist/' (ready for 'kubectl apply -f')");
};
14 changes: 14 additions & 0 deletions packages/cdk8s-cli/templates/python-app/Pipfile
@@ -0,0 +1,14 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
pylint = "*"

[packages]
aws-cdk-core = "*"
cdk8s = "*"

[requires]
python_version = "3.7"
13 changes: 13 additions & 0 deletions packages/cdk8s-cli/templates/python-app/main.py
@@ -0,0 +1,13 @@
from aws_cdk.core import Construct
from cdk8s import App, Chart

class MyChart(Chart):
def __init__(self, scope: Construct, ns: str, **kwargs):
super().__init__(scope, ns, **kwargs)

# define resources here

app = App()
MyChart(app, "{{ $base }}")

app.synth()

0 comments on commit 30f3bb7

Please sign in to comment.