Docker build with Moonrepo stuck on pnpm install on Railway
justkira
PROOP

7 months ago

The Problem:

I'm using Moonrepo to manage a monorepo and deploying a service (studio) to Railway using Docker. My Dockerfile is based on Moonrepo's multi-stage build guide.

When I run the CMD in my local Docker environment, the container starts up instantly, as expected. The pnpm install step from the build process is not re-run.

However, on Railway, when I set the Start Command in the dashboard to moon run studio:start, the pnpm install task is triggered and gets stuck. This is the main issue: moon run studio:start on Railway is somehow re-running the installation step, which it shouldn't, and then it hangs.

My Assumption:
My Dockerfile has a build stage with moon docker setup and a separate start stage with CMD moon run studio:start. The start stage should inherit the fully built application from the build stage, so there should be no need to re-run pnpm install. It seems that the Start Command on Railway is bypassing the cached build image and trying to set up the project from scratch, which is causing the endless stuck in pnpm install. Note this only happens if the start command inside docker when i remove it and start it using Deploy command railway it does pnpm install and works but still i don't want that werid pnpm install

I'm trying to understand why Railway's start command behaves differently from my Dockerfile's CMD command, causing it to trigger a dependency install that should have already been completed.

$10 Bounty

38 Replies

clashing
HOBBY

7 months ago

How are you starting Docker every time on Railway! What does that even mean

The issue is not very clear. Please specify the actual problem you are facing on Railway


justkira
PROOP

7 months ago

Docker build with Moonrepo stuck on pnpm install on Railway


justkira
PROOP

7 months ago

i rephased it better i guess

here is the dokcer
Current Full Docker

#### BASE STAGE
#### Installs moon.

FROM node:latest AS base
WORKDIR /app

# Install moon binary
RUN curl -fsSL https://moonrepo.dev/install/moon.sh | bash
ENV PATH="/root/.moon/bin:$PATH"

#### SKELETON STAGE
#### Scaffolds repository skeleton structures.

FROM base AS skeleton

# Copy entire repository and scaffold
COPY . .
RUN moon docker scaffold studio

#### BUILD STAGE
#### Builds the project.

FROM base AS build

# Copy toolchain
COPY --from=skeleton /root/.proto /root/.proto

# Copy workspace configs
COPY --from=skeleton /app/.moon/docker/workspace .

# Install dependencies
RUN moon docker setup

# Copy project sources
COPY --from=skeleton /app/.moon/docker/sources .

# Build the project
RUN moon run studio:build

# Prune extraneous dependencies
RUN moon docker prune

justkira
PROOP

7 months ago

1407673559630745600


justkira
PROOP

7 months ago

Here it happend again

1407796009576169500


7 months ago

You cannot run docker commands within Railway.


justkira
PROOP

7 months ago

is there a work around to that


justkira
PROOP

7 months ago

by command u mean CMD?

or if i wrap it in a bash or something i dont quite understand what o u mean wiht commands


justkira
PROOP

7 months ago

like this

CMD moon run studio:start

7 months ago

Your build command, you are trying to run a docker command, that just isn't supported.


justkira
PROOP

7 months ago

is that a platform limitation or something that can be supported in the future


justkira
PROOP

7 months ago

because it seems my only option is to go to a private registitry i guess


7 months ago

Not really either, its just not how its done.

What are you trying to achieve?


justkira
PROOP

7 months ago

'm trying to optimize a Docker build process within a monorepo managed by Moonrepo. Moonrepo offers features for creating small Docker images and manages project dependencies, but pnpm install seems to run unexpectedly when starting a Docker container, causing confusion and hindering my goal of getting the build working efficiently.


justkira
PROOP

7 months ago

well in my case it doesn't actually work but yaa


justkira
PROOP

7 months ago

what i expect when railway go to deploy
Is see

running localhost:3000 or whatever

what i see is pnpm install getting stuck for ever


justkira
PROOP

7 months ago

if CMD is inside docker


justkira
PROOP

7 months ago

when i take it out
well i still have to face that pnpm install but deploy works at the end


justkira
PROOP

7 months ago

#### BASE STAGE
#### Installs moon.

FROM node:latest AS base
WORKDIR /app

# Install moon binary
RUN curl -fsSL https://moonrepo.dev/install/moon.sh | bash
ENV PATH="/root/.moon/bin:$PATH"

#### SKELETON STAGE
#### Scaffolds repository skeleton structures.

FROM base AS skeleton

# Copy entire repository and scaffold
COPY . .
RUN moon docker scaffold studio

#### BUILD STAGE
#### Builds the project.

FROM base AS build

# Copy toolchain
COPY --from=skeleton /root/.proto /root/.proto

# Copy workspace configs
COPY --from=skeleton /app/.moon/docker/workspace .

# Install dependencies
RUN moon docker setup

# Copy project sources
COPY --from=skeleton /app/.moon/docker/sources .

# Build the project
RUN moon run studio:build

# Prune extraneous dependencies
RUN moon docker prune

#### START STAGE
#### Runs the project.

FROM base AS start

# Copy built sources
COPY --from=build /root/.proto /root/.proto
COPY --from=build /app /app

CMD moon run studio:start

here full docker that is not working


7 months ago

Is your build just not being done with your Dockerfile?


justkira
PROOP

7 months ago

it get stuck


justkira
PROOP

7 months ago

build is success


justkira
PROOP

7 months ago

i guess


7 months ago

link to the service please



justkira
PROOP

7 months ago

1407819485800435700


justkira
PROOP

7 months ago

this applies for both uni-fied studio and uni-fied backend


justkira
PROOP

7 months ago

they have also same docker strucutre


7 months ago

Looks like you need to adjust your studio:start script, its trying to install stuff


justkira
PROOP

7 months ago

well idea is that doesn't happen locally


justkira
PROOP

7 months ago

like when i build and run it


justkira
PROOP

7 months ago

this is comand btw
start:
command: 'node build'


justkira
PROOP

7 months ago

moon:start just maps to this node build


justkira
PROOP

7 months ago

node build is output file of sveltkit project node build/index.js just for more context


7 months ago

Have you run the dockerfile locally?


justkira
PROOP

7 months ago

yes


7 months ago

I will let the community continue to help you then.


justkira
PROOP

7 months ago

ill go talk with moonrepo devs too maybe issue is on there end or somehting incorrect with my setup acts diff between machine not sure


Loading...