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

Commit

Permalink
use content hash for local image tag
Browse files Browse the repository at this point in the history
  • Loading branch information
eladb committed Oct 13, 2023
1 parent 1accbc6 commit 9541ac3
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 14 deletions.
12 changes: 6 additions & 6 deletions sim/workload.w
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ class Workload impl api.IWorkload {
urlKey: str;
props: api.WorkloadProps;
appDir: str;

imageTag: str;

init(props: api.WorkloadProps) {
this.appDir = utils.entrypointDir(this);
this.props = props;
let hash = util.sha256(Json.stringify(props));
this.containerId = "wing-${this.node.addr.substring(0, 6)}-${hash}";
this.bucket = new cloud.Bucket();
this.imageTag = utils.resolveContentHash(this, props);

this.urlKey = "url";

Expand All @@ -39,14 +41,12 @@ class Workload impl api.IWorkload {
let opts = this.props;

let image = opts.image;
let var imageTag = image;

// if this a reference to a local directory, build the image from a docker file
log("image: ${image}");
if image.startsWith("./") {
imageTag = this.containerId;
log("building locally from ${image} and tagging ${imageTag}...");
utils.shell("docker", ["build", "-t", imageTag, image], this.appDir);
log("building locally from ${image} and tagging ${this.imageTag}...");
utils.shell("docker", ["build", "-t", this.imageTag, image], this.appDir);
} else {
utils.shell("docker", ["pull", opts.image], this.appDir);
}
Expand Down Expand Up @@ -75,7 +75,7 @@ class Workload impl api.IWorkload {
}
}

dockerRun.push(imageTag);
dockerRun.push(this.imageTag);

if let runArgs = this.props.args {
for a in runArgs {
Expand Down
5 changes: 0 additions & 5 deletions test/containers.test.w
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ new containers.Workload(
args: ["-text=hello1234"],
) as "http-echo";

// new containers.Workload(
// image: "./my-app/Dockerfile",
// port: 3000
// );

let getBody = inflight (): str? => {
if let url = hello.url() {
return http.get(url).body;
Expand Down
3 changes: 2 additions & 1 deletion test/ecr.test.w
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ bring "../tf-aws/ecr.w" as ecr;
bring "../utils.w" as utils;

new ecr.Repository(
name: "my-repository",
directory: utils.dirname() + "/test/my-app",
tag: "t3"
tag: "tag1"
);
2 changes: 1 addition & 1 deletion test/local-build.test.w
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ let app = new containers.Workload(

test "can access container" {
let response = http.get("${app.url()}");
assert((response.body ?? "") == "Hello, world!");
assert((response.body ?? "") == "Hello, Wingnuts!");
}
2 changes: 1 addition & 1 deletion utils.w
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Util {

pub static resolveContentHash(scope: std.IResource, props: utils_api.WorkloadProps): str {
if !props.image.startsWith("./") {
throw "image is not a local docker build: ${props.image}";
return props.image;
}

let sources = props.sources ?? ["**/*"];
Expand Down

0 comments on commit 9541ac3

Please sign in to comment.