init
This commit is contained in:
22
dollhouse/docker/Dockerfile.base
Executable file
22
dollhouse/docker/Dockerfile.base
Executable file
@@ -0,0 +1,22 @@
|
||||
FROM lukemathwalker/cargo-chef:latest-rust-1.91.1-slim-trixie AS chef
|
||||
WORKDIR /app
|
||||
|
||||
FROM chef AS planner
|
||||
COPY Cargo.toml Cargo.lock ./
|
||||
COPY crates/ ./crates/
|
||||
RUN cargo chef prepare --recipe-path recipe.json
|
||||
|
||||
FROM chef AS dependencies
|
||||
COPY --from=planner /app/recipe.json recipe.json
|
||||
|
||||
RUN apt-get update && apt-get install -y \
|
||||
pkg-config \
|
||||
libpq-dev \
|
||||
liblua5.3-dev \
|
||||
lua5.3 \
|
||||
wget \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN cargo chef cook --release --recipe-path recipe.json
|
||||
|
||||
FROM dependencies AS base
|
||||
24
dollhouse/docker/dollhouse-backend/Dockerfile
Executable file
24
dollhouse/docker/dollhouse-backend/Dockerfile
Executable file
@@ -0,0 +1,24 @@
|
||||
FROM dollhouse-base:latest AS backend-builder
|
||||
|
||||
RUN cargo install diesel_cli --no-default-features --features postgres
|
||||
|
||||
COPY . .
|
||||
RUN cargo build --release --bin dollhouse-backend
|
||||
|
||||
FROM ubuntu:24.04 AS runtime
|
||||
WORKDIR /app
|
||||
|
||||
COPY docker/dollhouse-backend/entrypoint.sh .
|
||||
COPY --from=backend-builder /app/target/release/dollhouse-backend /usr/local/bin/backend
|
||||
COPY --from=backend-builder /usr/local/cargo/bin/diesel ./diesel
|
||||
COPY crates/dollhouse-db/migrations ./migrations
|
||||
COPY crates/dollhouse-db/diesel.toml .
|
||||
|
||||
RUN apt-get update && apt install -y \
|
||||
libpq-dev \
|
||||
liblua5.3-dev \
|
||||
lua5.3 && \
|
||||
rm -rf /var/lib/apt/lists/* \
|
||||
&& chmod +x ./entrypoint.sh
|
||||
|
||||
ENTRYPOINT [ "./entrypoint.sh" ]
|
||||
6
dollhouse/docker/dollhouse-backend/entrypoint.sh
Executable file
6
dollhouse/docker/dollhouse-backend/entrypoint.sh
Executable file
@@ -0,0 +1,6 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -x
|
||||
|
||||
./diesel setup || exit 1
|
||||
exec /usr/local/bin/backend
|
||||
8
dollhouse/docker/dollhouse-cleaner/Dockerfile
Executable file
8
dollhouse/docker/dollhouse-cleaner/Dockerfile
Executable file
@@ -0,0 +1,8 @@
|
||||
FROM alpine:latest
|
||||
|
||||
RUN apk add --no-cache postgresql-client bash
|
||||
|
||||
COPY cleaner.sh /cleaner.sh
|
||||
RUN chmod +x /cleaner.sh
|
||||
|
||||
ENTRYPOINT ["/cleaner.sh"]
|
||||
29
dollhouse/docker/dollhouse-cleaner/cleaner.sh
Executable file
29
dollhouse/docker/dollhouse-cleaner/cleaner.sh
Executable file
@@ -0,0 +1,29 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
DIR="/firmware"
|
||||
|
||||
while true; do
|
||||
TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')
|
||||
echo "[$TIMESTAMP] Starting cleanup"
|
||||
|
||||
if [ -d "${DIR}" ]; then
|
||||
find "${DIR}" -type f -mmin +5 -delete 2>/dev/null
|
||||
fi
|
||||
|
||||
if [ -n "${DATABASE_URL}" ]; then
|
||||
psql "${DATABASE_URL}" -v "ON_ERROR_STOP=1" <<'SQL'
|
||||
BEGIN;
|
||||
DELETE FROM replicants_stats WHERE created_at <= NOW() - INTERVAL '5 minutes';
|
||||
DELETE FROM replicants WHERE created_at <= NOW() - INTERVAL '5 minutes';
|
||||
DELETE FROM users WHERE created_at <= NOW() - INTERVAL '5 minutes';
|
||||
DELETE FROM corps WHERE created_at <= NOW() - INTERVAL '5 minutes';
|
||||
COMMIT;
|
||||
SQL
|
||||
else
|
||||
echo " DATABASE_URL not set, skipping DB cleanup"
|
||||
fi
|
||||
|
||||
echo "[$TIMESTAMP] Cleanup completed"
|
||||
sleep 60
|
||||
done
|
||||
19
dollhouse/docker/dollhouse-frontend/Dockerfile
Executable file
19
dollhouse/docker/dollhouse-frontend/Dockerfile
Executable file
@@ -0,0 +1,19 @@
|
||||
FROM dollhouse-base:latest AS frontend-builder
|
||||
|
||||
RUN wget https://github.com/trunk-rs/trunk/releases/download/v0.21.14/trunk-x86_64-unknown-linux-gnu.tar.gz && \
|
||||
tar -xvf trunk-x86_64-unknown-linux-gnu.tar.gz && \
|
||||
mv trunk /usr/local/bin/ && \
|
||||
rm trunk-x86_64-unknown-linux-gnu.tar.gz
|
||||
|
||||
RUN rustup target add wasm32-unknown-unknown
|
||||
|
||||
COPY . .
|
||||
RUN cd crates/dollhouse-frontend && trunk build --release --no-sri
|
||||
|
||||
FROM nginx:1.24-alpine AS runtime
|
||||
COPY --from=frontend-builder /app/crates/dollhouse-frontend/dist /usr/share/nginx/html
|
||||
COPY docker/dollhouse-frontend/nginx.conf /etc/nginx/nginx.conf
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
53
dollhouse/docker/dollhouse-frontend/nginx.conf
Executable file
53
dollhouse/docker/dollhouse-frontend/nginx.conf
Executable file
@@ -0,0 +1,53 @@
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
http {
|
||||
include mime.types;
|
||||
default_type application/octet-stream;
|
||||
|
||||
server {
|
||||
listen 3000;
|
||||
server_name localhost;
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
|
||||
location /api/ {
|
||||
proxy_pass http://backend:5555/api/;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
|
||||
# CORS headers
|
||||
add_header Access-Control-Allow-Origin "*" always;
|
||||
add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS" always;
|
||||
add_header Access-Control-Allow-Headers "Authorization, Content-Type, Accept" always;
|
||||
add_header Access-Control-Allow-Credentials "true" always;
|
||||
|
||||
# Handle preflight
|
||||
if ($request_method = OPTIONS) {
|
||||
return 204;
|
||||
}
|
||||
}
|
||||
|
||||
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
||||
expires 1y;
|
||||
add_header Cache-Control "public, immutable";
|
||||
try_files $uri =404;
|
||||
}
|
||||
|
||||
location ~* \.(wasm)$ {
|
||||
add_header Content-Type application/wasm;
|
||||
default_type application/wasm;
|
||||
expires max;
|
||||
add_header Cache-Control "public, immutable";
|
||||
try_files $uri =404;
|
||||
}
|
||||
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user