Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding new blog posts to docker container and having SSR #582

Open
Surgical17 opened this issue Jan 13, 2025 · 0 comments
Open

Adding new blog posts to docker container and having SSR #582

Surgical17 opened this issue Jan 13, 2025 · 0 comments

Comments

@Surgical17
Copy link

Hi Guys.

Struggling with a small issue. I am testing deploying the app in a docker container, then to map set volume to the host with the idea that I will just add new blog posts to the host and it will show up on the web due to ssr. Issues i have is right now files get added to src/data/post but this volume seems empty after build yet there is still data/blogs in the list. I assume this is in src/content/post? I tried to mount that to a volume but seems it doesn't exist and fails during build. Since if i mount the volume and if its empty the folder will be empty so during build I copy content from src/content/post to post_backup, then when i mount and start the container I run a inin.sh to copy the files back and start the app but its not working.

Any better way to achieve what im trying to achieve?

My Dockerfile:

# Base image for Node.js
FROM node:20-alpine AS base
WORKDIR /app
COPY package.json package-lock.json ./

# Stage for installing production dependencies
FROM base AS prod-deps
RUN npm install --omit=dev
# Debug commands for production dependencies
RUN ls -la node_modules
RUN ls -la node_modules/tailwind-merge || echo "tailwind-merge not found"

# Stage for installing all dependencies
FROM base AS build-deps
RUN npm install

# Stage for building the application
FROM build-deps AS build
# Copy the entire source directory including assets
COPY . .
RUN npm run build
# Debug commands for the build output
RUN ls -la dist/server/chunks
RUN ls -la dist/client/assets || echo "assets directory not found"

# Runtime stage
FROM base AS runtime
COPY --from=prod-deps /app/node_modules ./node_modules
COPY --from=build /app/dist ./dist
COPY --from=build /app/src/assets ./src/assets
COPY --from=build /app/src ./src
COPY ./src/content/post /app/src/data/post_backup
COPY ./init.sh /app/init.sh
RUN chmod +x /app/init.sh

# Environment variables
ENV HOST=0.0.0.0
ENV PORT=4321
EXPOSE 4321

CMD ["/app/init.sh"]
# Command to start the application
# CMD ["node", "./dist/server/entry.mjs"]

My init.sh:

#!/bin/sh

# Debug: Check if post_backup exists
echo "Checking post_backup..."
ls -la /app/src/data/post_backup

# Check if content/post is empty and repopulate if needed
if [ -z "$(ls -A /app/src/content/post)" ]; then
    echo "Repopulating content/post from post_backup..."
    cp -R /app/src/data/post_backup/* /app/src/content/post/
else
    echo "content/post is already populated."
fi

# Debug: Confirm content/post contents
echo "Final content/post contents:"
ls -la /app/src/content/post

# Start the application
exec node ./dist/server/entry.mjs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant