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

Commit

Permalink
add name to workload
Browse files Browse the repository at this point in the history
  • Loading branch information
eladb committed Oct 13, 2023
1 parent 48e2148 commit 8ac8432
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 22 deletions.
30 changes: 24 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ The `Workload` resource represents a containerized workload.
bring "wing-containers" as containers;

new containers.Workload(
name: "hello",
image: "paulbouwer/hello-kubernetes:1",
port: 8080,
readiness: "/",
replicas: 4,
env: {
"MESSAGE" => message,
}
) as "hello";
);
```

## `sim`
Expand Down Expand Up @@ -63,14 +64,31 @@ new containers.tfaws.Cluster() as "my-wing-cluster";

And provision it using Terraform:

```js
$ wing compile -t tf-aws eks.main.w
$ cd target/eks.main.tfaws
$ terraform init
$ terraform apply
```sh
wing compile -t tf-aws eks.main.w
cd target/eks.main.tfaws
terraform init
terraform apply
./eks-values.sh my-wing-cluster > values.yaml
```

This might take a up to 20 minutes to provision (now you see why we want to share it across apps?).
The last command will populate `values.yaml` with the the cluster information needed to deploy
workloads.

To connect to this cluster using `kubectl`, use:

```sh
aws eks update-kubeconfig --name my-wing-cluster
```

Then:

```sh
$ kubectl get all
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 172.20.0.1 <none> 443/TCP 36m
```

## Roadmap

Expand Down
1 change: 1 addition & 0 deletions api.w
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface IWorkload extends std.IResource {
}

struct ContainerOpts {
name: str;
image: str;
port: num?;
env: Map<str>?;
Expand Down
7 changes: 4 additions & 3 deletions sim/workload.w
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ class Workload impl api.IWorkload {
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);
let hash = utils.resolveContentHash(this, props);
this.imageTag = "${props.name}:${hash}";
this.containerId = this.imageTag;

this.urlKey = "url";

Expand Down
6 changes: 4 additions & 2 deletions test/containers.test.w
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ bring http;
let message = "hello, wing change!!";

let hello = new containers.Workload(
name: "hello",
image: "paulbouwer/hello-kubernetes:1",
port: 8080,
readiness: "/",
Expand All @@ -12,15 +13,16 @@ let hello = new containers.Workload(
"MESSAGE" => message,
},
public: true,
) as "hello";
);

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

let getBody = inflight (): str? => {
if let url = hello.url() {
Expand Down
3 changes: 2 additions & 1 deletion test/local-build.test.w
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ bring "../containers.w" as containers;
bring http;

let app = new containers.Workload(
name: "my-app",
image: "./my-app",
port: 3000,
public: true,
) as "my-app-4";
);

test "can access container" {
let response = http.get("${app.url()}");
Expand Down
3 changes: 2 additions & 1 deletion test/simple.test.w
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ bring http;
bring "../containers.w" as containers;

let app = new containers.Workload(
name: "http-echo",
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() {
Expand Down
17 changes: 8 additions & 9 deletions tfaws/workload.w
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ bring "../utils.w" as workload_utils;

class Workload impl workload_api.IWorkload {
init(props: workload_api.WorkloadProps) {
let name = "${this.node.id.replace(".", "-").substring(0, 40).lowercase()}-${this.node.addr.substring(0, 6)}";
let cluster = workload_eks.Cluster.getOrCreate(this);

let var image = props.image;
Expand All @@ -18,7 +17,7 @@ class Workload impl workload_api.IWorkload {
let hash = workload_utils.resolveContentHash(this, props);
let appDir = workload_utils.entrypointDir(this);
let repository = new workload_ecr.Repository(
name: name,
name: props.name,
directory: appDir + "/" + props.image,
tag: hash
);
Expand All @@ -29,13 +28,13 @@ class Workload impl workload_api.IWorkload {
}
}

let chart = new _Chart(name, props);
let chart = new _Chart(props);
let helmDir = chart.toHelm();

let helm = new workload_eks.HelmChart(
cluster,
dependsOn: deps.copy(),
name: name,
name: props.name,
chart: helmDir,
values: ["image: ${image}"],
);
Expand All @@ -57,7 +56,7 @@ class Workload impl workload_api.IWorkload {
class _Chart extends workload_cdk8s.Chart {
name: str;

init(name: str, props: workload_api.WorkloadProps) {
init(props: workload_api.WorkloadProps) {
let env = props.env ?? {};
let envVariables = MutMap<workload_plus.EnvValue>{};

Expand All @@ -82,7 +81,7 @@ class _Chart extends workload_cdk8s.Chart {
let deployment = new workload_plus.Deployment(
replicas: props.replicas,
metadata: {
name: name
name: props.name
},
);

Expand All @@ -105,14 +104,14 @@ class _Chart extends workload_cdk8s.Chart {
}

let service = deployment.exposeViaService(
name: name,
name: props.name,
serviceType: serviceType,
);

if isPublic {
new workload_plus.Ingress(
metadata: {
name: name,
name: props.name,
annotations: {
"kubernetes.io/ingress.class": "alb",
"alb.ingress.kubernetes.io/scheme": "internet-facing",
Expand All @@ -126,7 +125,7 @@ class _Chart extends workload_cdk8s.Chart {
);
}

this.name = name;
this.name = props.name;
}

pub toHelm(): str {
Expand Down

0 comments on commit 8ac8432

Please sign in to comment.