Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
generate helm chart under the .wing directory and use content hash to…
Browse files Browse the repository at this point in the history
… invalidate
  • Loading branch information
eladb committed Oct 10, 2023
1 parent 6091abe commit 804b7d0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/containers.test.w
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
20 changes: 14 additions & 6 deletions test/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions tf-aws/workload.w
Original file line number Diff line number Diff line change
Expand Up @@ -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<cdk8s.EnvValue>{};
Expand Down Expand Up @@ -100,6 +102,8 @@ class _Chart extends k8s.Chart {
defaultBackend: cdk8s.IngressBackend.fromService(service),
);
}

this.name = name;
}

pub toHelm(): str {
Expand Down

0 comments on commit 804b7d0

Please sign in to comment.