diff --git a/Dockerfile b/Dockerfile index cda0298..75f8d5d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,6 +5,7 @@ COPY ./markdown_backend ./markdown_backend WORKDIR /build/markdown_backend RUN rustup target add x86_64-unknown-linux-musl 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 FROM node:20 @@ -16,12 +17,20 @@ COPY package*.json ./ RUN npm install 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 --from=rust-build /build/markdown_backend/target/release/markdown_backend ./markdown_backend/target/release/markdown_backend +# Copy the statically linked Rust binary from the build stage +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 +# Create and set permissions for the docker volume mount point +RUN mkdir -p /app/docker && chmod 777 /app/docker + VOLUME ["/app/docker"] EXPOSE 3000 diff --git a/docker.sh b/docker.sh index 4ab52b0..a75ae64 100755 --- a/docker.sh +++ b/docker.sh @@ -2,6 +2,12 @@ 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" CONTAINER_NAME="markdownblog" VOLUME_NAME="markdownblog-posts" @@ -32,5 +38,11 @@ docker run -d \ 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' +# 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 "App should be available at http://localhost:$PORT" diff --git a/markdown_backend/src/markdown.rs b/markdown_backend/src/markdown.rs index f5c2540..1fa0bb2 100644 --- a/markdown_backend/src/markdown.rs +++ b/markdown_backend/src/markdown.rs @@ -55,8 +55,15 @@ fn get_posts_directory() -> PathBuf { fn get_file_creation_date(path: &Path) -> std::io::Result> { let metadata = fs::metadata(path)?; - let created = metadata.created()?; - Ok(DateTime::::from(created)) + // Try to get creation time, fall back to modification time if not available + match metadata.created() { + Ok(created) => Ok(DateTime::::from(created)), + Err(_) => { + // Fall back to modification time if creation time is not available + let modified = metadata.modified()?; + Ok(DateTime::::from(modified)) + } + } } fn process_anchor_links(content: &str) -> String {