fix: Fix Dockerfile
This commit is contained in:
57
Dockerfile
57
Dockerfile
@@ -1,11 +1,13 @@
|
|||||||
# Build Stage
|
# Build Stage
|
||||||
FROM rust:1.85-bookworm AS builder
|
FROM rust:1.88-bookworm AS builder
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Install sqlite3 for compile-time query checking
|
||||||
|
RUN apt-get update && apt-get install -y sqlite3 && rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# Cache dependencies
|
# Cache dependencies
|
||||||
# We create a dummy project to build only dependencies
|
RUN cargo init --name blog_cms .
|
||||||
RUN cargo new --bin blog_cms
|
|
||||||
COPY Cargo.toml Cargo.lock ./
|
COPY Cargo.toml Cargo.lock ./
|
||||||
RUN cargo build --release
|
RUN cargo build --release
|
||||||
RUN rm src/*.rs
|
RUN rm src/*.rs
|
||||||
@@ -14,8 +16,43 @@ RUN rm src/*.rs
|
|||||||
COPY src ./src
|
COPY src ./src
|
||||||
COPY templates ./templates
|
COPY templates ./templates
|
||||||
|
|
||||||
# The templates are needed during compilation by askama
|
# Create a temporary SQLite DB with the schema for sqlx compile-time checks
|
||||||
# Rebuild the real source
|
RUN sqlite3 /tmp/build.db " \
|
||||||
|
CREATE TABLE users ( \
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT, \
|
||||||
|
username TEXT NOT NULL UNIQUE, \
|
||||||
|
password_hash TEXT NOT NULL, \
|
||||||
|
role TEXT NOT NULL DEFAULT 'readonly' \
|
||||||
|
); \
|
||||||
|
CREATE TABLE sessions ( \
|
||||||
|
id TEXT PRIMARY KEY, \
|
||||||
|
user_id INTEGER NOT NULL, \
|
||||||
|
expires_at INTEGER NOT NULL, \
|
||||||
|
FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE \
|
||||||
|
); \
|
||||||
|
CREATE TABLE posts ( \
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT, \
|
||||||
|
author_id INTEGER NOT NULL, \
|
||||||
|
title TEXT NOT NULL, \
|
||||||
|
content TEXT NOT NULL, \
|
||||||
|
tags TEXT NOT NULL DEFAULT '', \
|
||||||
|
categories TEXT NOT NULL DEFAULT '', \
|
||||||
|
visibility TEXT NOT NULL DEFAULT 'public', \
|
||||||
|
password TEXT, \
|
||||||
|
created_at INTEGER NOT NULL, \
|
||||||
|
updated_at INTEGER NOT NULL, \
|
||||||
|
FOREIGN KEY(author_id) REFERENCES users(id) ON DELETE CASCADE \
|
||||||
|
); \
|
||||||
|
CREATE TABLE attachments ( \
|
||||||
|
id TEXT PRIMARY KEY, \
|
||||||
|
filename TEXT NOT NULL, \
|
||||||
|
content_type TEXT NOT NULL, \
|
||||||
|
size INTEGER NOT NULL, \
|
||||||
|
created_at INTEGER NOT NULL \
|
||||||
|
);"
|
||||||
|
|
||||||
|
# Rebuild the real source with DATABASE_URL for sqlx macros
|
||||||
|
ENV DATABASE_URL=sqlite:///tmp/build.db
|
||||||
RUN touch src/main.rs && cargo build --release
|
RUN touch src/main.rs && cargo build --release
|
||||||
|
|
||||||
# Final Stage
|
# Final Stage
|
||||||
@@ -23,7 +60,7 @@ FROM debian:bookworm-slim
|
|||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Install runtime dependencies (like SSL certificates and sqlite)
|
# Install runtime dependencies
|
||||||
RUN apt-get update && apt-get install -y \
|
RUN apt-get update && apt-get install -y \
|
||||||
ca-certificates \
|
ca-certificates \
|
||||||
libsqlite3-0 \
|
libsqlite3-0 \
|
||||||
@@ -32,15 +69,13 @@ RUN apt-get update && apt-get install -y \
|
|||||||
# Copy the binary from the builder
|
# Copy the binary from the builder
|
||||||
COPY --from=builder /app/target/release/blog_cms .
|
COPY --from=builder /app/target/release/blog_cms .
|
||||||
|
|
||||||
# Create directory for attachments and database
|
# Create directories for attachments and database
|
||||||
RUN mkdir -p attachments
|
RUN mkdir -p attachments data
|
||||||
|
|
||||||
# Default environment variables
|
# Default environment variables
|
||||||
ENV PORT=3000
|
ENV PORT=3000
|
||||||
ENV DATABASE_URL=sqlite:///app/data.db
|
ENV DATABASE_URL=sqlite:///app/data/data.db
|
||||||
|
|
||||||
# Expose the application port
|
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|
||||||
# Start the application
|
|
||||||
CMD ["./blog_cms"]
|
CMD ["./blog_cms"]
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
version: '3.8'
|
|
||||||
services:
|
services:
|
||||||
blog:
|
blog:
|
||||||
build: .
|
build: .
|
||||||
ports:
|
ports:
|
||||||
- "3000:3000"
|
- "8080:3000"
|
||||||
environment:
|
environment:
|
||||||
- PORT=3000
|
- PORT=3000
|
||||||
- DATABASE_URL=sqlite:///app/data.db
|
- DATABASE_URL=sqlite:///app/data/data.db
|
||||||
volumes:
|
volumes:
|
||||||
- ./data.db:/app/data.db
|
- ./data:/app/data
|
||||||
- ./attachments:/app/attachments
|
- ./attachments:/app/attachments
|
||||||
restart: always
|
restart: always
|
||||||
|
|||||||
Reference in New Issue
Block a user