Failing to deploy even though its fine locally
# help
g
I want to preface this with the fact that I am both relatively new to Rust and that this is my first time using shuttle so the issue is likely to be something dumb I missed. With that said. You can see the logs here https://pastebin.com/raw/gRLD8zZs, I cant really tell whats wrong from reading them. I can share the source code (not public yet) in case that helps later. I saw somewhere that you can use
Secrets.toml
and
Secrets.dev.toml
which I did use to change which sql schema file I use (the dev one clears the tables, other than that they are the same). I'm not sure if I should do something special to read in the contents of the file:
Copy code
rs
  let schema = secret_store
    .get("SCHEMA")
    .expect("SCHEMA secret not found.");
  let schema = read_to_string(schema).expect("SCHEMA is read correctly.");
I feel like this should be fine (again, works fine locally and none of the expect error messages are appearing in the logs so idk) but including it anyway. I dont really have any other ideas as to what might be causing this. Im using Axum. In case this matters, my
dashboard
page appears to be empty still
e
Mmm.... you're probably running into the fact that Shuttle doesn't necessarily keep the exact file structure in the repo you're working on. At compile time the repo structure is intact, but not necessarily at runtime. Generally just the compiled assets are available, plus Known files like
Secrets.toml
. You may want to look into the static folder functionality (https://docs.shuttle.rs/resources/shuttle-static-folder) that Shuttle does know about for this kind of use case? Alternatively I'd suggest perhaps using compiler attributes like
#[cfg(debug_assertions)]
(memory's hazy on the exact syntax, but that's close I think?) to swap out the ones you want based on whether it's compiled locally in debug mode, or in release mode.
Personally my solution has been a bit of a kludge, but I essentially just ditched the clearing of data locally and opted to do that manually if I need to do that, and have my schema constructed with things like
CREATE TABLE IF NOT EXISTS ...
g
I see. Do you know if the stuff from Secrets.toml are available as normal environment variables during compile time? If thats the case I could also import the sql file with include_str!
e
I've not seen anything to that effect in documentation nor examples, so I would assume likely not.
g
Makes sense, thanks for the help! Curious as to why the file structure is different, any idea?
e
I'm sure it's probably just Shuttle trying to minimise how much storage space is really required for each container to run or something, but the shuttle folks could probably give a more comprehensive answer
one thing perhaps you could try is just have it default to the production thing and then if an environment var is set at compile time, then swap that out for whatever that's set to, maybe? 🤔
that way it'll compile fine in Shuttle and locally you can do whatever you need as well
g
That could also work yeah, looking into the static folder stuff right now as that probably doesnt need me to change too much
Hm, its still not working https://pastebin.com/raw/3M0p0cmW I created an
sql
folder and put the files in there
Copy code
rs
#[shuttle_runtime::main]
async fn axum(
  #[shuttle_shared_db::Postgres] pool: PgPool,
  #[shuttle_secrets::Secrets] secret_store: SecretStore,
  #[shuttle_static_folder::StaticFolder(folder = "sql")] static_folder: PathBuf,
) -> shuttle_axum::ShuttleAxum {
  let schema = secret_store
    .get("SCHEMA")
    .expect("SCHEMA secret not found.");
  let schema =
    read_to_string(static_folder.as_path().join(schema)).expect("SCHEMA is read correctly.");

  // ...
}
I feel like this should preserve the files, maybe something else is wrong? (this again works locally)
e
is that pastebin the full log? is anything further shown if you manually query
cargo shuttle logs <id>
with the last deployment id?
g
nope thats it
i can restart and try again tho
¯\_(ツ)_/¯
e
and you're sure your schema file is valid?
The only similar state I've reached is with a schema with syntax errors tbh
g
well its the same between both sql files except for the drop so probably?
Copy code
sql
-- schema.dev.sql
DROP TABLE IF EXISTS metadata;
DROP TABLE IF EXISTS urls;

CREATE TABLE urls (
  id VARCHAR(6) PRIMARY KEY,
  url VARCHAR NOT NULL
);

CREATE TABLE metadata (
  id VARCHAR(6) REFERENCES urls(id),
  url VARCHAR NOT NULL,
  hits INT NOT NULL
);


-- schema.sql

CREATE TABLE urls (
  id VARCHAR(6) PRIMARY KEY,
  url VARCHAR NOT NULL
);

CREATE TABLE metadata (
  id VARCHAR(6) REFERENCES urls(id),
  url VARCHAR NOT NULL,
  hits INT NOT NULL
);
I think ill just publish the repo and post it here in case anyone can figure it out because I am lost xd
e
yeah, seems fine to me 🤔
g
e
ah, hm. I wonder if the
panic
is not getting caught by the logging infra, then
g
o
should i just println or?
or I can use tracing it seems like
e
tracing might be a way to go... is
ShuttleAxum
a result type? it is for the serenity wrapper at least, so I do stuff like... https://github.com/vexx32/thread-tracker/blob/main/src/main.rs#L274C11-L279
I think you might be able to do similar
those at least do get logged pretty consistently in my experience
g
that was indeed the issue 🗿
ok my dashboard is still empty, cant u see anything on the website?
e
dashboard doesn't show anything atm, it's all CLI for now till they get some more frontend bits and pieces put in
g
Works fine now, thanks a lot!
e
awesome! np :3
g
One last thing, how do you usually interact with your db directly?
e
if I need to, I'll login with pgAdmin (probably any postgres-compatible db admin tool will work) -- once the service is started after a
cargo shuttle deploy
it'll give you a connection string for the DB that looks like this:
Copy code
postgres://user-PROJECT-NAME:DB-PASSWORD@db.shuttle.rs:5432/db-PROJECT-NAME
take the
user-PROJECT-NAME
as the username, the
DB-PASSWORD
as the password, and give it to pgAdmin like this:

https://cdn.discordapp.com/attachments/1102289940835995748/1102306254405246976/image.pngâ–¾

I can't remember if it just prompts you for the password or if there's a field for it when initially setting up, but if so enter the password there too
do note the password rotates... either every
deploy
or if you do a
project restart
, I forget which. probably every deploy?
so if your password stops working, check the
cargo shuttle resource list
for the most recent connection string + password
when you login you can see other DBs in the server, but you won't be able to access anything in any of them other than the database you've setup in your project, so you'll have to scroll through to find your specific one, it'll be called
db-PROJECT-NAME
just like in the connection string
I'm sure it's also possible to use other methods that work with a PG database, but that's the way I've been doing it
g
thanks :)
e
np ^^