Stash commit

This commit is contained in:
Sivert V. Sæther 2024-11-07 14:19:09 +01:00
parent 4991467d32
commit 441e071074
10 changed files with 105 additions and 15 deletions

4
.dockerignore Normal file
View File

@ -0,0 +1,4 @@
**/Dockerfile
**/target
**/dist
nginx*

27
Dockerfile Normal file
View File

@ -0,0 +1,27 @@
FROM rust:slim AS build
RUN rustup default nightly
RUN rustup target add wasm32-unknown-unknown
RUN cargo install cargo-watch trunk
RUN apt update && apt install -y\
pkg-config librust-openssl-dev
ADD ./ /
WORKDIR /backend
RUN cargo build --release
WORKDIR /frontend
RUN trunk build --release
FROM nginx:latest
COPY --from=build /target/release/oracle /bin
COPY --from=build /frontend/dist /srv/www
ADD init.sh /bin/init.sh
ENV WEB_WORKERS=4
EXPOSE 80
CMD [ "init.sh" ]

View File

@ -1,6 +1,6 @@
[default] [default]
address = "0.0.0.0" address = "0.0.0.0"
port = 80 port = 8080
ip_header = "X-Real-IP" ip_header = "X-Real-IP"
log_level = "normal" log_level = "normal"

4
frontend/Trunk.toml Normal file
View File

@ -0,0 +1,4 @@
[build]
minify = "on_release"
[clean]
cargo = true

View File

@ -1,4 +1,4 @@
pub mod models; pub mod models;
pub static BASE: &'static str = env!("BASE"); pub static BASE: &'static str = "/api";

View File

@ -45,7 +45,7 @@ impl Component for Chat {
</div> </div>
<form class="chat"> <form class="chat">
<div> <div>
<input type="textfield" required=true /> <textarea type="textfield" autofocus=true required=true />
</div> </div>
<div> <div>
<button onclick={ <button onclick={

View File

@ -8,7 +8,7 @@ use allpaca::log;
#[function_component] #[function_component]
fn App() -> Html { fn App() -> Html {
html! { html! {
<> <center>
<div class="navbar"> <div class="navbar">
<nav::Bar></nav::Bar> <nav::Bar></nav::Bar>
</div> </div>
@ -17,7 +17,7 @@ fn App() -> Html {
<div> <div>
<Fetcher></Fetcher> <Fetcher></Fetcher>
</div> </div>
</> </center>
} }
} }

View File

@ -3,10 +3,20 @@ body {
color: lime; color: lime;
} }
.navbar, .model-list { ul {
list-style: none; list-style: none;
} }
.model-list > li { .model-list > li {
margin: 1vh; margin: 1vh;
} }
.chat textarea {
resize: none;
width: 69vw;
height: 3vh;
}
.chat {
align-content: center;
}

45
init.sh Executable file
View File

@ -0,0 +1,45 @@
#!/bin/sh
echo "error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
worker_processes $WEB_WORKERS;
user nginx;
events {
worker_connections 1024;
}
http {
log_format main '\$remote_addr - \$remote_user [\$time_local] "\$request" \$status \$body_bytes_sent "\$http_referer" "\$http_user_agent" "\$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
default_type application/octet-stream;
include /etc/nginx/mime.types;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
gzip on;
server {
listen 80;
location / {
index index.html;
root /srv/www;
}
location /api {
rewrite /api/?(.*) /\$1 break;
proxy_set_header X-Real-IP \$remote_addr;
proxy_pass http://localhost:8080;
}
}
}
" > /etc/nginx/nginx.conf
echo "[default]
ip_header = \"X-Real-IP\"
log_level = \"normal\"
workers = $WEB_WORKERS
address = \"0.0.0.0\"
port = 8080
" > /Rocket.toml
oracle &
nginx -g "daemon off;"

View File

@ -35,7 +35,7 @@ http {
location /api { location /api {
rewrite /api/?(.*) /$1 break; rewrite /api/?(.*) /$1 break;
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://backend:80; proxy_pass http://backend:8080;
} }
} }
} }