diff --git a/README.md b/README.md index 7c9d44c..2853078 100644 --- a/README.md +++ b/README.md @@ -46,10 +46,12 @@ See [Captain's Log](https://winglang.slack.com/archives/C047QFSUL5R/p16968681568 - [x] EKS as a singleton - [ ] Add support for local Dockerfiles (currently only images from Docker Hub are supported), this includes publishing into an ECR. +- [ ] Reference existing EKS repository. - [ ] Use a `cloud.Redis` database - [ ] Implement `cloud.Service` using containers. - [ ] Deploy multiple workloads (maybe guestbook?) - [ ] Publish the library +- [x] Generate helm charts under target directory - [ ] Implement `start()` and `stop()` and `url()`. - [ ] Sidecar containers - [ ] Domains diff --git a/test/containers.test.w b/test/containers.test.w index 019189c..f62c9bc 100644 --- a/test/containers.test.w +++ b/test/containers.test.w @@ -1,7 +1,7 @@ bring "../containers.w" as containers; bring http; -let message = "hello, wing!"; +let message = "hello, wing change!!"; let hello = new containers.Workload( image: "paulbouwer/hello-kubernetes:1", diff --git a/test/util.js b/test/util.js index 75bf8ca..3af7fb8 100644 --- a/test/util.js +++ b/test/util.js @@ -4,6 +4,8 @@ const fs = require('fs'); const os = require('os'); const path = require('path'); const cdktf = require('cdktf'); +const wingsdk = require('@winglang/sdk'); +const crypto = require('crypto'); exports.shell = async function (command, args, cwd) { return new Promise((resolve, reject) => { @@ -24,28 +26,34 @@ exports.entrypointDir = function (scope) { exports.toHelmChart = function(chart) { const app = cdk8s.App.of(chart); + const outdir = wingsdk.core.App.of(chart).workdir; + console.log(outdir); + app.resolvers = [new cdk8s.LazyResolver(), new cdk8s.ImplicitTokenResolver(), new cdk8s.NumberStringUnionResolver()]; const docs = cdk8s.App._synthChart(chart); const yaml = cdk8s.Yaml.stringify(...docs); - const workdir = fs.mkdtempSync(path.join(os.tmpdir(), "helm.")); + const hash = crypto.createHash("md5").update(yaml).digest("hex"); + const reldir = `helm/${chart.name}-${hash}`; + + const workdir = path.join(outdir, reldir);//fs.mkdtempSync(path.join(os.tmpdir(), "helm.")); const templates = path.join(workdir, "templates"); - fs.mkdirSync(templates, {recursive: true}); + fs.mkdirSync(templates, { recursive: true }); fs.writeFileSync(path.join(templates, "all.yaml"), yaml); const manifest = { apiVersion: "v2", - name: "app", - description: "generated by wing", + name: chart.name, + description: chart.node.path, type: "application", version: "0.1.0", - appVersion: "0.1.0", + appVersion: hash, }; fs.writeFileSync(path.join(workdir, "Chart.yaml"), cdk8s.Yaml.stringify(manifest)); - return workdir; + return path.join("./", ".wing", reldir); }; exports.toEksCluster = x => x; diff --git a/tf-aws/workload.w b/tf-aws/workload.w index 91c5010..202a2c8 100644 --- a/tf-aws/workload.w +++ b/tf-aws/workload.w @@ -32,6 +32,8 @@ class Workload impl api.IWorkload { } class _Chart extends k8s.Chart { + name: str; + init(name: str, props: api.WorkloadProps) { let env = props.env ?? {}; let envVariables = MutMap{}; @@ -100,6 +102,8 @@ class _Chart extends k8s.Chart { defaultBackend: cdk8s.IngressBackend.fromService(service), ); } + + this.name = name; } pub toHelm(): str {