Can't deploy due to can't cd to client

I already have one app with a postgres db running on fly. I’m trying to deploy another node app but I think the builder is taking up my last available machine. When I try to deploy it, I just get an error that it can’t cd into the client directory, but I think this is because it just doesn’t have a machine. I can’t scale more machines for this app because there’s no initial machine to clone. What am I missing?

==> Verifying app config
Validating /home/me/myapp_v2/myapp/fly.toml
Platform: machines
✓ Configuration is valid
--> Verified app config
==> Building image
Remote builder fly-builder-old-thunder-773 ready
==> Building image with Docker
--> docker host: 20.10.12 linux x86_64
[+] Building 9.9s (13/17)                                                                                             
 => [internal] load build definition from Dockerfile                                                             0.1s
 => => transferring dockerfile: 957B                                                                             0.1s
 => [internal] load .dockerignore                                                                                0.1s
 => => transferring context: 34B                                                                                 0.1s
 => resolve image config for docker.io/docker/dockerfile:1                                                       0.2s
 => CACHED docker-image://docker.io/docker/dockerfile:1@sha256:ac85f380a63b13dfcefa89046420e1781752bab202122f8f  0.0s
 => [internal] load build definition from Dockerfile                                                             0.0s
 => [internal] load metadata for docker.io/library/node:20.6.1-slim                                              0.1s
 => [internal] load .dockerignore                                                                                0.0s
 => [base 1/2] FROM docker.io/library/node:20.6.1-slim@sha256:2dab2d0e8813ee1601f8d25a8e4aa5530ffc4d0cc16600ec4  0.0s
 => CACHED [base 2/2] WORKDIR /app                                                                               0.0s
 => [internal] load build context                                                                                1.3s
 => => transferring context: 817.13kB                                                                            1.2s
 => CACHED [build 1/6] RUN apt-get update -qq &&     apt-get install -y build-essential pkg-config python-is-py  0.0s
 => CACHED [build 2/6] COPY --link package-lock.json package.json ./                                             0.0s
 => ERROR [build 3/6] RUN npm ci --include=dev                                                                   8.0s
------                                                                                                                
 > [build 3/6] RUN npm ci --include=dev:
#0 7.617 
#0 7.617 > myapp@1.0.0 postinstall
#0 7.617 > cd client && npm install
#0 7.617 
#0 7.622 sh: 1: cd: can't cd to client
#0 7.624 npm notice 
#0 7.624 npm notice New major version of npm available! 9.8.1 -> 10.1.0
#0 7.624 npm notice Changelog: <https://github.com/npm/cli/releases/tag/v10.1.0>
#0 7.624 npm notice Run `npm install -g npm@10.1.0` to update!
#0 7.625 npm notice 
#0 7.626 npm ERR! code 2
#0 7.626 npm ERR! path /app
#0 7.628 npm ERR! command failed
#0 7.628 npm ERR! command sh -c cd client && npm install
#0 7.630 
#0 7.630 npm ERR! A complete log of this run can be found in: /root/.npm/_logs/2023-09-15T22_19_14_598Z-debug-0.log
------
Error: failed to fetch an image or build from source: error building: failed to solve: executor failed running [/bin/sh -c npm ci --include=dev]: exit code: 2

Glancing at the error, it looks like it’s a npm error during the docker build step.

Does it work locally?

Can you post the Dockerfile?

Can you do ls -al to see if client folder exists?

Are you running a USER node in the Dockerfile?

Can you pull the logs from here - /root/.npm/_logs/2023-09-15T22_19_14_598Z-debug-0.log

fly deploy --local-only says
Error: failed to fetch an image or build from source: docker is unavailable to build the deployment image

This is the dockerfile generated by fly launch

# syntax = docker/dockerfile:1

# Adjust NODE_VERSION as desired
ARG NODE_VERSION=20.3.1
FROM node:${NODE_VERSION}-slim as base

LABEL fly_launch_runtime="Node.js"

# Node.js app lives here
WORKDIR /app

# Set production environment
ENV NODE_ENV="production"


# Throw-away build stage to reduce size of final image
FROM base as build

# Install packages needed to build node modules
RUN apt-get update -qq && \
    apt-get install -y build-essential pkg-config python-is-python3

# Install node modules
COPY --link package-lock.json package.json ./
RUN npm ci --include=dev

# Copy application code
COPY --link . .

# Build application
RUN npm run build

# Remove development dependencies
RUN npm prune --omit=dev


# Final stage for app image
FROM base

# Copy built application
COPY --from=build /app /app

# Start the server by default, this can be overwritten at runtime
EXPOSE 3000
CMD [ "npm", "run", "start" ]

The client folder definitely exists in the root of my app.

For some reason WSL is giving me permission errors trying to access the npm logs. fly logs also hangs.

Do you have docker agent running and installed locally?

This line here at the bottom of your dockerfile. What If you change it to point at the file that has your server or port? For example something like:

CMD [ "node", "server.js" ]
CMD [ "node", "index.js" ]

Does this do anything different for you?

I believe that the problem was this error in the npm ci step.

 => ERROR [build 3/6] RUN npm ci --include=dev                                                                   8.0s
------                                                                                                                
 > [build 3/6] RUN npm ci --include=dev:
#0 7.617 
#0 7.617 > myapp@1.0.0 postinstall
#0 7.617 > cd client && npm install
#0 7.617 
#0 7.622 sh: 1: cd: can't cd to client
#0 7.624 npm notice 
#0 7.624 npm notice New major version of npm available! 9.8.1 -> 10.1.0
#0 7.624 npm notice Changelog: <https://github.com/npm/cli/releases/tag/v10.1.0>
#0 7.624 npm notice Run `npm install -g npm@10.1.0` to update!
#0 7.625 npm notice 
#0 7.626 npm ERR! code 2
#0 7.626 npm ERR! path /app
#0 7.628 npm ERR! command failed
#0 7.628 npm ERR! command sh -c cd client && npm install
#0 7.630 
#0 7.630 npm ERR! A complete log of this run can be found in: /root/.npm/_logs/2023-09-15T22_19_14_598Z-debug-0.log

I’d check package.json’s scripts section. You may have cd client && npm install there.

Do you have client/ directory? If so, you probably need to

# Copy application code
COPY --link . .

before the npm ci step.

1 Like

Yes I have Docker installed and running.

My start script in package.json is just node app.js
Changing the command at the end to “node”, “app.js” doesn’t do anything different.

These are my scripts:

  "scripts": {
    "start": "node app.js",
    "dev": "concurrently --kill-others-on-fail \"npm:server\" \"npm:client\"",
    "server": "nodemon app.js",
    "client": "cd client && npm start",
    "postinstall": "cd client && npm install",
    "build": "rm -rf build && cd client && npm run build && cp -r build ../"
  },

There is an entry for the client script to cd client and npm start. Is that bad? Removing it doesn’t change the outcome.

Moving copy --link . . before npm ci ended up fixing it. Thank you

It is not bad, but it doesn’t work with Dockerfile you had, particularly this section.

# Install node modules
COPY --link package-lock.json package.json ./
RUN npm ci --include=dev

# Copy application code
COPY --link . .

This section assumes npm ci --include=dev works only with package-lock.json and package.json. By only copying these two files, the cached result of npm ci is invalidated only if you modify these 2 JSON files.

But, having cd client && npm install as postinstall breaks the assumption, since npm ci runs postinstall

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.