Skip to content

Commit

Permalink
Pulumi wasm core (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrzejressel authored Jun 30, 2024
1 parent 59620f7 commit d940e31
Show file tree
Hide file tree
Showing 92 changed files with 4,960 additions and 2,867 deletions.
14 changes: 14 additions & 0 deletions .templates/examples.justfile.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# DO NOT EDIT
# EDIT .templates/examples.justfile.template instead
set windows-shell := ["pwsh.exe", "-c"]

run:
cargo run -p pulumi_wasm_runner -- run --wasm ../../target/wasm32-wasi/debug/pulumi/pulumi_wasm_example_docker.wasm

[windows]
local-test:
#!pwsh
cargo run -p cargo-pulumi
$env:PULUMI_CONFIG_PASSPHRASE=" "
pulumi destroy -y
pulumi up -y
70 changes: 70 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ edition.workspace = true
members = [
"cargo-pulumi",
"cargo-pulumi-gen",
"examples/dependencies",
"examples/docker",
"examples/simple",
"msgpack_protobuf_converter",
Expand All @@ -19,6 +20,7 @@ members = [
"providers/pulumi_wasm_provider_random_rust",
# DO NOT EDIT - END
"pulumi_wasm",
"pulumi_wasm_core",
"pulumi_wasm_generator",
"pulumi_wasm_runner",
"pulumi_wasm_rust",
Expand All @@ -33,6 +35,7 @@ edition = "2021"

[workspace.dependencies]
msgpack_protobuf_converter = { path = "msgpack_protobuf_converter" }
pulumi_wasm_core = { path = "pulumi_wasm_core" }
pulumi_wasm_docker = { path = "providers/pulumi_wasm_provider_docker_rust" }
pulumi_wasm_generator = { path = "pulumi_wasm_generator" }
pulumi_wasm_random = { path = "providers/pulumi_wasm_provider_random_rust" }
Expand All @@ -55,12 +58,12 @@ rmp-serde = "1.3.0"
rmpv = "1.3.0"
serde = { version = "1.0.200", features = ["derive"] }
tonic = { version = "0.11.0", default-features = false }
tonic-build = "0.11.0"
tonic-web = "0.11.0"
serde_json = "1.0.116"
wasmtime = "22.0.0"
wasmtime-wasi = "22.0.0"
tonic-build = "0.11.0"
async-trait = "0.1.80"
tonic-web = "0.11.0"
log = { version = "0.4.21", features = ["kv"] }
tracing-subscriber = "0.3.18"
log4rs = "1.3.0"
Expand All @@ -82,3 +85,4 @@ fs_extra = "1.3.0"
handlebars = "5.1.2"
convert_case = "0.6.0"
automod = "1.0.14"
mockall = "0.12.1"
2 changes: 1 addition & 1 deletion cargo-pulumi/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ fn combine_wasm_files(
.args([
"compose",
"-o",
&composite.to_str().unwrap(),
(composite.to_str().unwrap()),
current_composite.to_str().unwrap(),
"-d",
package.to_str().unwrap(),
Expand Down
19 changes: 19 additions & 0 deletions examples/dependencies/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "pulumi_wasm_example_dependencies"
version.workspace = true
edition.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
crate-type = ["cdylib"]

[dependencies]
anyhow.workspace = true
pulumi_wasm_rust.workspace = true
pulumi_wasm_random.workspace = true

[dev-dependencies]
assert_cmd.workspace = true
predicates.workspace = true
serde_json.workspace = true
1 change: 1 addition & 0 deletions examples/dependencies/Pulumi.test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
encryptionsalt: v1:bBYmvuM1zu4=:v1:wcfRBO5+pEhKsHPm:ilCUcgZLePzhLhNyzrJYgrAZkhP0hQ==
2 changes: 2 additions & 0 deletions examples/dependencies/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name: Dependencies
runtime: wasm
15 changes: 15 additions & 0 deletions examples/dependencies/justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
set windows-shell := ["pwsh.exe", "-c"]
binary := "../../target/debug/pulumi_wasm_runner"
wasm := "../../target/wasm32-wasi/debug/pulumi/pulumi_wasm_example_dependencies.wasm"

run:
{{binary}} run --wasm {{wasm}}

[windows]
local-test:
#!pwsh
cargo build -p pulumi_wasm_runner
cargo run -p cargo-pulumi
$env:PULUMI_CONFIG_PASSPHRASE=" "
pulumi destroy -y
pulumi up -y
70 changes: 70 additions & 0 deletions examples/dependencies/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
use anyhow::Error;
use pulumi_wasm_random::resource::random_string::{random_string, RandomStringArgs};
use pulumi_wasm_rust::Output;
use pulumi_wasm_rust::{add_export, pulumi_main};

#[pulumi_main]
fn test_main() -> Result<(), Error> {
let length: Output<i32> = Output::new(&4);
let random_string_1 = random_string(
"test_1",
RandomStringArgs {
keepers: None.into(),
length,
lower: None.into(),
min_lower: None.into(),
min_numeric: None.into(),
min_special: None.into(),
min_upper: None.into(),
number: None.into(),
numeric: None.into(),
override_special: None.into(),
special: None.into(),
upper: None.into(),
},
);

let new_length = random_string_1.result.map(|s| s.len() as i32);

let random_string_2 = random_string(
"test_2",
RandomStringArgs {
keepers: None.into(),
length: new_length,
lower: None.into(),
min_lower: None.into(),
min_numeric: None.into(),
min_special: None.into(),
min_upper: None.into(),
number: None.into(),
numeric: None.into(),
override_special: None.into(),
special: None.into(),
upper: None.into(),
},
);

let random_string_3 = random_string(
"test_3",
RandomStringArgs {
keepers: None.into(),
length: random_string_2.length.map(|i| i * 2),
lower: None.into(),
min_lower: None.into(),
min_numeric: None.into(),
min_special: None.into(),
min_upper: None.into(),
number: None.into(),
numeric: None.into(),
override_special: None.into(),
special: None.into(),
upper: None.into(),
},
);

add_export("result", &random_string_1.result);
add_export("number_1", &random_string_1.length);
add_export("number_2", &random_string_2.length);
add_export("number_3", &random_string_3.length);
Ok(())
}
48 changes: 48 additions & 0 deletions examples/dependencies/tests/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use assert_cmd::prelude::*;
use serde_json::Value;
use std::process::Command;
use std::str;

#[test]
fn test_integration() -> Result<(), anyhow::Error> {
let github_token_env_vars = if let Ok(token) = std::env::var("GITHUB_TOKEN") {
vec![("GITHUB_TOKEN".to_string(), token)]
} else {
vec![]
};

Command::new("pulumi")
.args(["stack", "init", "test"])
.env("PULUMI_CONFIG_PASSPHRASE", " ")
.envs(github_token_env_vars.clone())
.current_dir(".")
.output()?;

Command::new("pulumi")
.args(["stack", "select", "test"])
.current_dir(".")
.assert()
.success();

Command::new("pulumi")
.args(["up", "-y"])
.current_dir(".")
.env("PULUMI_CONFIG_PASSPHRASE", " ")
.envs(github_token_env_vars)
.assert()
.success();

let binding = Command::new("pulumi")
.args(["stack", "export"])
.current_dir(".")
.env("PULUMI_CONFIG_PASSPHRASE", " ")
.assert()
.success();
let stack = &binding.get_output().stdout;

let stack: Value = serde_json::from_str(str::from_utf8(stack)?)?;

println!("{:#?}", stack);

Ok(())
}
5 changes: 0 additions & 5 deletions examples/docker/entrypoint.ps1

This file was deleted.

1 change: 0 additions & 1 deletion examples/docker/entrypoint.sh

This file was deleted.

5 changes: 4 additions & 1 deletion examples/docker/justfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
set windows-shell := ["pwsh.exe", "-c"]
binary := "../../target/debug/pulumi_wasm_runner"
wasm := "../../target/wasm32-wasi/debug/pulumi/pulumi_wasm_example_docker.wasm"

run:
cargo run -p pulumi_wasm_runner -- run --wasm ../../target/wasm32-wasi/debug/pulumi/pulumi_wasm_example_docker.wasm
{{binary}} run --wasm {{wasm}}

[windows]
local-test:
#!pwsh
cargo build -p pulumi_wasm_runner
cargo run -p cargo-pulumi
$env:PULUMI_CONFIG_PASSPHRASE=" "
pulumi destroy -y
Expand Down
4 changes: 0 additions & 4 deletions examples/docker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ use pulumi_wasm_docker::types::DockerBuild;
use pulumi_wasm_rust::Output;
use pulumi_wasm_rust::{add_export, pulumi_main};

// Causes compilation errors
// Generated by cargo-component
// mod bindings;

#[pulumi_main]
fn test_main() -> Result<(), Error> {
let _length: Output<i32> = Output::new(&12).map(|i: i32| i * 3);
Expand Down
5 changes: 0 additions & 5 deletions examples/simple/entrypoint.ps1

This file was deleted.

1 change: 0 additions & 1 deletion examples/simple/entrypoint.sh

This file was deleted.

Loading

0 comments on commit d940e31

Please sign in to comment.