works
This commit is contained in:
13
Dockerfile
13
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
|
||||
|
||||
12
docker.sh
12
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"
|
||||
|
||||
@@ -55,8 +55,15 @@ fn get_posts_directory() -> PathBuf {
|
||||
|
||||
fn get_file_creation_date(path: &Path) -> std::io::Result<DateTime<Utc>> {
|
||||
let metadata = fs::metadata(path)?;
|
||||
let created = metadata.created()?;
|
||||
Ok(DateTime::<Utc>::from(created))
|
||||
// Try to get creation time, fall back to modification time if not available
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user