https://linen.dev logo
Deployment Crashed
# help
w
I am trying to create a url shortener project but every time I run
cargo shuttle deploy
I get the following.
Copy code
Packaging url_shortener v0.1.0 (E:\Projects\url_shortener)

2022-12-08T16:38:38.562402603Z  INFO Entering queued state  

2022-12-08T16:38:38.562986385Z  INFO Entering building state

Deployment crashed
Run the following for more details

cargo shuttle logs 856eeb55-acbe-4026-b398-8ad06d15956c
Here are the logs
Copy code
2022-12-08T16:38:38.562402603Z  INFO Entering queued state

2022-12-08T16:38:38.562986385Z  INFO Entering building state

2022-12-08T16:38:38.590681863Z  INFO Entering crashed state
2022-12-08T16:38:38.593112600Z ERROR {error="Build error: failed to read `/opt/shuttle/shuttle-builds/tinyurl/Cargo.toml`"} shuttle_deployer::deployment::queue: service build encountered an error
Here is my code
Cargo.toml
Copy code
toml
[package]
name = "url_shortener"
version = "0.1.0"
edition = "2021"
publish = false

[lib]

[dependencies]
rocket = "0.5.0-rc.2"
shuttle-service = { version = "0.7.2", features = ["web-rocket"] }
shuttle-aws-rds = { version = "0.7.2", features = ["postgres"] }
sqlx = "0.6.2"
url = "2.3.1"
nanoid = "0.4.0"
Schema.sql
Copy code
sql
DROP TABLE IF EXISTS URLS;

CREATE TABLE URLS (
  id TEXT PRIMARY KEY,
  redirect TEXT NOT NULL
);
Shuttle.toml
Copy code
toml
name = "tinyurl"
lib.rs
Copy code
rs
#[macro_use]
extern crate rocket;
use rocket::{http::Status, State};
use shuttle_service::ShuttleRocket;
use sqlx::{Executor, PgPool};
use url::Url;

#[shuttle_service::main]
async fn rocket(#[shuttle_aws_rds::Postgres] pool: PgPool) -> ShuttleRocket {
    pool.execute(include_str!("../Schema.sql"))
        .await
        .map_err(|_| shuttle_service::Error::Database("Failed executing Schema.sql".into()))?;

    let rocket = rocket::build()
        .manage(pool)
        .mount("/urls", routes![post_url]);

    Ok(rocket)
}

#[post("/", data = "<input>")]
async fn post_url(input: String, pool: &State<PgPool>) -> Result<String, Status> {

    let id = nanoid::nanoid!(8);

    let url = Url::parse(&input).map_err(|_| Status::UnprocessableEntity)?;

    sqlx::query("INSERT INTO URLS(id, redirect) VALUES ($1, $2)")
        .bind(&id)
        .bind(url.as_str())
        .execute(&**pool)
        .await
        .map_err(|_| Status::InternalServerError)?;

    Ok(format!("https://tinyurl.shuttle.app/{id}"))
}
k
Hey! Does it run locally? Also, which OS are you on?
w
I am on Windows 10 but I tried on Win 11 and that also didn't work, it runs locally aslong as I remove the
#[shuttle_aws_rds::Postgres] pool: PgPool
argument
I tried again using Github codespaces and it worked, seems to be an issue just on Windows.
k
Oops, sorry, I forgot to reply to this yesterday. Yeah, it seems like a windows issue. I know some users have had success doing a
cargo build
before
cargo shuttle deploy
, you could try that. 🤞
b
do you have docker installed and what toolcahin are you using?