added deployment via docker compose
This commit is contained in:
@@ -0,0 +1,4 @@
|
|||||||
|
*/target
|
||||||
|
*.env
|
||||||
|
*.log*
|
||||||
|
*.lock
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
DATABASE_URL="postgresql://chatapp:chatapp@100.118.108.58:5432/chatapp"
|
DATABASE_URL="postgresql://chatapp:chatapp@100.118.108.58:5432/chatapp"
|
||||||
|
ROCKET_SECRET_KEY="fCHCI6x/uItqldCJTdbruqQvXQXAeH/+vGtXmu3Hv6A="
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
/target
|
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
FROM docker.io/rust:1-slim-bookworm AS build
|
||||||
|
|
||||||
|
## cargo package name: customize here or provide via --build-arg
|
||||||
|
ARG pkg=backend
|
||||||
|
ARG DATABASE_URL
|
||||||
|
|
||||||
|
WORKDIR /build
|
||||||
|
|
||||||
|
COPY .cargo .cargo
|
||||||
|
COPY cdn cdn
|
||||||
|
COPY src src
|
||||||
|
COPY Cargo.toml Cargo.toml
|
||||||
|
COPY Rocket.toml Rocket.toml
|
||||||
|
COPY static static
|
||||||
|
COPY templates templates
|
||||||
|
|
||||||
|
RUN apt-get update && apt-get install -y libssl-dev pkg-config
|
||||||
|
|
||||||
|
RUN --mount=type=cache,target=/build/target \
|
||||||
|
--mount=type=cache,target=/usr/local/cargo/registry \
|
||||||
|
--mount=type=cache,target=/usr/local/cargo/git \
|
||||||
|
set -eux; \
|
||||||
|
cargo build --release; \
|
||||||
|
objcopy --compress-debug-sections target/release/$pkg ./main
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
FROM docker.io/debian:bookworm-slim
|
||||||
|
|
||||||
|
RUN apt-get update && apt-get install -y libssl-dev pkg-config
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
## copy the main binary
|
||||||
|
COPY --from=build /build/main ./
|
||||||
|
|
||||||
|
## copy runtime assets which may or may not exist
|
||||||
|
COPY --from=build /build/Rocket.toml ./Rocket.toml
|
||||||
|
COPY --from=build /build/static ./static
|
||||||
|
COPY --from=build /build/cdn ./cdn
|
||||||
|
COPY --from=build /build/template[s] ./templates
|
||||||
|
|
||||||
|
## ensure the container listens globally on port 8000
|
||||||
|
ENV ROCKET_ADDRESS=0.0.0.0
|
||||||
|
ENV ROCKET_PORT=8000
|
||||||
|
|
||||||
|
CMD ./main
|
||||||
@@ -1,6 +1,12 @@
|
|||||||
[debug]
|
[debug]
|
||||||
secret_key = "yYhvCGnRh/TrcHtB8sZqCFifrVmJxoKFLBYw/WWBZeU="
|
secret_key = "yYhvCGnRh/TrcHtB8sZqCFifrVmJxoKFLBYw/WWBZeU="
|
||||||
|
address = "127.0.0.1"
|
||||||
port = 8000
|
port = 8000
|
||||||
|
|
||||||
[default.databases.postgres_db]
|
[default.databases.postgres_db]
|
||||||
url = "postgresql://chatapp:chatapp@100.118.108.58:5432/chatapp"
|
url = "postgresql://chatapp:chatapp@100.118.108.58:5432/chatapp"
|
||||||
|
|
||||||
|
[default] # run inside a docker container or pod
|
||||||
|
secret_key = "fCHCI6x/uItqldCJTdbruqQvXQXAeH/+vGtXmu3Hv6A="
|
||||||
|
address = "0.0.0.0"
|
||||||
|
port = 8082
|
||||||
|
|||||||
+1
-1
@@ -99,7 +99,7 @@ pub async fn mfa_page(session: Session) -> Template {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[get("/api/totp.jpg")]
|
#[get("/api/totp.jpg")]
|
||||||
pub async fn gen_totp(s: Session) -> Option<QrCodeImage> {
|
pub async fn get_totp(s: Session) -> Option<QrCodeImage> {
|
||||||
let totp = TOTP::new(
|
let totp = TOTP::new(
|
||||||
Algorithm::SHA1,
|
Algorithm::SHA1,
|
||||||
6,
|
6,
|
||||||
|
|||||||
+19
-6
@@ -2,7 +2,7 @@
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate rocket;
|
extern crate rocket;
|
||||||
|
|
||||||
use rocket::fs::FileServer;
|
use rocket::fs::{FileServer, NamedFile};
|
||||||
use rocket::http::Method;
|
use rocket::http::Method;
|
||||||
use rocket::serde::json::Json;
|
use rocket::serde::json::Json;
|
||||||
use rocket::{Build, Rocket};
|
use rocket::{Build, Rocket};
|
||||||
@@ -66,16 +66,29 @@ fn rocket() -> Rocket<Build> {
|
|||||||
.mount(
|
.mount(
|
||||||
"/",
|
"/",
|
||||||
routes![
|
routes![
|
||||||
users,
|
favicon,
|
||||||
username_for_id,
|
|
||||||
messages::chat_page,
|
messages::chat_page,
|
||||||
|
auth::signup_page,
|
||||||
|
auth::login_page,
|
||||||
|
auth::mfa_page,
|
||||||
|
],
|
||||||
|
)
|
||||||
|
.mount(
|
||||||
|
"/api",
|
||||||
|
routes![
|
||||||
messages::get_messages,
|
messages::get_messages,
|
||||||
messages::post_message,
|
messages::post_message,
|
||||||
messages::event_stream,
|
messages::event_stream,
|
||||||
|
users,
|
||||||
|
username_for_id,
|
||||||
auth::signup,
|
auth::signup,
|
||||||
auth::signup_page,
|
auth::login,
|
||||||
auth::login_page,
|
auth::get_totp,
|
||||||
auth::login
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[get("/favicon.ico")]
|
||||||
|
async fn favicon() -> NamedFile {
|
||||||
|
NamedFile::open("static/favicon.ico").await.unwrap()
|
||||||
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ body {
|
|||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
height: 100vh;
|
height: 100vh;
|
||||||
max-width: 100vw;
|
min-width: 100vw;
|
||||||
margin: 0 0;
|
margin: 0 0;
|
||||||
background: #121212;
|
background: #121212;
|
||||||
position: relative;
|
position: relative;
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
@@ -165,7 +165,7 @@
|
|||||||
function sendMessage() {
|
function sendMessage() {
|
||||||
const message = input.value.trim();
|
const message = input.value.trim();
|
||||||
if (message) {
|
if (message) {
|
||||||
fetch("http://localhost:8000/chat", {
|
fetch("/api/chat", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
user_id: user_id,
|
user_id: user_id,
|
||||||
@@ -189,11 +189,11 @@
|
|||||||
|
|
||||||
async function loadData() {
|
async function loadData() {
|
||||||
try {
|
try {
|
||||||
const userIds = await fetch("http://localhost:8000/users/")
|
const userIds = await fetch("/api/users/")
|
||||||
.then(r => r.json());
|
.then(r => r.json());
|
||||||
|
|
||||||
const userPromises = userIds.map(userId =>
|
const userPromises = userIds.map(userId =>
|
||||||
fetch(`http://localhost:8000/users/${userId}`)
|
fetch(`/api/users/${userId}`)
|
||||||
.then(r => r.text())
|
.then(r => r.text())
|
||||||
.then(username => ({ userId, username }))
|
.then(username => ({ userId, username }))
|
||||||
);
|
);
|
||||||
@@ -206,7 +206,8 @@
|
|||||||
|
|
||||||
console.log('Users loaded:', users);
|
console.log('Users loaded:', users);
|
||||||
|
|
||||||
const messageSource = new EventSource("http://localhost:8000/events");
|
const messageSource = new EventSource("/api/events");
|
||||||
|
messageSource.onopen = () => messagesContainer.innerHTML = '';
|
||||||
messageSource.onmessage = (event) => insertMessage(JSON.parse(event.data));
|
messageSource.onmessage = (event) => insertMessage(JSON.parse(event.data));
|
||||||
messageSource.onerror = (error) => {
|
messageSource.onerror = (error) => {
|
||||||
console.error('EventSource error:', error);
|
console.error('EventSource error:', error);
|
||||||
|
|||||||
@@ -109,7 +109,7 @@
|
|||||||
try {
|
try {
|
||||||
// Replace with your actual backend endpoint
|
// Replace with your actual backend endpoint
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
"http://localhost:8000/login",
|
"/api/login",
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
|
|||||||
@@ -225,7 +225,7 @@
|
|||||||
try {
|
try {
|
||||||
// Replace with your actual backend endpoint
|
// Replace with your actual backend endpoint
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
"http://localhost:8000/signup",
|
"/api/signup",
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
services:
|
||||||
|
backend:
|
||||||
|
image: git.zxq5.dev/zxq5/chatapp-backend:latest
|
||||||
|
ports:
|
||||||
|
- "8000:8000"
|
||||||
|
depends_on:
|
||||||
|
- redis
|
||||||
|
environment:
|
||||||
|
- ROCKET_SECRET_KEY=$ROCKET_SECRET_KEY
|
||||||
|
- DATABASE_URL="postgresql://chatapp:chatapp@100.118.108.58:5432/chatapp"
|
||||||
|
redis:
|
||||||
|
image: docker.io/library/redis:alpine
|
||||||
|
ports:
|
||||||
|
- "6379:6379"
|
||||||
Reference in New Issue
Block a user