diff --git a/containers/containers.test.w b/containers/containers.test.w deleted file mode 100644 index 6aaddb36..00000000 --- a/containers/containers.test.w +++ /dev/null @@ -1,25 +0,0 @@ -bring "./workload.w" as containers; -bring expect; -bring http; - -let echo = new containers.Workload( - name: "http-echo", - image: "hashicorp/http-echo", - port: 5678, - public: true, - replicas: 2, - args: ["-text=hello1234"], -) as "http-echo"; - -let httpGet = inflight (url: str?): str => { - if let url = url { - return http.get(url).body; - } - - throw "no body"; -}; - -test "access public url" { - let echoBody = httpGet(echo.publicUrl); - assert(echoBody.contains("hello1234")); -} diff --git a/containers/ecr.main.w b/containers/ecr.main.w deleted file mode 100644 index dcd116d5..00000000 --- a/containers/ecr.main.w +++ /dev/null @@ -1,15 +0,0 @@ -bring "./tfaws-ecr.w" as ecr; -bring util; - -class Extern { - pub static extern "./utils.js" dirname(): str; -} - -if util.env("WING_TARGET") == "tf-aws" { - new ecr.Repository( - name: "my-repository", - directory: Extern.dirname() + "/test/my-app", - tag: "tag1" - ); -} - diff --git a/containers/aws.w b/containers/eks/aws.w similarity index 100% rename from containers/aws.w rename to containers/eks/aws.w diff --git a/containers/eks-values.sh b/containers/eks/eks-values.sh similarity index 100% rename from containers/eks-values.sh rename to containers/eks/eks-values.sh diff --git a/containers/tfaws-ecr.w b/containers/eks/tfaws-ecr.w similarity index 100% rename from containers/tfaws-ecr.w rename to containers/eks/tfaws-ecr.w diff --git a/containers/tfaws-eks.w b/containers/eks/tfaws-eks.w similarity index 100% rename from containers/tfaws-eks.w rename to containers/eks/tfaws-eks.w diff --git a/containers/tfaws-vpc.w b/containers/eks/tfaws-vpc.w similarity index 100% rename from containers/tfaws-vpc.w rename to containers/eks/tfaws-vpc.w diff --git a/containers/workload.tfaws.w b/containers/eks/workload.tfaws.w similarity index 97% rename from containers/workload.tfaws.w rename to containers/eks/workload.tfaws.w index 07f3c6e5..b50d1edc 100644 --- a/containers/workload.tfaws.w +++ b/containers/eks/workload.tfaws.w @@ -1,4 +1,4 @@ -bring "./api.w" as api; +bring "../api.w" as api; bring "./tfaws-eks.w" as eks; bring "cdk8s-plus-27" as plus; bring "cdk8s" as cdk8s; @@ -6,7 +6,7 @@ bring "cdktf" as cdktf; bring "./tfaws-ecr.w" as ecr; bring "@cdktf/provider-kubernetes" as k8s; bring "@cdktf/provider-helm" as helm_provider; -bring "./helm.w" as helm; +bring "../helm/helm.w" as helm; bring fs; bring cloud; diff --git a/containers/helm.extern.d.ts b/containers/helm/helm.extern.d.ts similarity index 100% rename from containers/helm.extern.d.ts rename to containers/helm/helm.extern.d.ts diff --git a/containers/helm.js b/containers/helm/helm.js similarity index 100% rename from containers/helm.js rename to containers/helm/helm.js diff --git a/containers/helm.w b/containers/helm/helm.w similarity index 98% rename from containers/helm.w rename to containers/helm/helm.w index 5c05400e..0787e41c 100644 --- a/containers/helm.w +++ b/containers/helm/helm.w @@ -1,4 +1,4 @@ -bring "./api.w" as api; +bring "../api.w" as api; bring "cdk8s-plus-27" as plus; bring "cdk8s" as cdk8s; diff --git a/containers/package-lock.json b/containers/package-lock.json index 097eda7f..1395e4aa 100644 --- a/containers/package-lock.json +++ b/containers/package-lock.json @@ -1,12 +1,12 @@ { "name": "@winglibs/containers", - "version": "0.1.5", + "version": "0.1.6", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@winglibs/containers", - "version": "0.1.5", + "version": "0.1.6", "license": "MIT", "peerDependencies": { "@cdktf/provider-aws": "^19.12.0", diff --git a/containers/package.json b/containers/package.json index b425a1ae..ee373e63 100644 --- a/containers/package.json +++ b/containers/package.json @@ -1,6 +1,6 @@ { "name": "@winglibs/containers", - "version": "0.1.5", + "version": "0.1.6", "description": "Container support for Wing", "repository": { "type": "git", diff --git a/containers/workload.sim.w b/containers/sim/workload.sim.w similarity index 99% rename from containers/workload.sim.w rename to containers/sim/workload.sim.w index 59343640..9c6e7c1f 100644 --- a/containers/workload.sim.w +++ b/containers/sim/workload.sim.w @@ -3,7 +3,7 @@ bring util; bring cloud; bring sim; bring ui; -bring "./api.w" as api; +bring "../api.w" as api; pub class Workload_sim impl api.IWorkload { pub publicUrl: str?; diff --git a/containers/test.sh b/containers/test.sh index 7298891c..4d6a806f 100755 --- a/containers/test.sh +++ b/containers/test.sh @@ -6,5 +6,5 @@ else fi DEBUG=1 wing test -wing test -t tf-aws -s $snapshot_mode containers.test.w -wing test -t tf-aws -s $snapshot_mode containers-with-readiness.test.w +WING_CONTAINERS_PROVIDER="eks" wing test -t tf-aws -s $snapshot_mode test/containers.test.w +WING_CONTAINERS_PROVIDER="eks" wing test -t tf-aws -s $snapshot_mode test/containers-with-readiness.test.w diff --git a/containers/containers-with-readiness.test.w b/containers/test/containers-with-readiness.test.w similarity index 93% rename from containers/containers-with-readiness.test.w rename to containers/test/containers-with-readiness.test.w index 8fc09d0a..f78bb30a 100644 --- a/containers/containers-with-readiness.test.w +++ b/containers/test/containers-with-readiness.test.w @@ -1,4 +1,4 @@ -bring "./workload.w" as containers; +bring "../" as containers; bring expect; bring http; diff --git a/containers/containers-with-readiness.test.w.tf-aws.snap.md b/containers/test/containers-with-readiness.test.w.tf-aws.snap.md similarity index 99% rename from containers/containers-with-readiness.test.w.tf-aws.snap.md rename to containers/test/containers-with-readiness.test.w.tf-aws.snap.md index 88cbf431..f7cc12f5 100644 --- a/containers/containers-with-readiness.test.w.tf-aws.snap.md +++ b/containers/test/containers-with-readiness.test.w.tf-aws.snap.md @@ -316,7 +316,7 @@ "required_providers": { "aws": { "source": "aws", - "version": "5.31.0" + "version": "5.56.1" }, "helm": { "source": "helm", diff --git a/containers/test/containers.test.w b/containers/test/containers.test.w new file mode 100644 index 00000000..8c51e0d8 --- /dev/null +++ b/containers/test/containers.test.w @@ -0,0 +1,18 @@ +bring "../" as containers; +bring expect; +bring http; +bring sim; + +let echo = new containers.Workload( + name: "http-echo", + image: "hashicorp/http-echo", + port: 5678, + public: true, + replicas: 2, + args: ["-text=hello1234"], +); + +// test "access public url" { +// let echoBody = http.get(echo.publicUrl!).body; +// assert(echoBody.contains("hello1234")); +// } diff --git a/containers/containers.test.w.tf-aws.snap.md b/containers/test/containers.test.w.tf-aws.snap.md similarity index 91% rename from containers/containers.test.w.tf-aws.snap.md rename to containers/test/containers.test.w.tf-aws.snap.md index 50813f64..d127fb91 100644 --- a/containers/containers.test.w.tf-aws.snap.md +++ b/containers/test/containers.test.w.tf-aws.snap.md @@ -62,15 +62,15 @@ } }, "kubernetes_ingress_v1": { - "http-echo_DataKubernetesIngressV1_14943683": { + "Workload_http-echo_DataKubernetesIngressV1_A36C9067": { "//": { "metadata": { - "path": "root/Default/Default/http-echo/http-echo/DataKubernetesIngressV1", - "uniqueId": "http-echo_DataKubernetesIngressV1_14943683" + "path": "root/Default/Default/Workload/http-echo/DataKubernetesIngressV1", + "uniqueId": "Workload_http-echo_DataKubernetesIngressV1_A36C9067" } }, "depends_on": [ - "helm_release.http-echo_Release_2E4AC011" + "helm_release.Workload_http-echo_Release_73477725" ], "metadata": { "name": "http-echo" @@ -92,7 +92,7 @@ "enable_dns_hostnames": true, "enable_nat_gateway": true, "private_subnet_tags": { - "kubernetes.io/cluster/wing-eks-c81852": "shared", + "kubernetes.io/cluster/wing-eks-c8281f": "shared", "kubernetes.io/role/internal-elb": "1" }, "private_subnets": [ @@ -101,7 +101,7 @@ "10.0.3.0/24" ], "public_subnet_tags": { - "kubernetes.io/cluster/wing-eks-c81852": "shared", + "kubernetes.io/cluster/wing-eks-c8281f": "shared", "kubernetes.io/role/elb": "1" }, "public_subnets": [ @@ -130,7 +130,7 @@ } }, "cluster_endpoint_public_access": true, - "cluster_name": "wing-eks-c81852", + "cluster_name": "wing-eks-c8281f", "cluster_version": "1.27", "create_cluster_security_group": false, "create_node_security_group": false, @@ -179,7 +179,7 @@ }, "WingEksCluster_ekscluster_name_E1D79024": { "description": "eks.cluster_name", - "value": "wing-eks-c81852" + "value": "wing-eks-c8281f" }, "WingEksCluster_eksendpoint_FD8710BA": { "description": "eks.endpoint", @@ -201,7 +201,7 @@ "eks", "get-token", "--cluster-name", - "wing-eks-c81852" + "wing-eks-c8281f" ], "command": "aws" }, @@ -218,7 +218,7 @@ "eks", "get-token", "--cluster-name", - "wing-eks-c81852" + "wing-eks-c8281f" ], "command": "aws" }, @@ -262,18 +262,18 @@ }, { "name": "clusterName", - "value": "wing-eks-c81852" + "value": "wing-eks-c8281f" } ] }, - "http-echo_Release_2E4AC011": { + "Workload_http-echo_Release_73477725": { "//": { "metadata": { - "path": "root/Default/Default/http-echo/http-echo/Release", - "uniqueId": "http-echo_Release_2E4AC011" + "path": "root/Default/Default/Workload/http-echo/Release", + "uniqueId": "Workload_http-echo_Release_73477725" } }, - "chart": ".wing/helm/http-echo-273a4641f9f305c101f6b0ae07761c77", + "chart": ".wing/helm/http-echo-63344863709bcf4e44f7b887311641a4", "depends_on": [ ], "name": "http-echo", @@ -316,7 +316,7 @@ "required_providers": { "aws": { "source": "aws", - "version": "5.31.0" + "version": "5.56.1" }, "helm": { "source": "helm", diff --git a/containers/test/ecr.main.w b/containers/test/ecr.main.w new file mode 100644 index 00000000..9032b347 --- /dev/null +++ b/containers/test/ecr.main.w @@ -0,0 +1,11 @@ +bring "../eks/tfaws-ecr.w" as ecr; +bring util; + +if util.env("WING_TARGET") == "tf-aws" { + new ecr.Repository( + name: "my-repository", + directory: "{@dirname}/test/my-app", + tag: "tag1" + ); +} + diff --git a/containers/eks.main.w b/containers/test/eks.main.w similarity index 76% rename from containers/eks.main.w rename to containers/test/eks.main.w index bc0cf2f0..98f2aa5e 100644 --- a/containers/eks.main.w +++ b/containers/test/eks.main.w @@ -1,4 +1,4 @@ -bring "./tfaws-eks.w" as eks; +bring "../eks/tfaws-eks.w" as eks; bring util; if util.env("WING_TARGET") == "tf-aws" { diff --git a/containers/forwarders.test.w b/containers/test/forwarders.test.w similarity index 96% rename from containers/forwarders.test.w rename to containers/test/forwarders.test.w index 0081fba0..bd5eac54 100644 --- a/containers/forwarders.test.w +++ b/containers/test/forwarders.test.w @@ -2,10 +2,10 @@ bring cloud; bring util; bring http; bring expect; -bring "./workload.w" as w; +bring "../" as containers; -let workload = new w.Workload( - image: "./test/forwarders", +let workload = new containers.Workload( + image: "{@dirname}/forwarders", name: "forwarders", port: 3000, public: true, diff --git a/containers/local-build.test.w b/containers/test/local-build.test.w similarity index 79% rename from containers/local-build.test.w rename to containers/test/local-build.test.w index fbff2f5d..57ef4c1d 100644 --- a/containers/local-build.test.w +++ b/containers/test/local-build.test.w @@ -1,10 +1,10 @@ -bring "./workload.w" as containers; +bring "../" as containers; bring http; bring expect; let app = new containers.Workload( name: "my-app", - image: "./test/my_app", + image: "{@dirname}/my_app", port: 3000, public: true, ); diff --git a/containers/microservices.test.w b/containers/test/microservices.test.w similarity index 83% rename from containers/microservices.test.w rename to containers/test/microservices.test.w index 12e451f3..76757afb 100644 --- a/containers/microservices.test.w +++ b/containers/test/microservices.test.w @@ -1,17 +1,17 @@ -bring "./workload.w" as containers; +bring "../" as containers; bring cloud; bring http; bring expect; let producer = new containers.Workload( name: "producer", - image: "./test/microservices_producer", + image: "{@dirname}/microservices_producer", port: 4000, ) as "producer"; let consumer = new containers.Workload( name: "consumer", - image: "./test/microservices_consumer", + image: "{@dirname}/microservices_consumer", port: 3000, public: true, env: { diff --git a/containers/simple.test.w b/containers/test/simple.test.w similarity index 92% rename from containers/simple.test.w rename to containers/test/simple.test.w index 3c702d32..cfebaa27 100644 --- a/containers/simple.test.w +++ b/containers/test/simple.test.w @@ -1,6 +1,6 @@ bring cloud; bring http; -bring "./workload.w" as containers; +bring "../" as containers; bring expect; let app = new containers.Workload( diff --git a/containers/utils.extern.d.ts b/containers/utils.extern.d.ts deleted file mode 100644 index 5c1a51c5..00000000 --- a/containers/utils.extern.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -export default interface extern { - dirname: () => string, -} diff --git a/containers/utils.js b/containers/utils.js deleted file mode 100644 index 463d717d..00000000 --- a/containers/utils.js +++ /dev/null @@ -1,5 +0,0 @@ - -exports.dirname = function() { - return __dirname; -}; - diff --git a/containers/wing.toml b/containers/wing.toml deleted file mode 100644 index 1201cfb6..00000000 --- a/containers/wing.toml +++ /dev/null @@ -1,2 +0,0 @@ -[containers] -provider="eks" diff --git a/containers/workload.w b/containers/workload.w index 123107a8..3dd7b8ac 100644 --- a/containers/workload.w +++ b/containers/workload.w @@ -1,8 +1,8 @@ bring util; -bring "./workload.sim.w" as sim; -bring "./workload.tfaws.w" as tfaws; +bring "./sim/workload.sim.w" as sim; +bring "./eks/workload.tfaws.w" as tfaws; bring "./api.w" as api; -bring "./helm.w" as helm; +bring "./helm/helm.w" as helm; bring http; bring fs; bring ui; @@ -63,9 +63,22 @@ pub class Workload impl api.IWorkload { } resolveProvider(target: str): str { - let allowed = ["eks", "helm"]; - let params: Json = nodeof(this).app.parameters.value("containers"); - let provider = params?.tryGet("provider")?.tryAsStr(); + let value = (): str? => { + if let p = util.tryEnv("WING_CONTAINERS_PROVIDER") { + return p; + } + + let params: Json = nodeof(this).app.parameters.value("containers"); + if let provider = params?.tryGet("provider")?.tryAsStr() { + return provider; + } + + return "ecs"; + }; + + let allowed = ["eks", "helm", "ecs"]; + let provider = value(); + if provider == nil { throw "Missing 'provider' under 'containers' in wing.toml. Allowed values are {allowed.join(", ")}"; }