diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..27d1ae3 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,14 @@ +# Ignore the .git directory +.git/ + +# Ignore node_modules directory +node_modules/ + +# Ignore all .log files +*.log + +# Ignore temporary files +tmp/ + +Rocket.toml +.env diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c88e022 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,31 @@ +# Stage 1: Build the frontend assets using Bun +FROM oven/bun:1-alpine AS bun-builder + +# Set the working directory +WORKDIR /app/web + +# Copy the frontend source code +COPY ./web ./ + +# Install dependencies and build the frontend +RUN bun install --frozen-lockfile && bun run build + +# Build binaries +FROM rust:slim + +RUN apt update && \ + apt install -y libsqlite3-dev +COPY --from=bun-builder /app/web/dist ./web/dist + +WORKDIR /app + +COPY . . + +RUN cargo build --release + +ENV ROCKET_ADDRESS=0.0.0.0 +ENV ROCKET_PORT=8000 + +EXPOSE 8000 + +CMD [ "cargo", "run", "--release" ] diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..e292925 --- /dev/null +++ b/readme.md @@ -0,0 +1,25 @@ +## Running + +### Docker +To run this in docker please run: + +```Bash +docker build -t url-shortener . +``` +Copy and fill out a Rocket.toml from the Rocket.toml.example + +Generate a secret for rocket +```Bash +openssl rand -base64 32 +``` +Start docker container with: +```bash +docker run -p 8000:8000 \ + -e DATABASE_URL=/app/sqlite.db \ + -e BASE_URL=https://url.renman.dev \ + -e JWT_SECRET=secret \ + -e ROCKET_SECRET_KEY={OUTPUT_OF_PREVIOUS_STEP} \ + -v $(pwd)/sqlite.db:/app/sqlite.db \ + -v $(pwd)/Rocket.toml:/app/Rocket.toml \ + url-shortener +``` diff --git a/src/auth/email.rs b/src/auth/email.rs index e915934..d87d6fc 100644 --- a/src/auth/email.rs +++ b/src/auth/email.rs @@ -21,15 +21,16 @@ impl From for User { } } } +#[allow(dead_code)] #[get("/login/email")] -fn email_login<'a>(cookies: &'a CookieJar<'a>) -> (Status, &'a str) { +fn email_login<'a>(_cookies: &'a CookieJar<'a>) -> (Status, &'a str) { // Create magic link // Send email containing magic link (Status::Ok, "Email link sent") } - +#[allow(dead_code)] #[get("/auth/email")] -async fn email_callback(cookies: &CookieJar<'_>) -> Result> { +async fn email_callback(_cookies: &CookieJar<'_>) -> Result> { // Validate magic link // create token // Set a cookie with the user's name, and redirect to the home page. @@ -40,7 +41,7 @@ async fn email_callback(cookies: &CookieJar<'_>) -> Result impl Fairing { AdHoc::on_ignite("Email Auth", |rocket| async { rocket.mount("/api", rocket::routes![email_login, email_callback]) diff --git a/src/auth/google.rs b/src/auth/google.rs index 6c096e8..b59594d 100644 --- a/src/auth/google.rs +++ b/src/auth/google.rs @@ -39,11 +39,12 @@ impl From for User { } } } +#[allow(dead_code)] #[get("/login/google")] fn google_login(oauth2: OAuth2, cookies: &CookieJar<'_>) -> Redirect { oauth2.get_redirect(cookies, &["profile"]).unwrap() } - +#[allow(dead_code)] #[get("/auth/google")] async fn google_callback( token: TokenResponse, @@ -71,6 +72,7 @@ async fn google_callback( Ok(Redirect::to("/")) } +#[allow(dead_code)] pub fn google_fairing() -> impl Fairing { AdHoc::on_ignite("Google OAuth2", |rocket| async { rocket diff --git a/src/handlers/url.rs b/src/handlers/url.rs index 0eb9a5e..84a0e43 100644 --- a/src/handlers/url.rs +++ b/src/handlers/url.rs @@ -1,4 +1,3 @@ -use chrono::{DateTime, Utc}; use rocket::{http::Status, response::Redirect}; use crate::{