From ae699f3c33824a0a25ba1d931833de6e5c67d195 Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Sun, 4 Feb 2024 15:16:14 +0200 Subject: [PATCH] chore(containers): modernize (#68) * chore(containers): modernize * disable tests --- containers/aws.w | 2 +- containers/ecr.main.w | 14 +++++++++----- containers/eks.main.w | 7 +++++-- containers/package-lock.json | 14 ++++++++++++-- containers/package.json | 6 +++--- containers/tfaws-ecr.w | 9 ++++----- containers/tfaws-eks.w | 20 ++++++++++---------- 7 files changed, 44 insertions(+), 28 deletions(-) diff --git a/containers/aws.w b/containers/aws.w index 056d9aa1..f256431c 100644 --- a/containers/aws.w +++ b/containers/aws.w @@ -3,7 +3,7 @@ bring "@cdktf/provider-aws" as aws; pub class Aws { pub static getOrCreate(scope: std.IResource): Aws { - let stack = cdktf.TerraformStack.of(scope); + let stack = nodeof(scope).root; let id = "WingAwsUtil"; let existing: Aws? = unsafeCast(stack.node.tryFindChild(id)); return (existing ?? new Aws() as id in stack); diff --git a/containers/ecr.main.w b/containers/ecr.main.w index e9db9a1e..fe313564 100644 --- a/containers/ecr.main.w +++ b/containers/ecr.main.w @@ -1,8 +1,12 @@ bring "./tfaws-ecr.w" as ecr; bring "./utils.w" as utils; +bring util; + +if util.env("WING_TARGET") == "tf-aws" { + new ecr.Repository( + name: "my-repository", + directory: utils.dirname() + "/test/my-app", + tag: "tag1" + ); +} -new ecr.Repository( - name: "my-repository", - directory: utils.dirname() + "/test/my-app", - tag: "tag1" -); diff --git a/containers/eks.main.w b/containers/eks.main.w index 8bdf1455..bc0cf2f0 100644 --- a/containers/eks.main.w +++ b/containers/eks.main.w @@ -1,4 +1,7 @@ bring "./tfaws-eks.w" as eks; +bring util; -// create an eks cluster -new eks.Cluster("wing-eks"); +if util.env("WING_TARGET") == "tf-aws" { + // create an eks cluster + new eks.Cluster("wing-eks"); +} \ No newline at end of file diff --git a/containers/package-lock.json b/containers/package-lock.json index 051e6d57..2be6cd76 100644 --- a/containers/package-lock.json +++ b/containers/package-lock.json @@ -18,8 +18,8 @@ "glob": "^10.3.10" }, "peerDependencies": { - "cdktf": "^0.19.1", - "winglang": "^0.54.39" + "cdktf": "*", + "winglang": "*" } }, "node_modules/@cdktf/provider-aws": { @@ -808,6 +808,15 @@ "@octokit/openapi-types": "^12.11.0" } }, + "node_modules/@opentelemetry/api": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/api/-/api-1.7.0.tgz", + "integrity": "sha512-AdY5wvN0P2vXBi3b29hxZgSFvdhdxPB9+f0B6s//P9Q8nibRWeA3cHm8UmLpio9ABigkVHJ5NMPk+Mz8VCCyrw==", + "peer": true, + "engines": { + "node": ">=8.0.0" + } + }, "node_modules/@pkgjs/parseargs": { "version": "0.11.0", "resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz", @@ -9759,6 +9768,7 @@ "version": "2.4.3", "resolved": "https://registry.npmjs.org/safe-stable-stringify/-/safe-stable-stringify-2.4.3.tgz", "integrity": "sha512-e2bDA2WJT0wxseVd4lsDP4+3ONX6HpMXQa1ZhFQ7SU+GjvORCmShbCMltrtIDfkYhVHrOcPtj+KhmDBdPdZD1g==", + "optional": true, "engines": { "node": ">=10" } diff --git a/containers/package.json b/containers/package.json index f9906033..69373395 100644 --- a/containers/package.json +++ b/containers/package.json @@ -1,6 +1,6 @@ { "name": "@winglibs/containers", - "version": "0.0.19", + "version": "0.0.20", "description": "Container support for Wing", "repository": { "type": "git", @@ -13,8 +13,8 @@ }, "license": "MIT", "peerDependencies": { - "cdktf": "^0.19.1", - "winglang": "^0.54.39" + "cdktf": "*", + "winglang": "*" }, "dependencies": { "@cdktf/provider-aws": "^18.0.5", diff --git a/containers/tfaws-ecr.w b/containers/tfaws-ecr.w index e92f4892..fc0cff35 100644 --- a/containers/tfaws-ecr.w +++ b/containers/tfaws-ecr.w @@ -55,13 +55,12 @@ pub class Repository { let image = "{r.repositoryUrl}:{props.tag}"; let arch = "linux/amd64"; - // null provider singleton - let stack = cdktf.TerraformStack.of(this); + let root = nodeof(this).root; let nullProviderId = "NullProvider"; - if !stack.node.tryFindChild(nullProviderId)? { - new null_provider.provider.NullProvider() as nullProviderId in stack; - } + if !root.node.tryFindChild(nullProviderId)? { + new null_provider.provider.NullProvider() as nullProviderId in root; + } let publish = new null_provider.resource.Resource( dependsOn: [r], diff --git a/containers/tfaws-eks.w b/containers/tfaws-eks.w index 6aa96b89..3ea80539 100644 --- a/containers/tfaws-eks.w +++ b/containers/tfaws-eks.w @@ -28,10 +28,10 @@ pub class ClusterBase impl ICluster { } pub kubernetesProvider(): cdktf.TerraformProvider { - let stack = cdktf.TerraformStack.of(this); + let root = nodeof(this).root; let singletonKey = "WingKubernetesProvider"; let attributes = this.attributes(); - let existing = stack.node.tryFindChild(singletonKey); + let existing = root.node.tryFindChild(singletonKey); if existing? { return unsafeCast(existing); } @@ -45,14 +45,14 @@ pub class ClusterBase impl ICluster { args: ["eks", "get-token", "--cluster-name", attributes.name], command: "aws", } - ) as singletonKey in stack; + ) as singletonKey in root; } pub helmProvider(): cdktf.TerraformProvider { - let stack = cdktf.TerraformStack.of(this); + let root = nodeof(this).root; let singletonKey = "WingHelmProvider"; let attributes = this.attributes(); - let existing = stack.node.tryFindChild(singletonKey); + let existing = root.node.tryFindChild(singletonKey); if existing? { return unsafeCast(existing); } @@ -65,7 +65,7 @@ pub class ClusterBase impl ICluster { args: ["eks", "get-token", "--cluster-name", attributes.name], command: "aws", } - }) as singletonKey in stack; + }) as singletonKey in root; } } @@ -85,15 +85,15 @@ pub class Cluster extends ClusterBase impl ICluster { /** singleton */ pub static getOrCreate(scope: std.IResource): ICluster { - let stack = cdktf.TerraformStack.of(scope); + let root = nodeof(scope).root; let uid = "WingEksCluster"; - let existing: ICluster? = unsafeCast(stack.node.tryFindChild(uid)); + let existing: ICluster? = unsafeCast(root.node.tryFindChild(uid)); let newCluster = (): ICluster => { if let attrs = Cluster.tryGetClusterAttributes() { - return new ClusterRef(attrs) as uid in stack; + return new ClusterRef(attrs) as uid in root; } else { let clusterName = "wing-eks-{std.Node.of(scope).addr.substring(0, 6)}"; - return new Cluster(clusterName) as uid in stack; + return new Cluster(clusterName) as uid in root; } };