Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(containers): modernize #68

Merged
merged 2 commits into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion containers/aws.w
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 9 additions & 5 deletions containers/ecr.main.w
Original file line number Diff line number Diff line change
@@ -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"
);
7 changes: 5 additions & 2 deletions containers/eks.main.w
Original file line number Diff line number Diff line change
@@ -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");
}
14 changes: 12 additions & 2 deletions containers/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions containers/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@winglibs/containers",
"version": "0.0.19",
"version": "0.0.20",
"description": "Container support for Wing",
"repository": {
"type": "git",
Expand All @@ -13,8 +13,8 @@
},
"license": "MIT",
"peerDependencies": {
"cdktf": "^0.19.1",
"winglang": "^0.54.39"
"cdktf": "*",
"winglang": "*"
},
"dependencies": {
"@cdktf/provider-aws": "^18.0.5",
Expand Down
9 changes: 4 additions & 5 deletions containers/tfaws-ecr.w
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
20 changes: 10 additions & 10 deletions containers/tfaws-eks.w
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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;
}
}

Expand All @@ -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;
}
};

Expand Down
Loading