|
| 1 | +FROM node:20.11-slim as dependencies |
| 2 | +WORKDIR /app |
| 3 | + |
| 4 | +# Install pnpm and build dependencies |
| 5 | +RUN npm install -g [email protected] && \ |
| 6 | + apt-get update -qq && \ |
| 7 | + apt-get install -y python3 build-essential && \ |
| 8 | + rm -rf /var/lib/apt/lists/* |
| 9 | + |
| 10 | +# Create the environments directory and env file FIRST |
| 11 | +RUN mkdir -p src/environments && \ |
| 12 | + echo "PLAYWRIGHT_BROWSERS_PATH=/app/pw-browsers" > src/environments/browser-path.env |
| 13 | + |
| 14 | +# Copy package files |
| 15 | +COPY package.json pnpm-lock.yaml ./ |
| 16 | + |
| 17 | +# Install dependencies and extra packages needed for content generation |
| 18 | +ENV PLAYWRIGHT_BROWSERS_PATH=/app/pw-browsers |
| 19 | +ENV HUSKY=0 |
| 20 | +RUN pnpm install && \ |
| 21 | + pnpm playwright install chromium |
| 22 | + |
| 23 | +# Content generation stage |
| 24 | +FROM dependencies as content-builder |
| 25 | +WORKDIR /app |
| 26 | + |
| 27 | +# Copy source files |
| 28 | +COPY . . |
| 29 | + |
| 30 | +# Copy over the node_modules and Playwright browsers |
| 31 | +COPY --from=dependencies /app/node_modules ./node_modules |
| 32 | +COPY --from=dependencies /app/pw-browsers ./pw-browsers |
| 33 | +COPY --from=dependencies /app/src/environments/browser-path.env ./src/environments/browser-path.env |
| 34 | + |
| 35 | +# First generate the content |
| 36 | +RUN pnpm run epub & pnpm run social-previews:build & wait |
| 37 | + |
| 38 | +# Run just the Astro build |
| 39 | +RUN pnpm exec astro build --experimental-integrations || if [ -d "dist" ]; then \ |
| 40 | + exit 0; \ |
| 41 | + else \ |
| 42 | + exit 1; \ |
| 43 | + fi |
| 44 | + |
| 45 | +# Production stage for static files |
| 46 | +FROM nginx:alpine |
| 47 | +COPY --from=content-builder /app/dist /usr/share/nginx/html |
| 48 | + |
| 49 | +EXPOSE 80 |
| 50 | +CMD ["nginx", "-g", "daemon off;"] |
0 commit comments