diff --git a/docs/_index.md b/docs/_index.md index e047d78d..3a4a0b28 100644 --- a/docs/_index.md +++ b/docs/_index.md @@ -10,7 +10,7 @@ The Threefold Resource Provider for the [threefold grid](https://threefold.io) l ### Network resource -{{< chooser language "go,python,yaml" >}} +{{< chooser language "go,python,yaml,nodejs" >}} {{% choosable language go %}} @@ -132,11 +132,35 @@ outputs: {{% /choosable %}} +{{% choosable language nodejs %}} + +```ts +import * as threefold from "@threefold/pulumi"; + +const provider = new threefold.Provider("provider", {mnemonic: process.env.MNEMONIC, network: process.env.NETWORK}); +const scheduler = new threefold.Scheduler("scheduler", {farm_ids: [1]}, { + provider: provider, +}); +const network = new threefold.Network("network", { + name: "testing", + description: "test network", + nodes: [scheduler.nodes[0]], + ip_range: "10.1.0.0/16", +}, { + provider: provider, + dependsOn: [scheduler], +}); +export const nodeDeploymentId = network.node_deployment_id; +export const nodesIpRange = network.nodes_ip_range; +``` + +{{% /choosable %}} + {{< /chooser >}} ### Virtual machine resource -{{< chooser language "go,python,yaml" >}} +{{< chooser language "go,python,yaml,nodejs" >}} {{% choosable language go %}} @@ -367,11 +391,71 @@ outputs: {{% /choosable %}} +{{% choosable language nodejs %}} + +```ts +import * as threefold from "@threefold/pulumi"; + +const provider = new threefold.Provider("provider", {mnemonic: process.env.MNEMONIC, network: process.env.NETWORK}); +const scheduler = new threefold.Scheduler("scheduler", { + mru: 0.25, + sru: 2, + farm_ids: [1], +}, { + provider: provider, +}); +const network = new threefold.Network("network", { + name: "test", + description: "test network", + nodes: [scheduler.nodes[0]], + ip_range: "10.1.0.0/16", + mycelium: true, +}, { + provider: provider, + dependsOn: [scheduler], +}); +const deployment = new threefold.Deployment("deployment", { + node_id: scheduler.nodes[0], + name: "deployment", + network_name: "test", + vms: [{ + name: "vm", + node_id: scheduler.nodes[0], + flist: "https://hub.grid.tf/tf-official-apps/base:latest.flist", + entrypoint: "/sbin/zinit init", + network_name: "test", + cpu: 2, + memory: 256, + planetary: true, + mycelium: true, + mounts: [{ + disk_name: "data", + mount_point: "/app", + }], + env_vars: { + SSH_KEY: "", + }, + }], + disks: [{ + name: "data", + size: 2, + }], +}, { + provider: provider, + dependsOn: [network], +}); +export const nodeDeploymentId = deployment.node_deployment_id; +export const planetaryIp = deployment.vms_computed.apply(vms_computed => vms_computed[0].planetary_ip); +export const myceliumIp = deployment.vms_computed.apply(vms_computed => vms_computed[0].mycelium_ip); +``` + +{{% /choosable %}} + {{< /chooser >}} ### Kubernetes resource -{{< chooser language "go,python,yaml" >}} +{{< chooser language "go,python,yaml,nodejs" >}} {{% choosable language go %}} @@ -612,11 +696,74 @@ outputs: {{% /choosable %}} +{{% choosable language nodejs %}} + +```ts +import * as threefold from "@threefold/pulumi"; + +const provider = new threefold.Provider("provider", {mnemonic: process.env.MNEMONIC, network: process.env.NETWORK}); +const scheduler = new threefold.Scheduler("scheduler", { + mru: 6, + sru: 6, + farm_ids: [1], +}, { + provider: provider, +}); +const network = new threefold.Network("network", { + name: "test", + description: "test network", + nodes: [scheduler.nodes[0]], + ip_range: "10.1.0.0/16", +}, { + provider: provider, + dependsOn: [scheduler], +}); +const kubernetes = new threefold.Kubernetes("kubernetes", { + master: { + name: "kubernetes", + network_name: "test", + node: scheduler.nodes[0], + disk_size: 2, + planetary: true, + cpu: 2, + memory: 2048, + }, + workers: [ + { + name: "worker1", + network_name: "test", + node: scheduler.nodes[0], + disk_size: 2, + cpu: 2, + memory: 2048, + }, + { + name: "worker2", + network_name: "test", + node: scheduler.nodes[0], + disk_size: 2, + cpu: 2, + memory: 2048, + }, + ], + token: "t123456789", + network_name: "test", + ssh_key: undefined, +}, { + provider: provider, + dependsOn: [network], +}); +export const nodeDeploymentId = kubernetes.node_deployment_id; +export const planetaryIp = kubernetes.master_computed.apply(master_computed => master_computed.planetary_ip); +``` + +{{% /choosable %}} + {{< /chooser >}} ### Name gateway resource -{{< chooser language "go,python,yaml" >}} +{{< chooser language "go,python,yaml,nodejs" >}} {{% choosable language go %}} @@ -741,11 +888,38 @@ outputs: {{% /choosable %}} +{{% choosable language nodejs %}} + +```ts +import * as threefold from "@threefold/pulumi"; + +const provider = new threefold.Provider("provider", {mnemonic: process.env.MNEMONIC, network: process.env.NETWORK}); +const scheduler = new threefold.Scheduler("scheduler", { + farm_ids: [1], + ipv4: true, + free_ips: 1, +}, { + provider: provider, +}); +const gatewayName = new threefold.GatewayName("gatewayName", { + name: "pulumi", + node_id: scheduler.nodes[0], + backends: ["http://69.164.223.208"], +}, { + provider: provider, + dependsOn: [scheduler], +}); +export const nodeDeploymentId = gatewayName.node_deployment_id; +export const fqdn = gatewayName.fqdn; +``` + +{{% /choosable %}} + {{< /chooser >}} ### FQDN gateway resource -{{< chooser language "go,python,yaml" >}} +{{< chooser language "go,python,yaml,nodejs" >}} {{% choosable language go %}} @@ -971,11 +1145,67 @@ outputs: {{% /choosable %}} +{{% choosable language nodejs %}} + +```ts +import * as pulumi from "@pulumi/pulumi"; +import * as threefold from "@threefold/pulumi"; + +const provider = new threefold.Provider("provider", {mnemonic: process.env.MNEMONIC, network: process.env.NETWORK}); +const scheduler = new threefold.Scheduler("scheduler", { + mru: 0.25, + farm_ids: [1], + ipv4: true, + free_ips: 1, +}, { + provider: provider, +}); +const network = new threefold.Network("network", { + name: "test", + description: "test network", + nodes: [scheduler.nodes[0]], + ip_range: "10.1.0.0/16", +}, { + provider: provider, + dependsOn: [scheduler], +}); +const deployment = new threefold.Deployment("deployment", { + node_id: scheduler.nodes[0], + name: "deployment", + network_name: "test", + vms: [{ + name: "vm", + node_id: scheduler.nodes[0], + flist: "https://hub.grid.tf/tf-official-apps/base:latest.flist", + network_name: "test", + cpu: 2, + memory: 256, + planetary: true, + }], +}, { + provider: provider, + dependsOn: [network], +}); +const gatewayFQDN = new threefold.GatewayFQDN("gatewayFQDN", { + name: "testing", + node_id: 14, + fqdn: "remote.omar.grid.tf", + backends: [pulumi.interpolate `http://[${deployment.vms_computed[0].planetary_ip}]:9000`], +}, { + provider: provider, + dependsOn: [deployment], +}); +export const nodeDeploymentId = gatewayFQDN.node_deployment_id; +export const fqdn = gatewayFQDN.fqdn; +``` + +{{% /choosable %}} + {{< /chooser >}} ### ZDB resource -{{< chooser language "go,python,yaml" >}} +{{< chooser language "go,python,yaml,nodejs" >}} {{% choosable language go %}} @@ -1117,4 +1347,36 @@ outputs: {{% /choosable %}} +{{% choosable language nodejs %}} + +```ts +import * as pulumi from "@pulumi/pulumi"; +import * as threefold from "@threefold/pulumi"; + +const provider = new threefold.Provider("provider", {mnemonic: process.env.MNEMONIC, network: process.env.NETWORK}); +const scheduler = new threefold.Scheduler("scheduler", { + mru: 0.25, + sru: 2, + farm_ids: [1], +}, { + provider: provider, +}); +const deployment = new threefold.Deployment("deployment", { + node_id: scheduler.nodes[0], + name: "zdb", + zdbs: [{ + name: "zdbsTest", + size: 2, + password: "123456", + }], +}, { + provider: provider, +}); +export const nodeDeploymentId = deployment.node_deployment_id; +export const zdbEndpoint = pulumi.all([deployment.zdbs_computed, deployment.zdbs_computed]).apply(([deploymentZdbs_computed, deploymentZdbs_computed1]) => `[${deploymentZdbs_computed[0].ips?.[1]}]:${deploymentZdbs_computed1[0].port}`); +export const zdbNamespace = deployment.zdbs_computed.apply(zdbs_computed => zdbs_computed[0].namespace); +``` + +{{% /choosable %}} + {{< /chooser >}} diff --git a/docs/installation-configuration.md b/docs/installation-configuration.md index e70e1275..443f4d38 100644 --- a/docs/installation-configuration.md +++ b/docs/installation-configuration.md @@ -9,6 +9,8 @@ layout: package The Pulumi Threefold provider is available as a package in those Pulumi languages: * Go: [`github.com/threefoldtech/pulumi-threefold/sdk`](https://pkg.go.dev/github.com/threefoldtech/pulumi-threefold/sdk) +* JavaScript/TypeScript: [`@threefold/pulumi`](https://www.npmjs.com/package/@threefold/pulumi) +* Python: [`pulumi-threefold`](https://pypi.org/project/pulumi-threefold/) ## Setup diff --git a/examples/nodejs/gateway_fqdn/.gitignore b/examples/nodejs/gateway_fqdn/.gitignore new file mode 100644 index 00000000..dc902b57 --- /dev/null +++ b/examples/nodejs/gateway_fqdn/.gitignore @@ -0,0 +1,2 @@ +/bin/ +/node_modules/ \ No newline at end of file diff --git a/examples/nodejs/gateway_fqdn/Makefile b/examples/nodejs/gateway_fqdn/Makefile new file mode 100644 index 00000000..41873400 --- /dev/null +++ b/examples/nodejs/gateway_fqdn/Makefile @@ -0,0 +1,17 @@ +current_dir = $(shell pwd) + +install: + yarn add @threefold/pulumi + +run: + rm -rf ${current_dir}/state + mkdir ${current_dir}/state + pulumi login --cloud-url file://${current_dir}/state + pulumi stack init test + pulumi up --yes + +destroy: + pulumi destroy --yes + pulumi stack rm --yes + pulumi logout + rm -rf ${current_dir}/state \ No newline at end of file diff --git a/examples/nodejs/gateway_fqdn/Pulumi.yaml b/examples/nodejs/gateway_fqdn/Pulumi.yaml new file mode 100644 index 00000000..1f1f9230 --- /dev/null +++ b/examples/nodejs/gateway_fqdn/Pulumi.yaml @@ -0,0 +1,2 @@ +name: pulumi-threefold +runtime: nodejs diff --git a/examples/nodejs/gateway_fqdn/index.ts b/examples/nodejs/gateway_fqdn/index.ts new file mode 100644 index 00000000..7961e196 --- /dev/null +++ b/examples/nodejs/gateway_fqdn/index.ts @@ -0,0 +1,49 @@ +import * as pulumi from "@pulumi/pulumi"; +import * as threefold from "@threefold/pulumi"; + +const provider = new threefold.Provider("provider", {mnemonic: process.env.MNEMONIC, network: process.env.NETWORK}); +const scheduler = new threefold.Scheduler("scheduler", { + mru: 0.25, + farm_ids: [1], + ipv4: true, + free_ips: 1, +}, { + provider: provider, +}); +const network = new threefold.Network("network", { + name: "test", + description: "test network", + nodes: [scheduler.nodes[0]], + ip_range: "10.1.0.0/16", +}, { + provider: provider, + dependsOn: [scheduler], +}); +const deployment = new threefold.Deployment("deployment", { + node_id: scheduler.nodes[0], + name: "deployment", + network_name: "test", + vms: [{ + name: "vm", + node_id: scheduler.nodes[0], + flist: "https://hub.grid.tf/tf-official-apps/base:latest.flist", + network_name: "test", + cpu: 2, + memory: 256, + planetary: true, + }], +}, { + provider: provider, + dependsOn: [network], +}); +const gatewayFQDN = new threefold.GatewayFQDN("gatewayFQDN", { + name: "testing", + node_id: 14, + fqdn: "remote.omar.grid.tf", + backends: [pulumi.interpolate `http://[${deployment.vms_computed[0].planetary_ip}]:9000`], +}, { + provider: provider, + dependsOn: [deployment], +}); +export const nodeDeploymentId = gatewayFQDN.node_deployment_id; +export const fqdn = gatewayFQDN.fqdn; diff --git a/examples/nodejs/gateway_fqdn/package.json b/examples/nodejs/gateway_fqdn/package.json new file mode 100644 index 00000000..5fdfbaaa --- /dev/null +++ b/examples/nodejs/gateway_fqdn/package.json @@ -0,0 +1,11 @@ +{ + "name": "pulumi-threefold", + "devDependencies": { + "@types/node": "^14" + }, + "dependencies": { + "@pulumi/pulumi": "^3.0.0", + "@threefold/pulumi": "^0.7.2", + "typescript": "^4.0.0" + } +} diff --git a/examples/nodejs/gateway_fqdn/tsconfig.json b/examples/nodejs/gateway_fqdn/tsconfig.json new file mode 100644 index 00000000..11fc69af --- /dev/null +++ b/examples/nodejs/gateway_fqdn/tsconfig.json @@ -0,0 +1,18 @@ +{ + "compilerOptions": { + "strict": true, + "outDir": "bin", + "target": "es2016", + "module": "commonjs", + "moduleResolution": "node", + "sourceMap": true, + "experimentalDecorators": true, + "pretty": true, + "noFallthroughCasesInSwitch": true, + "noImplicitReturns": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.ts", + ] +} \ No newline at end of file diff --git a/examples/nodejs/gateway_name/.gitignore b/examples/nodejs/gateway_name/.gitignore new file mode 100644 index 00000000..dc902b57 --- /dev/null +++ b/examples/nodejs/gateway_name/.gitignore @@ -0,0 +1,2 @@ +/bin/ +/node_modules/ \ No newline at end of file diff --git a/examples/nodejs/gateway_name/Makefile b/examples/nodejs/gateway_name/Makefile new file mode 100644 index 00000000..41873400 --- /dev/null +++ b/examples/nodejs/gateway_name/Makefile @@ -0,0 +1,17 @@ +current_dir = $(shell pwd) + +install: + yarn add @threefold/pulumi + +run: + rm -rf ${current_dir}/state + mkdir ${current_dir}/state + pulumi login --cloud-url file://${current_dir}/state + pulumi stack init test + pulumi up --yes + +destroy: + pulumi destroy --yes + pulumi stack rm --yes + pulumi logout + rm -rf ${current_dir}/state \ No newline at end of file diff --git a/examples/nodejs/gateway_name/Pulumi.yaml b/examples/nodejs/gateway_name/Pulumi.yaml new file mode 100644 index 00000000..1f1f9230 --- /dev/null +++ b/examples/nodejs/gateway_name/Pulumi.yaml @@ -0,0 +1,2 @@ +name: pulumi-threefold +runtime: nodejs diff --git a/examples/nodejs/gateway_name/index.ts b/examples/nodejs/gateway_name/index.ts new file mode 100644 index 00000000..165cff61 --- /dev/null +++ b/examples/nodejs/gateway_name/index.ts @@ -0,0 +1,20 @@ +import * as threefold from "@threefold/pulumi"; + +const provider = new threefold.Provider("provider", {mnemonic: process.env.MNEMONIC, network: process.env.NETWORK}); +const scheduler = new threefold.Scheduler("scheduler", { + farm_ids: [1], + ipv4: true, + free_ips: 1, +}, { + provider: provider, +}); +const gatewayName = new threefold.GatewayName("gatewayName", { + name: "pulumi", + node_id: scheduler.nodes[0], + backends: ["http://69.164.223.208"], +}, { + provider: provider, + dependsOn: [scheduler], +}); +export const nodeDeploymentId = gatewayName.node_deployment_id; +export const fqdn = gatewayName.fqdn; diff --git a/examples/nodejs/gateway_name/package.json b/examples/nodejs/gateway_name/package.json new file mode 100644 index 00000000..5fdfbaaa --- /dev/null +++ b/examples/nodejs/gateway_name/package.json @@ -0,0 +1,11 @@ +{ + "name": "pulumi-threefold", + "devDependencies": { + "@types/node": "^14" + }, + "dependencies": { + "@pulumi/pulumi": "^3.0.0", + "@threefold/pulumi": "^0.7.2", + "typescript": "^4.0.0" + } +} diff --git a/examples/nodejs/gateway_name/tsconfig.json b/examples/nodejs/gateway_name/tsconfig.json new file mode 100644 index 00000000..11fc69af --- /dev/null +++ b/examples/nodejs/gateway_name/tsconfig.json @@ -0,0 +1,18 @@ +{ + "compilerOptions": { + "strict": true, + "outDir": "bin", + "target": "es2016", + "module": "commonjs", + "moduleResolution": "node", + "sourceMap": true, + "experimentalDecorators": true, + "pretty": true, + "noFallthroughCasesInSwitch": true, + "noImplicitReturns": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.ts", + ] +} \ No newline at end of file diff --git a/examples/nodejs/kubernetes/.gitignore b/examples/nodejs/kubernetes/.gitignore new file mode 100644 index 00000000..dc902b57 --- /dev/null +++ b/examples/nodejs/kubernetes/.gitignore @@ -0,0 +1,2 @@ +/bin/ +/node_modules/ \ No newline at end of file diff --git a/examples/nodejs/kubernetes/Makefile b/examples/nodejs/kubernetes/Makefile new file mode 100644 index 00000000..41873400 --- /dev/null +++ b/examples/nodejs/kubernetes/Makefile @@ -0,0 +1,17 @@ +current_dir = $(shell pwd) + +install: + yarn add @threefold/pulumi + +run: + rm -rf ${current_dir}/state + mkdir ${current_dir}/state + pulumi login --cloud-url file://${current_dir}/state + pulumi stack init test + pulumi up --yes + +destroy: + pulumi destroy --yes + pulumi stack rm --yes + pulumi logout + rm -rf ${current_dir}/state \ No newline at end of file diff --git a/examples/nodejs/kubernetes/Pulumi.yaml b/examples/nodejs/kubernetes/Pulumi.yaml new file mode 100644 index 00000000..1f1f9230 --- /dev/null +++ b/examples/nodejs/kubernetes/Pulumi.yaml @@ -0,0 +1,2 @@ +name: pulumi-threefold +runtime: nodejs diff --git a/examples/nodejs/kubernetes/index.ts b/examples/nodejs/kubernetes/index.ts new file mode 100644 index 00000000..af47a5c4 --- /dev/null +++ b/examples/nodejs/kubernetes/index.ts @@ -0,0 +1,56 @@ +import * as threefold from "@threefold/pulumi"; + +const provider = new threefold.Provider("provider", {mnemonic: process.env.MNEMONIC, network: process.env.NETWORK}); +const scheduler = new threefold.Scheduler("scheduler", { + mru: 6, + sru: 6, + farm_ids: [1], +}, { + provider: provider, +}); +const network = new threefold.Network("network", { + name: "test", + description: "test network", + nodes: [scheduler.nodes[0]], + ip_range: "10.1.0.0/16", +}, { + provider: provider, + dependsOn: [scheduler], +}); +const kubernetes = new threefold.Kubernetes("kubernetes", { + master: { + name: "kubernetes", + network_name: "test", + node: scheduler.nodes[0], + disk_size: 2, + planetary: true, + cpu: 2, + memory: 2048, + }, + workers: [ + { + name: "worker1", + network_name: "test", + node: scheduler.nodes[0], + disk_size: 2, + cpu: 2, + memory: 2048, + }, + { + name: "worker2", + network_name: "test", + node: scheduler.nodes[0], + disk_size: 2, + cpu: 2, + memory: 2048, + }, + ], + token: "t123456789", + network_name: "test", + ssh_key: undefined, +}, { + provider: provider, + dependsOn: [network], +}); +export const nodeDeploymentId = kubernetes.node_deployment_id; +export const planetaryIp = kubernetes.master_computed.apply(master_computed => master_computed.planetary_ip); diff --git a/examples/nodejs/kubernetes/package.json b/examples/nodejs/kubernetes/package.json new file mode 100644 index 00000000..5fdfbaaa --- /dev/null +++ b/examples/nodejs/kubernetes/package.json @@ -0,0 +1,11 @@ +{ + "name": "pulumi-threefold", + "devDependencies": { + "@types/node": "^14" + }, + "dependencies": { + "@pulumi/pulumi": "^3.0.0", + "@threefold/pulumi": "^0.7.2", + "typescript": "^4.0.0" + } +} diff --git a/examples/nodejs/kubernetes/tsconfig.json b/examples/nodejs/kubernetes/tsconfig.json new file mode 100644 index 00000000..11fc69af --- /dev/null +++ b/examples/nodejs/kubernetes/tsconfig.json @@ -0,0 +1,18 @@ +{ + "compilerOptions": { + "strict": true, + "outDir": "bin", + "target": "es2016", + "module": "commonjs", + "moduleResolution": "node", + "sourceMap": true, + "experimentalDecorators": true, + "pretty": true, + "noFallthroughCasesInSwitch": true, + "noImplicitReturns": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.ts", + ] +} \ No newline at end of file diff --git a/examples/nodejs/network/.gitignore b/examples/nodejs/network/.gitignore new file mode 100644 index 00000000..dc902b57 --- /dev/null +++ b/examples/nodejs/network/.gitignore @@ -0,0 +1,2 @@ +/bin/ +/node_modules/ \ No newline at end of file diff --git a/examples/nodejs/network/Makefile b/examples/nodejs/network/Makefile new file mode 100644 index 00000000..41873400 --- /dev/null +++ b/examples/nodejs/network/Makefile @@ -0,0 +1,17 @@ +current_dir = $(shell pwd) + +install: + yarn add @threefold/pulumi + +run: + rm -rf ${current_dir}/state + mkdir ${current_dir}/state + pulumi login --cloud-url file://${current_dir}/state + pulumi stack init test + pulumi up --yes + +destroy: + pulumi destroy --yes + pulumi stack rm --yes + pulumi logout + rm -rf ${current_dir}/state \ No newline at end of file diff --git a/examples/nodejs/network/Pulumi.yaml b/examples/nodejs/network/Pulumi.yaml new file mode 100644 index 00000000..1f1f9230 --- /dev/null +++ b/examples/nodejs/network/Pulumi.yaml @@ -0,0 +1,2 @@ +name: pulumi-threefold +runtime: nodejs diff --git a/examples/nodejs/network/index.ts b/examples/nodejs/network/index.ts new file mode 100644 index 00000000..659b2193 --- /dev/null +++ b/examples/nodejs/network/index.ts @@ -0,0 +1,17 @@ +import * as threefold from "@threefold/pulumi"; + +const provider = new threefold.Provider("provider", {mnemonic: process.env.MNEMONIC, network: process.env.NETWORK}); +const scheduler = new threefold.Scheduler("scheduler", {farm_ids: [1]}, { + provider: provider, +}); +const network = new threefold.Network("network", { + name: "testing", + description: "test network", + nodes: [scheduler.nodes[0]], + ip_range: "10.1.0.0/16", +}, { + provider: provider, + dependsOn: [scheduler], +}); +export const nodeDeploymentId = network.node_deployment_id; +export const nodesIpRange = network.nodes_ip_range; diff --git a/examples/nodejs/network/package.json b/examples/nodejs/network/package.json new file mode 100644 index 00000000..5fdfbaaa --- /dev/null +++ b/examples/nodejs/network/package.json @@ -0,0 +1,11 @@ +{ + "name": "pulumi-threefold", + "devDependencies": { + "@types/node": "^14" + }, + "dependencies": { + "@pulumi/pulumi": "^3.0.0", + "@threefold/pulumi": "^0.7.2", + "typescript": "^4.0.0" + } +} diff --git a/examples/nodejs/network/tsconfig.json b/examples/nodejs/network/tsconfig.json new file mode 100644 index 00000000..11fc69af --- /dev/null +++ b/examples/nodejs/network/tsconfig.json @@ -0,0 +1,18 @@ +{ + "compilerOptions": { + "strict": true, + "outDir": "bin", + "target": "es2016", + "module": "commonjs", + "moduleResolution": "node", + "sourceMap": true, + "experimentalDecorators": true, + "pretty": true, + "noFallthroughCasesInSwitch": true, + "noImplicitReturns": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.ts", + ] +} \ No newline at end of file diff --git a/examples/nodejs/virtual_machine/.gitignore b/examples/nodejs/virtual_machine/.gitignore new file mode 100644 index 00000000..dc902b57 --- /dev/null +++ b/examples/nodejs/virtual_machine/.gitignore @@ -0,0 +1,2 @@ +/bin/ +/node_modules/ \ No newline at end of file diff --git a/examples/nodejs/virtual_machine/Makefile b/examples/nodejs/virtual_machine/Makefile new file mode 100644 index 00000000..41873400 --- /dev/null +++ b/examples/nodejs/virtual_machine/Makefile @@ -0,0 +1,17 @@ +current_dir = $(shell pwd) + +install: + yarn add @threefold/pulumi + +run: + rm -rf ${current_dir}/state + mkdir ${current_dir}/state + pulumi login --cloud-url file://${current_dir}/state + pulumi stack init test + pulumi up --yes + +destroy: + pulumi destroy --yes + pulumi stack rm --yes + pulumi logout + rm -rf ${current_dir}/state \ No newline at end of file diff --git a/examples/nodejs/virtual_machine/Pulumi.yaml b/examples/nodejs/virtual_machine/Pulumi.yaml new file mode 100644 index 00000000..1f1f9230 --- /dev/null +++ b/examples/nodejs/virtual_machine/Pulumi.yaml @@ -0,0 +1,2 @@ +name: pulumi-threefold +runtime: nodejs diff --git a/examples/nodejs/virtual_machine/index.ts b/examples/nodejs/virtual_machine/index.ts new file mode 100644 index 00000000..520d03fa --- /dev/null +++ b/examples/nodejs/virtual_machine/index.ts @@ -0,0 +1,53 @@ +import * as threefold from "@threefold/pulumi"; + +const provider = new threefold.Provider("provider", {mnemonic: process.env.MNEMONIC, network: process.env.NETWORK}); +const scheduler = new threefold.Scheduler("scheduler", { + mru: 0.25, + sru: 2, + farm_ids: [1], +}, { + provider: provider, +}); +const network = new threefold.Network("network", { + name: "test", + description: "test network", + nodes: [scheduler.nodes[0]], + ip_range: "10.1.0.0/16", + mycelium: true, +}, { + provider: provider, + dependsOn: [scheduler], +}); +const deployment = new threefold.Deployment("deployment", { + node_id: scheduler.nodes[0], + name: "deployment", + network_name: "test", + vms: [{ + name: "vm", + node_id: scheduler.nodes[0], + flist: "https://hub.grid.tf/tf-official-apps/base:latest.flist", + entrypoint: "/sbin/zinit init", + network_name: "test", + cpu: 2, + memory: 256, + planetary: true, + mycelium: true, + mounts: [{ + disk_name: "data", + mount_point: "/app", + }], + env_vars: { + SSH_KEY: "", + }, + }], + disks: [{ + name: "data", + size: 2, + }], +}, { + provider: provider, + dependsOn: [network], +}); +export const nodeDeploymentId = deployment.node_deployment_id; +export const planetaryIp = deployment.vms_computed.apply(vms_computed => vms_computed[0].planetary_ip); +export const myceliumIp = deployment.vms_computed.apply(vms_computed => vms_computed[0].mycelium_ip); diff --git a/examples/nodejs/virtual_machine/package.json b/examples/nodejs/virtual_machine/package.json new file mode 100644 index 00000000..06900a6a --- /dev/null +++ b/examples/nodejs/virtual_machine/package.json @@ -0,0 +1,11 @@ +{ + "name": "pulumi-threefold", + "devDependencies": { + "@types/node": "^14" + }, + "dependencies": { + "@pulumi/pulumi": "^3.131.0", + "@threefold/pulumi": "^0.7.2", + "typescript": "^4.0.0" + } +} diff --git a/examples/nodejs/virtual_machine/tsconfig.json b/examples/nodejs/virtual_machine/tsconfig.json new file mode 100644 index 00000000..11fc69af --- /dev/null +++ b/examples/nodejs/virtual_machine/tsconfig.json @@ -0,0 +1,18 @@ +{ + "compilerOptions": { + "strict": true, + "outDir": "bin", + "target": "es2016", + "module": "commonjs", + "moduleResolution": "node", + "sourceMap": true, + "experimentalDecorators": true, + "pretty": true, + "noFallthroughCasesInSwitch": true, + "noImplicitReturns": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.ts", + ] +} \ No newline at end of file diff --git a/examples/nodejs/zdb/.gitignore b/examples/nodejs/zdb/.gitignore new file mode 100644 index 00000000..dc902b57 --- /dev/null +++ b/examples/nodejs/zdb/.gitignore @@ -0,0 +1,2 @@ +/bin/ +/node_modules/ \ No newline at end of file diff --git a/examples/nodejs/zdb/Makefile b/examples/nodejs/zdb/Makefile new file mode 100644 index 00000000..41873400 --- /dev/null +++ b/examples/nodejs/zdb/Makefile @@ -0,0 +1,17 @@ +current_dir = $(shell pwd) + +install: + yarn add @threefold/pulumi + +run: + rm -rf ${current_dir}/state + mkdir ${current_dir}/state + pulumi login --cloud-url file://${current_dir}/state + pulumi stack init test + pulumi up --yes + +destroy: + pulumi destroy --yes + pulumi stack rm --yes + pulumi logout + rm -rf ${current_dir}/state \ No newline at end of file diff --git a/examples/nodejs/zdb/Pulumi.yaml b/examples/nodejs/zdb/Pulumi.yaml new file mode 100644 index 00000000..1f1f9230 --- /dev/null +++ b/examples/nodejs/zdb/Pulumi.yaml @@ -0,0 +1,2 @@ +name: pulumi-threefold +runtime: nodejs diff --git a/examples/nodejs/zdb/index.ts b/examples/nodejs/zdb/index.ts new file mode 100644 index 00000000..63974d13 --- /dev/null +++ b/examples/nodejs/zdb/index.ts @@ -0,0 +1,25 @@ +import * as pulumi from "@pulumi/pulumi"; +import * as threefold from "@threefold/pulumi"; + +const provider = new threefold.Provider("provider", {mnemonic: process.env.MNEMONIC, network: process.env.NETWORK}); +const scheduler = new threefold.Scheduler("scheduler", { + mru: 0.25, + sru: 2, + farm_ids: [1], +}, { + provider: provider, +}); +const deployment = new threefold.Deployment("deployment", { + node_id: scheduler.nodes[0], + name: "zdb", + zdbs: [{ + name: "zdbsTest", + size: 2, + password: "123456", + }], +}, { + provider: provider, +}); +export const nodeDeploymentId = deployment.node_deployment_id; +export const zdbEndpoint = pulumi.all([deployment.zdbs_computed, deployment.zdbs_computed]).apply(([deploymentZdbs_computed, deploymentZdbs_computed1]) => `[${deploymentZdbs_computed[0].ips?.[1]}]:${deploymentZdbs_computed1[0].port}`); +export const zdbNamespace = deployment.zdbs_computed.apply(zdbs_computed => zdbs_computed[0].namespace); diff --git a/examples/nodejs/zdb/package.json b/examples/nodejs/zdb/package.json new file mode 100644 index 00000000..5fdfbaaa --- /dev/null +++ b/examples/nodejs/zdb/package.json @@ -0,0 +1,11 @@ +{ + "name": "pulumi-threefold", + "devDependencies": { + "@types/node": "^14" + }, + "dependencies": { + "@pulumi/pulumi": "^3.0.0", + "@threefold/pulumi": "^0.7.2", + "typescript": "^4.0.0" + } +} diff --git a/examples/nodejs/zdb/tsconfig.json b/examples/nodejs/zdb/tsconfig.json new file mode 100644 index 00000000..11fc69af --- /dev/null +++ b/examples/nodejs/zdb/tsconfig.json @@ -0,0 +1,18 @@ +{ + "compilerOptions": { + "strict": true, + "outDir": "bin", + "target": "es2016", + "module": "commonjs", + "moduleResolution": "node", + "sourceMap": true, + "experimentalDecorators": true, + "pretty": true, + "noFallthroughCasesInSwitch": true, + "noImplicitReturns": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.ts", + ] +} \ No newline at end of file diff --git a/provider/gateway_fqdn_resource.go b/provider/gateway_fqdn_resource.go index b3bb3af3..8494c956 100644 --- a/provider/gateway_fqdn_resource.go +++ b/provider/gateway_fqdn_resource.go @@ -54,6 +54,13 @@ func (*GatewayFQDN) Check( args.NodeID = 1 } + // TODO: bypass validation of empty backend (will be assigned from vm) + for i, backend := range args.Backends { + if len(backend) == 0 { + args.Backends[i] = "http://0.0.0.0" + } + } + gw, err := parseToGatewayFQDN(args) if err != nil { return args, checkFailures, err diff --git a/provider/gateway_name_resource.go b/provider/gateway_name_resource.go index d8d93c1d..bf241512 100644 --- a/provider/gateway_name_resource.go +++ b/provider/gateway_name_resource.go @@ -54,6 +54,13 @@ func (*GatewayName) Check( args.NodeID = 1 } + // TODO: bypass validation of empty backend (will be assigned from vm) + for i, backend := range args.Backends { + if len(backend) == 0 { + args.Backends[i] = "http://0.0.0.0" + } + } + gw, err := parseToGWName(args) if err != nil { return args, checkFailures, err