diff --git a/Dockerfile.combined b/Dockerfile.combined new file mode 100644 index 0000000..064fab2 --- /dev/null +++ b/Dockerfile.combined @@ -0,0 +1,58 @@ +# Multi-stage build combining both services + +# Stage 1: Build the Node.js/Astro application +FROM node:24-alpine AS app-builder +WORKDIR /app +COPY package*.json ./ +RUN npm i +COPY . . +ENV PUBLIC_PB_URL=http://pb:8080 +ENV PUBLIC_URL=http://localhost:4321 +RUN npm run build + +# Stage 2: Setup PocketBase and combine with the built app +FROM alpine:latest + +ARG PB_VERSION=0.29.2 + +WORKDIR /pb + +RUN apk add --no-cache \ + unzip \ + curl \ + ca-certificates \ + bash \ + nodejs \ + npm + +# Download and unzip PocketBase +ADD https://github.com/pocketbase/pocketbase/releases/download/v${PB_VERSION}/pocketbase_${PB_VERSION}_linux_amd64.zip /tmp/pb.zip +RUN unzip /tmp/pb.zip -d /pb/ + +# Copy PocketBase entrypoint +COPY api/docker-entrypoint.sh /usr/local/bin/ +RUN chmod +x /usr/local/bin/docker-entrypoint.sh + +# Create app directory and copy built application +WORKDIR /app +COPY --from=app-builder /app . +# COPY --from=app-builder /app/package*.json ./ +# COPY --from=app-builder /app/node_modules ./node_modules + +# Set environment variables (keeping them as they are) +ENV PUBLIC_PB_URL=http://pb:8080 +ENV PUBLIC_URL=http://localhost:4321 + +VOLUME [ "/pb/pb_data", "/pb/pb_migrations", "/pb/pb_hooks" ] +# VOLUME [ "/pb/pb_data" ] + +EXPOSE 8080 4321 + +# Create a startup script that runs both services +RUN echo '#!/bin/bash' > /usr/local/bin/start-services.sh && \ + echo 'cd /pb && docker-entrypoint.sh serve --http=0.0.0.0:8080 &' >> /usr/local/bin/start-services.sh && \ + echo 'cd /app && npm run preview -- --host &' >> /usr/local/bin/start-services.sh && \ + echo 'wait' >> /usr/local/bin/start-services.sh && \ + chmod +x /usr/local/bin/start-services.sh + +CMD ["start-services.sh"]