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

Commit

Permalink
some improvements to sim
Browse files Browse the repository at this point in the history
  • Loading branch information
eladb committed Oct 13, 2023
1 parent 146f8ec commit 2e25a33
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 12 deletions.
2 changes: 1 addition & 1 deletion api.w
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
interface IWorkload {
interface IWorkload extends std.IResource {
/** starts the container */
inflight start(): void;

Expand Down
2 changes: 2 additions & 0 deletions containers.w
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class Workload impl api.IWorkload {
} else {
throw "unsupported target ${target}";
}

std.Node.of(this.inner).hidden = true;
}

pub inflight start() {
Expand Down
20 changes: 12 additions & 8 deletions sim/workload.w
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,22 @@ class Workload impl api.IWorkload {
}

pub inflight start(): void {
log("starting container");
log("appdir=${this.appDir}");
log("starting workload...");

let opts = this.props;

let image = opts.image;

// if this a reference to a local directory, build the image from a docker file
log("image: ${image}");
if image.startsWith("./") {
log("building locally from ${image} and tagging ${this.imageTag}...");
utils.shell("docker", ["build", "-t", this.imageTag, image], this.appDir);
if opts.image.startsWith("./") {
// 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 {
log("pulling ${opts.image}");
utils.shell("docker", ["pull", opts.image], this.appDir);
}

Expand Down Expand Up @@ -83,6 +86,7 @@ class Workload impl api.IWorkload {
}
}

log("starting container ${this.containerId}");
utils.shell("docker", dockerRun.copy());

let out = Json.parse(utils.shell("docker", ["inspect", this.containerId]));
Expand Down
4 changes: 4 additions & 0 deletions test/local-build.test.w
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@ let app = new containers.Workload(

test "can access container" {
let response = http.get("${app.url()}");
if let body = response.body {
log(body);
}

assert((response.body ?? "") == "Hello, Wingnuts!");
}
2 changes: 1 addition & 1 deletion test/my-app/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:20.8.0-alpine

EXPOSE 3000
ADD index.js /app/index.js
ENTRYPOINT [ "/app/index.js" ]
16 changes: 14 additions & 2 deletions test/simple.test.w
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
bring cloud;
bring http;
bring "../containers.w" as containers;

new containers.Workload(
let app = new containers.Workload(
image: "hashicorp/http-echo",
port: 5678,
public: true,
replicas: 2,
args: ["-text=bang_bang"],
);
) as "http-echo";

test "http get" {
if let url = app.url() {
let response = http.get(url);
log(response.body ?? "");
if let body = response.body {
assert(body.contains("bang_bang"));
}
}
}

0 comments on commit 2e25a33

Please sign in to comment.