Help with setting up Turborepo Node application

multiplehatsHOBBY

8 months ago

I've tried many things but I can't get it to work. The issue I'm currently running into is:

> [builder 6/6] RUN turbo run build --filter=scan-service:

0.267  WARNING  No locally installed `turbo` found. Using version: 2.0.9.

0.276

0.276 Attention:

0.276 Turborepo now collects completely anonymous telemetry regarding usage.

0.276 This information is used to shape the Turborepo roadmap and prioritize features.

0.276 You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:

0.276 https://turbo.build/repo/docs/telemetry

0.276

0.293   x No package found with name 'scan-service' in workspace

0.293

-----



Dockerfile:36

-------------------

34 |

35 |     # Build the scan-service

36 | >>> RUN turbo run build --filter=scan-service

37 |

38 |     # Expose port 3000

-------------------

ERROR: failed to solve: process "/bin/sh -c turbo run build --filter=scan-service" did not complete successfully: exit code: 1

The commands work locally,, and the "scan-service" app exists.

Project id: 50068b33-dd62-4d85-85a0-4353794cb644

0 Replies

multiplehatsHOBBY

8 months ago

Dockerfile

# Base stage with node:20-slim and pnpm setup
FROM node:20-slim AS base

# Environment variables for pnpm
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"

# Enable corepack to use pnpm
RUN corepack enable

# Install necessary build tools
RUN apt-get update && apt-get install -y \
    build-essential \
    python3 \
    && rm -rf /var/lib/apt/lists/*

# Builder stage
FROM base AS builder

# Set working directory to the app's directory
WORKDIR /usr/src/app/apps/scan-service

# Copy the entire project (from the perspective of apps/scan-service)
COPY ../.. ../..

# Move to the root directory
WORKDIR /usr/src/app

# Install Turbo globally
RUN pnpm install turbo@2.0.9 -g

# Install dependencies from the root
RUN pnpm install

# Build the scan-service
RUN turbo run build --filter=scan-service

# Expose port 3000
EXPOSE 3000

# Command to run the application
CMD ["turbo", "run", "start", "--filter=scan-service"]

multiplehatsHOBBY

8 months ago

Project id: 50068b33-dd62-4d85-85a0-4353794cb644


multiplehatsHOBBY

8 months ago

service settings

1283051270189351000


multiplehatsHOBBY

8 months ago

service id: f30f6f38-ab67-479b-9351-8acf06ea91cd


multiplehatsHOBBY

8 months ago

50068b33-dd62-4d85-85a0-4353794cb644


multiplehatsHOBBY

8 months ago

50068b33-dd62-4d85-85a0-4353794cb644


multiplehatsHOBBY

8 months ago

Fixed it. I removed the Root DIrectoy /apps/scan-service option. And instead set Config-as-code to /apps/scan-service/railway.toml.

[build]
builder = "DOCKERFILE"
dockerfilePath = "apps/scan-service/Dockerfile"

[deploy]
numReplicas = 1
restartPolicyType = "ON_FAILURE"
restartPolicyMaxRetries = 3
healthcheckPath = "/v1/health"
healthcheckTimeout = 50

multiplehatsHOBBY

8 months ago

Also revamped Dockerfile.

# Base stage
FROM node:18-alpine AS base

# Environment variables for pnpm
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"

RUN apk update && apk add --no-cache libc6-compat
RUN corepack enable

# Pruning stage
FROM base AS pruner
WORKDIR /app
COPY . .

# Install Turbo globally
RUN pnpm add -g turbo
RUN turbo prune scan-service --docker

# Development dependencies stage
FROM base AS dev-deps
WORKDIR /app
COPY --from=pruner /app/out/json/ .
COPY --from=pruner /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
RUN pnpm install

# Production dependencies stage
FROM base AS prod-deps
WORKDIR /app
COPY --from=pruner /app/out/json/ .
COPY --from=pruner /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
RUN pnpm install

# Build stage
FROM base AS builder
WORKDIR /app
COPY --from=dev-deps /app/ .
COPY --from=pruner /app/out/full/ .
COPY turbo.json* ./
RUN pnpm turbo run build --filter=scan-service...

# Runner stage
FROM base AS runner
WORKDIR /app
COPY --from=prod-deps /app/ .
COPY --from=builder /app/apps/scan-service/dist/ ./apps/scan-service/dist/

# Expose port 3000
EXPOSE 3000

# Command to run the application
CMD ["pnpm", "start"]

8 months ago

awesome! glad you were able to solve it!