-
-
Save budivoogt/d750e8c2b6ef24748446899b094f3cdb to your computer and use it in GitHub Desktop.
Dockerfile for Railway ioredis issue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| This is my Dockerfile: | |
| ``` | |
| # | |
| # BASE STAGE | |
| # | |
| FROM node:20-alpine AS base | |
| # Install system dependencies | |
| RUN apk update && apk add curl bash | |
| # Enable built-in corepack and prepare pnpm | |
| RUN corepack enable && corepack prepare pnpm@10.2.1 --activate | |
| # Configure pnpm | |
| RUN echo "node-linker=hoisted\nshamefully-hoist=true\nstrict-peer-dependencies=false" > /root/.npmrc | |
| # Specify the environment variables needed at build time | |
| ARG DOTENV_PRIVATE_KEY_PRODUCTION | |
| ARG DOTENV_PRIVATE_KEY_STAGING | |
| ARG DATABASE_URL | |
| ARG REDIS_URL | |
| # | |
| # DEPENDENCIES STAGE | |
| # | |
| FROM base AS deps | |
| WORKDIR /app | |
| # Install dotenvx | |
| RUN curl -sfS https://dotenvx.sh/install.sh | sh | |
| # Copy package files and env files first (least likely to change) | |
| COPY package.json pnpm-lock.yaml .env.production .env.staging ./ | |
| COPY .npmrc.template .npmrc | |
| # Fetch all dependencies to pnpm store (with network) | |
| RUN --mount=type=cache,id=s/0645a717-42ab-437e-b049-27ac16263f72-/root/.local/share/pnpm/store,target=/root/.local/share/pnpm/store \ | |
| dotenvx run -- pnpm fetch --frozen-lockfile | |
| # Install production dependencies from cache (offline, no network needed) | |
| RUN --mount=type=cache,id=s/0645a717-42ab-437e-b049-27ac16263f72-/root/.local/share/pnpm/store,target=/root/.local/share/pnpm/store \ | |
| dotenvx run -- pnpm install --frozen-lockfile --offline --prod | |
| # | |
| # BUILD STAGE | |
| # | |
| FROM deps AS build | |
| # Install all dependencies (including devDependencies) from cache | |
| RUN --mount=type=cache,id=s/0645a717-42ab-437e-b049-27ac16263f72-/root/.local/share/pnpm/store,target=/root/.local/share/pnpm/store \ | |
| dotenvx run -- pnpm install --frozen-lockfile --offline | |
| # Copy source files in order of change frequency (most stable first) | |
| COPY drizzle-dev.config.ts drizzle-prod.config.ts ./ | |
| COPY src/lib/database ./src/lib/database | |
| COPY . . | |
| # Set Node options for increased memory | |
| ENV NODE_OPTIONS="--max-old-space-size=4096" | |
| # Build the application | |
| RUN NODE_ENV=production pnpm run build | |
| # | |
| # PRODUCTION STAGE | |
| # | |
| FROM base AS production | |
| WORKDIR /app | |
| # Copy production dependencies from deps stage | |
| COPY --from=deps /app/node_modules ./node_modules | |
| # Copy built application | |
| COPY --from=build /app/build ./build | |
| # Copy necessary runtime files | |
| COPY --from=build /app/package.json ./package.json | |
| COPY --from=build /app/.env.production ./.env.production | |
| COPY --from=build /app/.env.staging ./.env.staging | |
| COPY --from=build /app/.drizzle ./.drizzle | |
| COPY --from=build /app/drizzle-dev.config.ts ./drizzle-dev.config.ts | |
| COPY --from=build /app/drizzle-prod.config.ts ./drizzle-prod.config.ts | |
| COPY --from=build /app/src/lib/database ./src/lib/database | |
| # Expose the port the app runs on | |
| EXPOSE 3000 | |
| # Start the application | |
| CMD ["pnpm", "start"] | |
| ``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment