From 6adeee1985a74b10e9c85761a3b5d9f1e69eb122 Mon Sep 17 00:00:00 2001 From: Chris McCormick Date: Sun, 16 Jun 2024 20:06:11 +0100 Subject: [PATCH 1/6] Add DATA_PATH to environment. Fixes #357 --- piku.py | 1 + 1 file changed, 1 insertion(+) diff --git a/piku.py b/piku.py index 205c5ea..58a2eb2 100755 --- a/piku.py +++ b/piku.py @@ -714,6 +714,7 @@ def spawn_app(app, deltas={}): env = { 'APP': app, 'LOG_ROOT': LOG_ROOT, + 'DATA_PATH': join(DATA_ROOT, app), 'HOME': environ['HOME'], 'USER': environ['USER'], 'PATH': ':'.join([join(virtualenv_path, 'bin'), environ['PATH']]), From bf2636fb44246df34c4b91e96bab79c62dc8dbaf Mon Sep 17 00:00:00 2001 From: Puneet Mehta Date: Fri, 21 Jun 2024 09:45:36 +0530 Subject: [PATCH 2/6] feat(go): go.mod support --- piku.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/piku.py b/piku.py index 142e906..8eb6668 100755 --- a/piku.py +++ b/piku.py @@ -403,7 +403,7 @@ def do_deploy(app, deltas={}, newrev=None): settings.update(deploy_java_maven(app, deltas)) elif exists(join(app_path, 'build.gradle')) and found_app("Java Gradle") and check_requirements(['java', 'gradle']): settings.update(deploy_java_gradle(app, deltas)) - elif (exists(join(app_path, 'Godeps')) or len(glob(join(app_path, '*.go')))) and found_app("Go") and check_requirements(['go']): + elif (exists(join(app_path, 'Godeps')) or exists(join(app_path, 'go.mod')) or len(glob(join(app_path, '*.go')))) and found_app("Go") and check_requirements(['go']): settings.update(deploy_go(app, deltas)) elif exists(join(app_path, 'deps.edn')) and found_app("Clojure CLI") and check_requirements(['java', 'clojure']): settings.update(deploy_clojure_cli(app, deltas)) @@ -566,6 +566,7 @@ def deploy_go(app, deltas={}): go_path = join(ENV_ROOT, app) deps = join(APP_ROOT, app, 'Godeps') + go_mod = join(APP_ROOT, app, 'go.mod') first_time = False if not exists(go_path): @@ -585,6 +586,11 @@ def deploy_go(app, deltas={}): 'GO15VENDOREXPERIMENT': '1' } call('godep update ...', cwd=join(APP_ROOT, app), env=env, shell=True) + + if exists(go_mod): + echo("-----> Running go mod tidy for '{}'".format(app), fg='green') + call('go mod tidy', cwd=join(APP_ROOT, app), shell=True) + return spawn_app(app, deltas) From 9dd884fa8a944f044a5649c09d51e191f4699e84 Mon Sep 17 00:00:00 2001 From: Puneet Mehta Date: Fri, 21 Jun 2024 09:54:56 +0530 Subject: [PATCH 3/6] chore(lint) --- piku.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/piku.py b/piku.py index 8eb6668..9cddfaf 100755 --- a/piku.py +++ b/piku.py @@ -590,7 +590,7 @@ def deploy_go(app, deltas={}): if exists(go_mod): echo("-----> Running go mod tidy for '{}'".format(app), fg='green') call('go mod tidy', cwd=join(APP_ROOT, app), shell=True) - + return spawn_app(app, deltas) From 7acadbcd61701c0bf1d06b047e7c47943c1f7f72 Mon Sep 17 00:00:00 2001 From: Henrik Persson Date: Mon, 17 Jun 2024 18:22:36 +0200 Subject: [PATCH 4/6] Add Rust --- examples/rust/.gitignore | 1 + examples/rust/Cargo.lock | 7 +++++++ examples/rust/Cargo.toml | 8 ++++++++ examples/rust/ENV | 3 +++ examples/rust/Procfile | 1 + examples/rust/rust-toolchain.toml | 2 ++ examples/rust/src/main.rs | 17 +++++++++++++++++ piku.py | 11 +++++++++++ 8 files changed, 50 insertions(+) create mode 100644 examples/rust/.gitignore create mode 100644 examples/rust/Cargo.lock create mode 100644 examples/rust/Cargo.toml create mode 100644 examples/rust/ENV create mode 100644 examples/rust/Procfile create mode 100644 examples/rust/rust-toolchain.toml create mode 100644 examples/rust/src/main.rs diff --git a/examples/rust/.gitignore b/examples/rust/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/examples/rust/.gitignore @@ -0,0 +1 @@ +/target diff --git a/examples/rust/Cargo.lock b/examples/rust/Cargo.lock new file mode 100644 index 0000000..0d59fe4 --- /dev/null +++ b/examples/rust/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "piku-rust" +version = "0.1.0" diff --git a/examples/rust/Cargo.toml b/examples/rust/Cargo.toml new file mode 100644 index 0000000..b6aff38 --- /dev/null +++ b/examples/rust/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "piku-rust" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/examples/rust/ENV b/examples/rust/ENV new file mode 100644 index 0000000..52f49a4 --- /dev/null +++ b/examples/rust/ENV @@ -0,0 +1,3 @@ +PIKU_AUTO_RESTART=1 +PORT=4000 +BIND_ADDRESS=127.0.0.1 diff --git a/examples/rust/Procfile b/examples/rust/Procfile new file mode 100644 index 0000000..14ba474 --- /dev/null +++ b/examples/rust/Procfile @@ -0,0 +1 @@ +web: cargo run diff --git a/examples/rust/rust-toolchain.toml b/examples/rust/rust-toolchain.toml new file mode 100644 index 0000000..5198580 --- /dev/null +++ b/examples/rust/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "1.78.0" diff --git a/examples/rust/src/main.rs b/examples/rust/src/main.rs new file mode 100644 index 0000000..f60cc47 --- /dev/null +++ b/examples/rust/src/main.rs @@ -0,0 +1,17 @@ +use std::{io::Write, net::TcpListener}; + +fn main() -> std::io::Result<()> { + let addr = format!("{}:{}", + std::env::var("BIND_ADDRESS").expect("no addr"), + std::env::var("PORT").expect("no port")); + + println!("Listening on {}", addr); + let listener = TcpListener::bind(addr)?; + + for stream in listener.incoming() { + let mut stream = stream?; + stream.write_all(b"Hello!\n")?; + } + + Ok(()) +} diff --git a/piku.py b/piku.py index 205c5ea..f1c1c9e 100755 --- a/piku.py +++ b/piku.py @@ -409,6 +409,8 @@ def do_deploy(app, deltas={}, newrev=None): settings.update(deploy_clojure_cli(app, deltas)) elif exists(join(app_path, 'project.clj')) and found_app("Clojure Lein") and check_requirements(['java', 'lein']): settings.update(deploy_clojure_leiningen(app, deltas)) + elif exists(join(app_path, 'Cargo.toml')) and exists(join(app_path, 'rust-toolchain.toml')) and found_app("Rust") and check_requirements(['rustc', 'cargo']): + settings.update(deploy_rust(app, deltas)) elif 'release' in workers and 'web' in workers: echo("-----> Generic app detected.", fg='green') settings.update(deploy_identity(app, deltas)) @@ -588,6 +590,15 @@ def deploy_go(app, deltas={}): return spawn_app(app, deltas) +def deploy_rust(app, deltas={}): + """Deploy a Rust application""" + + app_path = join(APP_ROOT, app) + echo("-----> Running cargo build for '{}'".format(app), fg='green') + call('cargo build', cwd=app_path, shell=True) + return spawn_app(app, deltas) + + def deploy_node(app, deltas={}): """Deploy a Node application""" From 29c5e218326fa415fccb93cd3e8c43daa12f98e5 Mon Sep 17 00:00:00 2001 From: Pedro Gandarinho Date: Wed, 26 Jun 2024 14:33:30 +0100 Subject: [PATCH 5/6] Adding support for catch-all URLs --- docs/ENV.md | 2 ++ piku.py | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/ENV.md b/docs/ENV.md index 8639627..c1f2ea6 100644 --- a/docs/ENV.md +++ b/docs/ENV.md @@ -71,6 +71,8 @@ Also, keep in mind that using `nginx` caching with a `static` website worker wil * `NGINX_INCLUDE_FILE`: a file in the app's dir to include in nginx config `server` section - useful for including custom `nginx` directives. * `NGINX_ALLOW_GIT_FOLDERS`: (boolean) allow access to `.git` folders (default: false, blocked) +* `NGINX_CATCH_ALL` (string, defaults to ""): specifies a filename to serve to all requests regardless of path (useful when using client-side routing) + ## Acme Settings diff --git a/piku.py b/piku.py index 142e906..53c9f1e 100755 --- a/piku.py +++ b/piku.py @@ -171,7 +171,7 @@ PIKU_INTERNAL_NGINX_STATIC_MAPPING = """ directio 8m; aio threads; alias $static_path; - try_files $uri $uri.html $uri/ =404; + try_files $uri $uri.html $uri/ $catch_all =404; } """ @@ -934,6 +934,8 @@ def spawn_app(app, deltas={}): static_paths = ("/" if stripped[0:1] == ":" else "/:") + (stripped if stripped else ".") + "/" + ("," if static_paths else "") + static_paths if len(static_paths): try: + # pylint: disable=unused-variable + catch_all = env.get('NGINX_CATCH_ALL', '') items = static_paths.split(',') for item in items: static_url, static_path = item.split(':') From 690e01f23672903278ce20b4cc015d9aa5db00b5 Mon Sep 17 00:00:00 2001 From: Chris McCormick Date: Wed, 26 Jun 2024 16:05:07 +0100 Subject: [PATCH 6/6] ENV var name DATA_PATH to DATA_ROOT for consistency. #357 --- piku.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/piku.py b/piku.py index 58a2eb2..da7e147 100755 --- a/piku.py +++ b/piku.py @@ -714,7 +714,7 @@ def spawn_app(app, deltas={}): env = { 'APP': app, 'LOG_ROOT': LOG_ROOT, - 'DATA_PATH': join(DATA_ROOT, app), + 'DATA_ROOT': join(DATA_ROOT, app), 'HOME': environ['HOME'], 'USER': environ['USER'], 'PATH': ':'.join([join(virtualenv_path, 'bin'), environ['PATH']]),