mirror of
https://github.com/eliasrenman/url-shortener.git
synced 2026-03-16 20:16:06 +01:00
feat: docker file
This commit is contained in:
14
.dockerignore
Normal file
14
.dockerignore
Normal file
@@ -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
|
||||||
31
Dockerfile
Normal file
31
Dockerfile
Normal file
@@ -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" ]
|
||||||
25
readme.md
Normal file
25
readme.md
Normal file
@@ -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
|
||||||
|
```
|
||||||
@@ -21,15 +21,16 @@ impl From<EmailUserInfo> for User {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[allow(dead_code)]
|
||||||
#[get("/login/email")]
|
#[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
|
// Create magic link
|
||||||
// Send email containing magic link
|
// Send email containing magic link
|
||||||
(Status::Ok, "Email link sent")
|
(Status::Ok, "Email link sent")
|
||||||
}
|
}
|
||||||
|
#[allow(dead_code)]
|
||||||
#[get("/auth/email")]
|
#[get("/auth/email")]
|
||||||
async fn email_callback(cookies: &CookieJar<'_>) -> Result<Redirect, Debug<Error>> {
|
async fn email_callback(_cookies: &CookieJar<'_>) -> Result<Redirect, Debug<Error>> {
|
||||||
// Validate magic link
|
// Validate magic link
|
||||||
// create token
|
// create token
|
||||||
// Set a cookie with the user's name, and redirect to the home page.
|
// 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<Redirect, Debug<Error
|
|||||||
// );
|
// );
|
||||||
Ok(Redirect::to("/"))
|
Ok(Redirect::to("/"))
|
||||||
}
|
}
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn email_fairing() -> impl Fairing {
|
pub fn email_fairing() -> impl Fairing {
|
||||||
AdHoc::on_ignite("Email Auth", |rocket| async {
|
AdHoc::on_ignite("Email Auth", |rocket| async {
|
||||||
rocket.mount("/api", rocket::routes![email_login, email_callback])
|
rocket.mount("/api", rocket::routes![email_login, email_callback])
|
||||||
|
|||||||
@@ -39,11 +39,12 @@ impl From<GoogleUserInfo> for User {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[allow(dead_code)]
|
||||||
#[get("/login/google")]
|
#[get("/login/google")]
|
||||||
fn google_login(oauth2: OAuth2<GoogleUserInfo>, cookies: &CookieJar<'_>) -> Redirect {
|
fn google_login(oauth2: OAuth2<GoogleUserInfo>, cookies: &CookieJar<'_>) -> Redirect {
|
||||||
oauth2.get_redirect(cookies, &["profile"]).unwrap()
|
oauth2.get_redirect(cookies, &["profile"]).unwrap()
|
||||||
}
|
}
|
||||||
|
#[allow(dead_code)]
|
||||||
#[get("/auth/google")]
|
#[get("/auth/google")]
|
||||||
async fn google_callback(
|
async fn google_callback(
|
||||||
token: TokenResponse<GoogleUserInfo>,
|
token: TokenResponse<GoogleUserInfo>,
|
||||||
@@ -71,6 +72,7 @@ async fn google_callback(
|
|||||||
|
|
||||||
Ok(Redirect::to("/"))
|
Ok(Redirect::to("/"))
|
||||||
}
|
}
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn google_fairing() -> impl Fairing {
|
pub fn google_fairing() -> impl Fairing {
|
||||||
AdHoc::on_ignite("Google OAuth2", |rocket| async {
|
AdHoc::on_ignite("Google OAuth2", |rocket| async {
|
||||||
rocket
|
rocket
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
use chrono::{DateTime, Utc};
|
|
||||||
use rocket::{http::Status, response::Redirect};
|
use rocket::{http::Status, response::Redirect};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
|||||||
Reference in New Issue
Block a user