This commit is contained in:
ZockerKatze
2025-06-24 10:47:44 +02:00
parent 5ad73485ce
commit fbc41654e0
3 changed files with 32 additions and 4 deletions

View File

@@ -5,6 +5,7 @@ COPY ./markdown_backend ./markdown_backend
WORKDIR /build/markdown_backend WORKDIR /build/markdown_backend
RUN rustup target add x86_64-unknown-linux-musl RUN rustup target add x86_64-unknown-linux-musl
RUN apt-get update && apt-get install -y musl-tools RUN apt-get update && apt-get install -y musl-tools
# Build with musl target for static linking
RUN cargo build --release --target x86_64-unknown-linux-musl RUN cargo build --release --target x86_64-unknown-linux-musl
FROM node:20 FROM node:20
@@ -16,12 +17,20 @@ COPY package*.json ./
RUN npm install RUN npm install
COPY . . COPY . .
# Ensure posts directory exists and has correct permissions
RUN mkdir -p /app/posts
COPY posts/* /app/posts/
RUN chmod -R 755 /app/posts
# Copy the Rust binary from the build stage # Copy the statically linked Rust binary from the build stage
COPY --from=rust-build /build/markdown_backend/target/release/markdown_backend ./markdown_backend/target/release/markdown_backend COPY --from=rust-build /build/markdown_backend/target/x86_64-unknown-linux-musl/release/markdown_backend ./markdown_backend/target/release/markdown_backend
RUN chmod +x ./markdown_backend/target/release/markdown_backend
RUN npm run build RUN npm run build
# Create and set permissions for the docker volume mount point
RUN mkdir -p /app/docker && chmod 777 /app/docker
VOLUME ["/app/docker"] VOLUME ["/app/docker"]
EXPOSE 3000 EXPOSE 3000

View File

@@ -2,6 +2,12 @@
set -e set -e
# Check if Docker daemon is running
if ! docker info >/dev/null 2>&1; then
echo "Error: Docker daemon is not running"
exit 1
fi
IMAGE_NAME="markdownblog" IMAGE_NAME="markdownblog"
CONTAINER_NAME="markdownblog" CONTAINER_NAME="markdownblog"
VOLUME_NAME="markdownblog-posts" VOLUME_NAME="markdownblog-posts"
@@ -32,5 +38,11 @@ docker run -d \
echo "Copying built-in posts to Docker volume if empty..." echo "Copying built-in posts to Docker volume if empty..."
docker exec $CONTAINER_NAME sh -c 'if [ -d /app/posts ] && [ -d /app/docker ] && [ "$(ls -A /app/docker)" = "" ]; then cp -r /app/posts/* /app/docker/; fi' docker exec $CONTAINER_NAME sh -c 'if [ -d /app/posts ] && [ -d /app/docker ] && [ "$(ls -A /app/docker)" = "" ]; then cp -r /app/posts/* /app/docker/; fi'
# Check if container is running
if ! docker ps | grep -q $CONTAINER_NAME; then
echo "Error: Container failed to start. Check logs with: docker logs $CONTAINER_NAME"
exit 1
fi
echo "Deployment complete!" echo "Deployment complete!"
echo "App should be available at http://localhost:$PORT" echo "App should be available at http://localhost:$PORT"

View File

@@ -55,8 +55,15 @@ fn get_posts_directory() -> PathBuf {
fn get_file_creation_date(path: &Path) -> std::io::Result<DateTime<Utc>> { fn get_file_creation_date(path: &Path) -> std::io::Result<DateTime<Utc>> {
let metadata = fs::metadata(path)?; let metadata = fs::metadata(path)?;
let created = metadata.created()?; // Try to get creation time, fall back to modification time if not available
Ok(DateTime::<Utc>::from(created)) match metadata.created() {
Ok(created) => Ok(DateTime::<Utc>::from(created)),
Err(_) => {
// Fall back to modification time if creation time is not available
let modified = metadata.modified()?;
Ok(DateTime::<Utc>::from(modified))
}
}
} }
fn process_anchor_links(content: &str) -> String { fn process_anchor_links(content: &str) -> String {