From cd4672ca22940a1a88d1e677695627cea11f6cc7 Mon Sep 17 00:00:00 2001 From: Subhodip Roy Date: Thu, 23 Nov 2023 10:24:42 +0530 Subject: [PATCH 1/6] docker inspecting everytime for images --- containers/workload.sim.w | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/containers/workload.sim.w b/containers/workload.sim.w index 9643b71a..29722b94 100644 --- a/containers/workload.sim.w +++ b/containers/workload.sim.w @@ -70,19 +70,20 @@ pub class Workload_sim impl api.IWorkload { let opts = this.props; - // if this a reference to a local directory, build the image from a docker file - if utils.isPathInflight(opts.image) { - // check if the image is already built - try { - utils.shell("docker", ["inspect", this.imageTag]); - log("image ${this.imageTag} already exists"); - } catch { - log("building locally from ${opts.image} and tagging ${this.imageTag}..."); - utils.shell("docker", ["build", "-t", this.imageTag, opts.image], this.appDir); + try { + // check if the image exists + utils.shell("docker", ["image", "inspect", this.imageTag]); + log("image ${this.imageTag} already exists"); + } catch { + // if this a reference to a local directory, build the image from a docker file + if (utils.isPathInflight(opts.image)) { + log("building image ${this.imageTag} from ${opts.image}"); + utils.shell("docker", ["build", "-t", this.imageTag, opts.image]); + } else { + // pull the image from a registry + log("pulling image ${this.imageTag}"); + utils.shell("docker", ["pull", this.imageTag]); } - } else { - log("pulling ${opts.image}"); - utils.shell("docker", ["pull", opts.image], this.appDir); } // remove old container From 2395748c2a468c5d545cb8e47679cd8d3897a98f Mon Sep 17 00:00:00 2001 From: Subhodip Roy Date: Thu, 23 Nov 2023 19:28:18 +0530 Subject: [PATCH 2/6] fixing tests --- containers/workload.sim.w | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/containers/workload.sim.w b/containers/workload.sim.w index 29722b94..b6fe616e 100644 --- a/containers/workload.sim.w +++ b/containers/workload.sim.w @@ -70,19 +70,23 @@ pub class Workload_sim impl api.IWorkload { let opts = this.props; - try { - // check if the image exists - utils.shell("docker", ["image", "inspect", this.imageTag]); - log("image ${this.imageTag} already exists"); - } catch { - // if this a reference to a local directory, build the image from a docker file - if (utils.isPathInflight(opts.image)) { - log("building image ${this.imageTag} from ${opts.image}"); - utils.shell("docker", ["build", "-t", this.imageTag, opts.image]); - } else { - // pull the image from a registry - log("pulling image ${this.imageTag}"); - utils.shell("docker", ["pull", this.imageTag]); + // if this a reference to a local directory, build the image from a docker file + if utils.isPathInflight(opts.image) { + // check if the image is already built + try { + utils.shell("docker", ["inspect", this.imageTag]); + log("image ${this.imageTag} already exists"); + } catch { + log("building locally from ${opts.image} and tagging ${this.imageTag}..."); + utils.shell("docker", ["build", "-t", this.imageTag, opts.image], this.appDir); + } + } else { + try { + utils.shell("docker", ["inspect", this.imageTag]); + log("image ${this.imageTag} already exists"); + } catch { + log("pulling ${opts.image}"); + utils.shell("docker", ["pull", opts.image], this.appDir); } } From 6ba407a05a32b802ebd8438e2eb5fca40e3457a5 Mon Sep 17 00:00:00 2001 From: Subhodip Roy Date: Thu, 23 Nov 2023 19:42:17 +0530 Subject: [PATCH 3/6] minor fix --- containers/index.main.w | 27 +++++++++++++++++++++++++++ containers/workload.sim.w | 4 ++-- 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 containers/index.main.w diff --git a/containers/index.main.w b/containers/index.main.w new file mode 100644 index 00000000..a0408fc9 --- /dev/null +++ b/containers/index.main.w @@ -0,0 +1,27 @@ +bring "./workload.w" as containers; +bring cloud; + +pub class Redis{ + connectionUrl: str?; + new() { + let image = "redis@sha256:e50c7e23f79ae81351beacb20e004720d4bed657415e68c2b1a2b5557c075ce0"; + let container = new containers.Workload( + image: image, + name: "redis", + port: 6379, + public: true + ); + this.connectionUrl = container.publicUrl; + } + pub inflight getUrl(): str { + let url = this.connectionUrl??"error"; + return url; + } +} + +let redis = new Redis(); + +new cloud.Function(inflight () => { + let url = redis.getUrl(); + log("Redis URL: ${url}"); +}); diff --git a/containers/workload.sim.w b/containers/workload.sim.w index b6fe616e..6a4a2bb8 100644 --- a/containers/workload.sim.w +++ b/containers/workload.sim.w @@ -85,8 +85,8 @@ pub class Workload_sim impl api.IWorkload { utils.shell("docker", ["inspect", this.imageTag]); log("image ${this.imageTag} already exists"); } catch { - log("pulling ${opts.image}"); - utils.shell("docker", ["pull", opts.image], this.appDir); + log("pulling ${this.imageTag}"); + utils.shell("docker", ["pull", this.imageTag]); } } From a1f5073361fae19b0c97040ea69a5a322e65f2db Mon Sep 17 00:00:00 2001 From: Subhodip Roy Date: Thu, 23 Nov 2023 21:24:20 +0530 Subject: [PATCH 4/6] minor fix --- containers/index.main.w | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100644 containers/index.main.w diff --git a/containers/index.main.w b/containers/index.main.w deleted file mode 100644 index a0408fc9..00000000 --- a/containers/index.main.w +++ /dev/null @@ -1,27 +0,0 @@ -bring "./workload.w" as containers; -bring cloud; - -pub class Redis{ - connectionUrl: str?; - new() { - let image = "redis@sha256:e50c7e23f79ae81351beacb20e004720d4bed657415e68c2b1a2b5557c075ce0"; - let container = new containers.Workload( - image: image, - name: "redis", - port: 6379, - public: true - ); - this.connectionUrl = container.publicUrl; - } - pub inflight getUrl(): str { - let url = this.connectionUrl??"error"; - return url; - } -} - -let redis = new Redis(); - -new cloud.Function(inflight () => { - let url = redis.getUrl(); - log("Redis URL: ${url}"); -}); From 246e944a19328b34a292997d99f85a8693c010a0 Mon Sep 17 00:00:00 2001 From: Subhodip Roy Date: Sun, 26 Nov 2023 13:00:09 +0530 Subject: [PATCH 5/6] removing $ --- containers/test/local-build.test.w | 2 +- containers/test/microservices.test.w | 2 +- containers/tfaws-ecr.w | 10 ++++----- containers/tfaws-eks.w | 10 ++++----- containers/values.w | 4 ++-- containers/workload.sim.w | 32 ++++++++++++++-------------- containers/workload.tfaws.w | 8 +++---- containers/workload.w | 2 +- 8 files changed, 35 insertions(+), 35 deletions(-) diff --git a/containers/test/local-build.test.w b/containers/test/local-build.test.w index 779ef471..b66b7b39 100644 --- a/containers/test/local-build.test.w +++ b/containers/test/local-build.test.w @@ -9,6 +9,6 @@ let app = new containers.Workload( ); test "can access container" { - let response = http.get("${app.publicUrl}"); + let response = http.get("{app.publicUrl}"); assert(response.body == "Hello, Wingnuts!"); } \ No newline at end of file diff --git a/containers/test/microservices.test.w b/containers/test/microservices.test.w index df438545..a584e30f 100644 --- a/containers/test/microservices.test.w +++ b/containers/test/microservices.test.w @@ -22,7 +22,7 @@ let consumer = new containers.Workload( // TODO: failing on github for now: // test "send request" { // if let url = consumer.publicUrl { -// log("get ${url}..."); +// log("get {url}..."); // if let body = http.get(url).body { // expect.equal(body, Json.stringify({ producer_result: { result: 12 } })); // } else { diff --git a/containers/tfaws-ecr.w b/containers/tfaws-ecr.w index 2c0eb639..e92f4892 100644 --- a/containers/tfaws-ecr.w +++ b/containers/tfaws-ecr.w @@ -35,7 +35,7 @@ pub class Repository { rules: [ { rulePriority: 1, - description: "Keep only the last ${count} untagged images.", + description: "Keep only the last {count} untagged images.", selection: { tagStatus: "untagged", countType: "imageCountMoreThan", @@ -52,7 +52,7 @@ pub class Repository { let awsInfo = aws_info.Aws.getOrCreate(this); let region = awsInfo.region(); let accountId = awsInfo.accountId(); - let image = "${r.repositoryUrl}:${props.tag}"; + let image = "{r.repositoryUrl}:{props.tag}"; let arch = "linux/amd64"; @@ -72,9 +72,9 @@ pub class Repository { { type: "local-exec", command: [ - "aws ecr get-login-password --region ${region} | docker login --username AWS --password-stdin ${accountId}.dkr.ecr.${region}.amazonaws.com || exit 1", - "docker buildx build --platform ${arch} -t ${image} ${props.directory} || exit 1", - "docker push ${image} || exit 1", + "aws ecr get-login-password --region {region} | docker login --username AWS --password-stdin {accountId}.dkr.ecr.{region}.amazonaws.com || exit 1", + "docker buildx build --platform {arch} -t {image} {props.directory} || exit 1", + "docker push {image} || exit 1", ].join("\n") } ], diff --git a/containers/tfaws-eks.w b/containers/tfaws-eks.w index 75e92049..1409e84b 100644 --- a/containers/tfaws-eks.w +++ b/containers/tfaws-eks.w @@ -88,7 +88,7 @@ pub class Cluster extends ClusterBase impl ICluster { if let attrs = Cluster.tryGetClusterAttributes() { return new ClusterRef(attrs) as uid in stack; } else { - let clusterName = "wing-eks-${std.Node.of(scope).addr.substring(0, 6)}"; + let clusterName = "wing-eks-{std.Node.of(scope).addr.substring(0, 6)}"; return new Cluster(clusterName) as uid in stack; } }; @@ -118,11 +118,11 @@ pub class Cluster extends ClusterBase impl ICluster { new(clusterName: str) { let privateSubnetTags = MutMap{}; privateSubnetTags.set("kubernetes.io/role/internal-elb", "1"); - privateSubnetTags.set("kubernetes.io/cluster/${clusterName}", "shared"); + privateSubnetTags.set("kubernetes.io/cluster/{clusterName}", "shared"); let publicSubnetTags = MutMap{}; publicSubnetTags.set("kubernetes.io/role/elb", "1"); - publicSubnetTags.set("kubernetes.io/cluster/${clusterName}", "shared"); + publicSubnetTags.set("kubernetes.io/cluster/{clusterName}", "shared"); this.vpc = new vpc.Vpc( privateSubnetTags: privateSubnetTags.copy(), @@ -189,12 +189,12 @@ pub class Cluster extends ClusterBase impl ICluster { let lbRole = new cdktf.TerraformHclModule( source: "terraform-aws-modules/iam/aws//modules/iam-role-for-service-accounts-eks", variables: { - role_name: "eks-lb-role-${this.node.addr}", + role_name: "eks-lb-role-{this.node.addr}", attach_load_balancer_controller_policy: true, oidc_providers: { main: { provider_arn: this._oidcProviderArn, - namespace_service_accounts: ["kube-system:${serviceAccountName}"], + namespace_service_accounts: ["kube-system:{serviceAccountName}"], } } } diff --git a/containers/values.w b/containers/values.w index 65670ef3..4aad02f5 100644 --- a/containers/values.w +++ b/containers/values.w @@ -9,7 +9,7 @@ pub class Values { if let valuesFile = util.tryEnv("WING_VALUES_FILE") { if valuesFile != "undefined" { // bug if !fs.exists(valuesFile) { - throw "Values file ${valuesFile} not found"; + throw "Values file {valuesFile} not found"; } for x in fs.readYaml(valuesFile) { @@ -46,7 +46,7 @@ pub class Values { if let value = Values.tryGet(key) { return value; } else { - throw "Missing platform value '${key}' (use --values or -v)"; + throw "Missing platform value '{key}' (use --values or -v)"; } } } \ No newline at end of file diff --git a/containers/workload.sim.w b/containers/workload.sim.w index 6a4a2bb8..144156c6 100644 --- a/containers/workload.sim.w +++ b/containers/workload.sim.w @@ -23,8 +23,8 @@ pub class Workload_sim impl api.IWorkload { let hash = utils.resolveContentHash(this, props); if hash? { - this.imageTag = "${props.name}:${hash}"; - this.containerId = "${props.name}-${hash}"; + this.imageTag = "{props.name}:{hash}"; + this.containerId = "{props.name}-{hash}"; } else { this.imageTag = props.image; this.containerId = props.name; @@ -75,17 +75,17 @@ pub class Workload_sim impl api.IWorkload { // check if the image is already built try { utils.shell("docker", ["inspect", this.imageTag]); - log("image ${this.imageTag} already exists"); + log("image {this.imageTag} already exists"); } catch { - log("building locally from ${opts.image} and tagging ${this.imageTag}..."); + log("building locally from {opts.image} and tagging {this.imageTag}..."); utils.shell("docker", ["build", "-t", this.imageTag, opts.image], this.appDir); } } else { try { utils.shell("docker", ["inspect", this.imageTag]); - log("image ${this.imageTag} already exists"); + log("image {this.imageTag} already exists"); } catch { - log("pulling ${this.imageTag}"); + log("pulling {this.imageTag}"); utils.shell("docker", ["pull", this.imageTag]); } } @@ -102,14 +102,14 @@ pub class Workload_sim impl api.IWorkload { if let port = opts.port { dockerRun.push("-p"); - dockerRun.push("${port}"); + dockerRun.push("{port}"); } if let env = opts.env { if env.size() > 0 { dockerRun.push("-e"); for k in env.keys() { - dockerRun.push("${k}=${env.get(k)}"); + dockerRun.push("{k}={env.get(k)}"); } } } @@ -122,31 +122,31 @@ pub class Workload_sim impl api.IWorkload { } } - log("starting container ${this.containerId}"); - log("docker ${dockerRun.join(" ")}"); + log("starting container {this.containerId}"); + log("docker {dockerRun.join(" ")}"); utils.shell("docker", dockerRun.copy()); let out = Json.parse(utils.shell("docker", ["inspect", this.containerId])); if let port = opts.port { - let hostPort = out.tryGetAt(0)?.tryGet("NetworkSettings")?.tryGet("Ports")?.tryGet("${port}/tcp")?.tryGetAt(0)?.tryGet("HostPort")?.tryAsStr(); + let hostPort = out.tryGetAt(0)?.tryGet("NetworkSettings")?.tryGet("Ports")?.tryGet("{port}/tcp")?.tryGetAt(0)?.tryGet("HostPort")?.tryAsStr(); if !hostPort? { - throw "Container does not listen to port ${port}"; + throw "Container does not listen to port {port}"; } - let publicUrl = "http://localhost:${hostPort}"; + let publicUrl = "http://localhost:{hostPort}"; if let k = this.publicUrlKey { this.state.set(k, publicUrl); } if let k = this.internalUrlKey { - this.state.set(k, "http://host.docker.internal:${hostPort}"); + this.state.set(k, "http://host.docker.internal:{hostPort}"); } if let readiness = opts.readiness { - let readinessUrl = "${publicUrl}${readiness}"; - log("waiting for container to be ready: ${readinessUrl}..."); + let readinessUrl = "{publicUrl}{readiness}"; + log("waiting for container to be ready: {readinessUrl}..."); util.waitUntil(inflight () => { try { return http.get(readinessUrl).ok; diff --git a/containers/workload.tfaws.w b/containers/workload.tfaws.w index 8bae6ed4..727b45c4 100644 --- a/containers/workload.tfaws.w +++ b/containers/workload.tfaws.w @@ -68,7 +68,7 @@ pub class Workload_tfaws impl api.IWorkload { ); deployment.addContainer( - image: "{{ .Values.image }}", + image: "\{\{ .Values.image }}", envVariables: envVariables.copy(), ports: ports.copy(), readiness: readiness, @@ -125,11 +125,11 @@ pub class Workload_tfaws impl api.IWorkload { dependsOn: deps.copy(), name: props.name, chart: chart.toHelm(), - values: ["image: ${image}"], + values: ["image: {image}"], ); if let port = props.port { - this.internalUrl = "http://${props.name}:${props.port}"; + this.internalUrl = "http://{props.name}:{props.port}"; } // if "public" is set, lookup the address from the ingress resource created by the helm chart @@ -144,7 +144,7 @@ pub class Workload_tfaws impl api.IWorkload { ); let hostname = ingress.status.get(0).loadBalancer.get(0).ingress.get(0).hostname; - this.publicUrl = "http://${hostname}"; + this.publicUrl = "http://{hostname}"; } } diff --git a/containers/workload.w b/containers/workload.w index 2bb13345..57d457c0 100644 --- a/containers/workload.w +++ b/containers/workload.w @@ -17,7 +17,7 @@ pub class Workload impl api.IWorkload { } elif target == "tf-aws" { this.inner = new tfaws.Workload_tfaws(props) as props.name; } else { - throw "unsupported target ${target}"; + throw "unsupported target {target}"; } From c0851b36e74b0e3c43b15c4f293d3843776c0dab Mon Sep 17 00:00:00 2001 From: Subhodip Roy Date: Sun, 26 Nov 2023 13:30:24 +0530 Subject: [PATCH 6/6] removing $ from checks library --- checks/check-http.w | 4 ++-- checks/check.test.w | 4 ++-- checks/check.w | 4 ++-- checks/results.w | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/checks/check-http.w b/checks/check-http.w index 227265b9..b6a08a0d 100644 --- a/checks/check-http.w +++ b/checks/check-http.w @@ -26,9 +26,9 @@ pub class CheckHttp impl c.ICheck { } let method = options?.method ?? http.HttpMethod.GET; - log("http ${method} ${full_url}"); + log("http {method} {full_url}"); let response = http.fetch(full_url, method: method); - log("status ${response.status}"); + log("status {response.status}"); expect.equal(response.status, options?.status ?? 200); diff --git a/checks/check.test.w b/checks/check.test.w index 9532a8e0..27b0d390 100644 --- a/checks/check.test.w +++ b/checks/check.test.w @@ -20,9 +20,9 @@ api.get("/foo", inflight (req) => { new cloud.Function(simulateFailure) as "simulate failure"; let check = new c.Check(inflight () => { - let response = http.get("${api.url}/foo"); + let response = http.get("{api.url}/foo"); if !response.ok { - throw "response status ${response.status}"; + throw "response status {response.status}"; } log(response.body); diff --git a/checks/check.w b/checks/check.w index 31fe6a92..49334705 100644 --- a/checks/check.w +++ b/checks/check.w @@ -39,7 +39,7 @@ pub class Check impl ICheck { this.results = r.Results.of(this); let wrapper = inflight (): str => { - log("running check ${this.node.path} (${this.checkid})..."); + log("running check {this.node.path} ({this.checkid})..."); let ts = datetime.utcNow().toIso(); let var result: r.CheckResult = { @@ -52,7 +52,7 @@ pub class Check impl ICheck { try { handler(); } catch e { - log("check failed: ${e}"); + log("check failed: {e}"); result = { checkid: this.checkid, diff --git a/checks/results.w b/checks/results.w index 173b17a9..bab2d5a2 100644 --- a/checks/results.w +++ b/checks/results.w @@ -47,9 +47,9 @@ pub class Results { let checkid = result.checkid; let body = Json.stringify(result); let key = this.makeLatestKey(checkid); - log("storing ${key}"); + log("storing {key}"); this.bucket.putJson(key, result); - this.bucket.putJson(this.makeKey(checkid, "${result.timestamp}.json"), result); + this.bucket.putJson(this.makeKey(checkid, "{result.timestamp}.json"), result); } pub inflight latest(checkid: str): CheckResult? { @@ -59,7 +59,7 @@ pub class Results { } inflight makeKey(checkid: str, key: str): str { - return "${checkid}/${key}"; + return "{checkid}/{key}"; } inflight makeLatestKey(checkid: str): str {