Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have service run locally, without shuttle involved at all #4

Merged
merged 5 commits into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 3 additions & 6 deletions .mlc.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
# FIXME this config is not working... https://github.com/becheran/mlc/issues/78
# Print debug information to console
debug = false
# Do not check web links
offline = false
# Check the exact file extension when searching for a file
match-file-extension = true
# List of files and directories which will be ignored
ignore-path = [""]
ignore-path = ["target"]
# List of links which will be ignored
ignore-links = [
"*slides.md,*slides.html,*twitter.com*,*sec.gov*,*support.giphy.com*,*bitdefender.com*,*etherscan.io*,*cryptoslate.com*,*golden.com*,",
]
ignore-links = []
# List of markup types which shall be checked
markup-types = ["Markdown", "Html"]
# Wait time in milliseconds between http request to the same host
# Consider use only if getting `429 - Too Many Requests`
throttle = 0
# Path to the root folder used to resolve all relative paths
root-dir = "./content/"
root-dir = "/"
3 changes: 2 additions & 1 deletion Cargo.lock

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

33 changes: 28 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
[package]
name = "cryptorado"
name = "cryptorado-rs"
version = "0.1.0"
edition = "2021"
homepage = "https://cryptorado.org"
keywords = [
"calendar",
"shuttle.rs",
"cryptorado",
"static site",
]
publish = false
repository = "https://github.com/Cryptorado-Community/cryptorado-rs"
description = "Home of the Cryptorado Community"

exclude = [
"static/*",
]

[[bin]]
name = "cryptorado-rs"
path = "src/bin.rs"

[dependencies]
axum = "0.6.18"
shuttle-axum = "0.30.0"
shuttle-runtime = "0.30.0"
tokio = "1.28.2"
anyhow = { version = "1.0.75", optional = true }
axum = "0.6.20"
shuttle-axum = { version = "0.30.1", optional = true }
shuttle-runtime = { version = "0.30.1", optional = true }
tokio = "1.33.0"
tower-http = { version = "0.4.0", features = ["fs"] }

[features]
default = ["shuttle"]
shuttle = ["dep:shuttle-runtime", "dep:shuttle-axum"]
local = ["dep:anyhow"]
179 changes: 179 additions & 0 deletions Makefile.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
# Make using this repo easy with https://github.com/sagiegurari/cargo-make#installation
#
# See all insluded task with:
# makers --list-all-steps

[tasks.default]
alias = "serve"
dependencies = ["check-install"]

[config]
# Catch errors and report to try and help user
on_error_task = "catch-error"
# Skip loading of all core tasks which saves up a bit on toml parsing and task creation
# Also makse minimal listing of included tasks: https://github.com/sagiegurari/cargo-make#disabling-predefined-tasksflows
skip_core_tasks = true
# Skips loading Git related environment variables
skip_git_env_info = true
# Skips loading rust related environment variables
skip_rust_env_info = true
# Skips loading the current crate related environment variables
skip_crate_env_info = true

# -----------------------------------------------------------------------------
# Installation

[tasks.i]
alias = "install"

[tasks.id]
alias = "install-dev"

[tasks.ia]
category = "Install"
dependencies = ["install", "install-dev"]

[tasks.install]
description = "Install dependencies for deploying this service."
category = "Install"
dependencies = ["install-shuttle"]

[tasks.install-dev]
description = "Install dependencies for deploying this service, and develper tooling."
category = "Install"
dependencies = ["install", "install-linkcheck", "install-formatter", "install-watch"]

[tasks.install-shuttle]
description = "Install shuttle."
category = "Install"
script = '''
if ! $(echo "type cargo-shuttle" | sh > /dev/null ); then
echo "🚀 Installing https://shuttle.rs ..."
cargo install --locked cargo-shuttle
fi
echo "💽 Shuttle installed."
'''

[tasks.install-linkcheck]
description = "Install markup link checker (mlc)."
category = "Install"
script = '''
if ! $(echo "type mlc" | sh > /dev/null ); then
echo "🕵 Installing link checker (mlc)..."
cargo install --locked mlc
fi
echo "💽 mlc installed."
'''

[tasks.install-formatter]
description = "Install formatter (dprint)."
category = "Install"
script = '''
if ! $(echo "type dprint" | sh > /dev/null ); then
echo "🕵 Installing formatter (dprint)..."
cargo install --locked dprint
fi
echo "💽 dprint installed."
'''

[tasks.install-watch]
description = "Install watching mode for cargo (cargo-watch)."
category = "Install"
script = '''
if ! $(echo "type dprint" | sh > /dev/null ); then
echo "🕵 Installing cargo watch ..."
cargo install --locked cargo-watch
fi
echo "💽 cargo watch installed."
'''

# -----------------------------------------------------------------------------
# Serving

[tasks.s]
alias = "serve"

[tasks.serve]
description = "Start a local server, not rebuilding on changes"
category = "Serve"
script = "cargo run --features local"

# -----------------------------------------------------------------------------
# Shuttle

[tasks.sd]
alias = "shuttle-dev"

[tasks.shuttle-dev]
description = "Start a local shuttle server"
category = "Shuttle"
script = "cargo shuttle run"

[tasks.deploy]
description = "Deploy to Shuttle (NOTE: you need to be the owner of the project in Shuttle.toml!)"
category = "Shuttle"
script = "cargo shuttle deploy"

# -----------------------------------------------------------------------------
# Dev tools for style, convention, and formatting

[tasks.dev]
alias = "develop"

[tasks.develop]
description = "Start a local server, watching for all changes"
category = "Develop"
script = "cargo watch -x 'run --features local'"

[tasks.clean]
description = "Clean the build files"
category = "Clean"
script = "cargo clean"

[tasks.l]
alias = "all-links"

[tasks.all-links]
category = "Checks"
description = "Check included links for all markup (.md|.html) files."
script = "mlc static"

[tasks.links-for]
category = "Checks"
description = "Check links for specific file(s). Example: `makers links-for ./content/contribute/**/*.md`"
script = "mlc ${@}"

[tasks.f]
alias = "fmt"

[tasks.fmt]
category = "Format"
description = "Format everything."
script = "dprint fmt"

[tasks.catch-error]
description = "Check and hint at solutions to common errors."
category = "Tools"
script = '''
if ! $(echo "type cargo-shuttle" | sh > /dev/null ); then
echo -e "❌ You may need to install the tooling. Run:\n\nmakers install\n"
exit 127
fi

if ! $(echo "type cargo-watch" | sh > /dev/null ); then
echo -e "❌ You may need to install the dev tooling. Run:\n\nmakers install-dev\n"
exit 127
fi

if ! $(echo "type mlc" | sh > /dev/null ); then
echo -e "❌ You may need to install the dev tooling. Run:\n\nmakers install-dev\n"
exit 127
fi

if ! $(echo "type dprint" | sh > /dev/null ); then
echo -e "❌ You may need to install the dev tooling. Run:\n\nmakers install-dev\n"
exit 127
fi

echo "✅ Instalation of all dependencies seems OK."
'''
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,31 @@

> HEAVY WIP

See the [github project](https://github.com/orgs/Cryptorado-Community/projects/1/views/1) for infomration on what we are up to.
See the [github project](https://github.com/orgs/Cryptorado-Community/projects/1) for infomration on what we are up to.

## Development

Installation is made easy with [cargo make](https://sagiegurari.github.io/cargo-make/) - install that utility first, then see the commands via:

```sh
# Install
cargo install cargo-make

# Show all make tasks
makers --list-all-steps
```

Run locally with:

```sh
# With Make
makers s

# With shuttle installed
cargo shuttle run

# Without shuttle at all
cargo run --features local
```

## Deployment
Expand Down
1 change: 1 addition & 0 deletions Shuttle.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
name = "cryptorado"
29 changes: 29 additions & 0 deletions src/bin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#[cfg(feature = "local")]
use std::net::SocketAddr;

#[cfg(feature = "local")]
use anyhow::Result;

/// Local main entrypoint.
///
/// See also `axum` - these will need to be manuall kept doing the same thing it seems 😭.
#[cfg(feature = "local")]
#[tokio::main]
async fn main() -> Result<()> {
println!("Serving at: http://127.0.0.1:8000");
let router = cryptorado_rs::get_router();
let addr = SocketAddr::from(([127, 0, 0, 1], 8000));
axum::Server::bind(&addr)
.serve(router.into_make_service())
.await?;
Ok(())
}

/// The main function for running this the shuttle service.
///
/// See also `main` - these will need to be manuall kept doing the same thing it seems 😭.
#[cfg(not(feature = "local"))]
#[shuttle_runtime::main]
async fn axum() -> shuttle_axum::ShuttleAxum {
Ok(cryptorado_rs::get_router().into())
}
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use axum::Router;
use tower_http::services::ServeDir;

/// Get the service router
pub fn get_router() -> Router {
Router::new().nest_service("/", ServeDir::new("static"))
}
10 changes: 0 additions & 10 deletions src/main.rs

This file was deleted.