ustaxes/UsTaxes

docker build error

kushtrimjunuzi opened this issue · 5 comments

Hi there, just wanted to report this issue when building docker image, the only change I did in Dockerfile was changing node version to 16.14.0, because the version 14 that was on the master is not working ether.
I'm going to try and fix this if I can, thanks all for this project.

kushtrim@docker1:~/projects/UsTaxes$ docker build -t ustaxes .
Sending build context to Docker daemon  6.817MB
Step 1/12 : FROM rust:1.51-slim-buster
 ---> eb285de0ba07
Step 2/12 : RUN apt-get update && apt-get -y upgrade && apt-get install -y curl
 ---> Using cache
 ---> e9caa1d832cd
Step 3/12 : ARG NVM_DIR="/root/.nvm"
 ---> Using cache
 ---> 3988eda250ba
Step 4/12 : ARG NODE_VERSION=16.14.0
 ---> Using cache
 ---> dce5aea8bc74
Step 5/12 : RUN curl https://raw.githubusercontent.com/creationix/nvm/v0.38.0/install.sh | bash
 ---> Using cache
 ---> f72a8adab53a
Step 6/12 : RUN . $NVM_DIR/nvm.sh && nvm install $NODE_VERSION --latest-npm
 ---> Using cache
 ---> fbcd752972fb
Step 7/12 : ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH
 ---> Using cache
 ---> 88ebf095566d
Step 8/12 : WORKDIR /app
 ---> Using cache
 ---> efdf42edf52a
Step 9/12 : ADD ./package.json ./package.json
 ---> 61cf4bba0956
Step 10/12 : ADD ./package-lock.json ./package-lock.json
 ---> ad7fd8967290
Step 11/12 : RUN npm ci
 ---> Running in 677ac339f602

> ustaxes@0.1.16 prepare
> ts-node ./scripts/env.ts && husky install

node:internal/modules/cjs/loader:936
  throw err;
  ^

Error: Cannot find module './env.ts'
Require stack:
- /app/scripts/imaginaryUncacheableRequireResolveScript
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.resolve (node:internal/modules/cjs/helpers:108:19)
    at requireResolveNonCached (/app/node_modules/ts-node/dist/bin.js:375:16)
    at getProjectSearchDir (/app/node_modules/ts-node/dist/bin.js:345:40)
    at main (/app/node_modules/ts-node/dist/bin.js:220:27)
    at Object.<anonymous> (/app/node_modules/ts-node/dist/bin.js:405:5)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1155:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/app/scripts/imaginaryUncacheableRequireResolveScript' ]
}
npm notice 
npm notice New minor version of npm available! 8.3.1 -> 8.5.1
npm notice Changelog: <https://github.com/npm/cli/releases/tag/v8.5.1>
npm notice Run `npm install -g npm@8.5.1` to update!
npm notice 
npm ERR! code 1
npm ERR! path /app
npm ERR! command failed
npm ERR! command sh -c ts-node ./scripts/env.ts && husky install

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2022-02-21T14_31_09_521Z-debug-0.log```

Hmm I was able to run that command successfully

 docker build -t ustaxes .
[+] Building 109.8s (14/14) FINISHED
 => [internal] load build definition from Dockerfile                                                               0.0s
 => => transferring dockerfile: 32B                                                                                0.0s
 => [internal] load .dockerignore                                                                                  0.0s
 => => transferring context: 35B                                                                                   0.0s
 => [internal] load metadata for docker.io/library/rust:1.51-slim-buster                                          11.1s
 => [internal] load build context                                                                                  1.8s
 => => transferring context: 2.61MB                                                                                1.7s
 => [1/9] FROM docker.io/library/rust:1.51-slim-buster@sha256:eb35fd0f970f3a32d21f5b39b6320cdc0baf0c0603cd15df16d  0.0s
 => CACHED [2/9] RUN apt-get update && apt-get -y upgrade && apt-get install -y curl                               0.0s
 => CACHED [3/9] RUN curl https://raw.githubusercontent.com/creationix/nvm/v0.38.0/install.sh | bash               0.0s
 => CACHED [4/9] RUN . /root/.nvm/nvm.sh && nvm install 14.6.0 --latest-npm                                        0.0s
 => CACHED [5/9] WORKDIR /app                                                                                      0.0s
 => CACHED [6/9] ADD ./package.json ./package.json                                                                 0.0s
 => [7/9] ADD ./package-lock.json ./package-lock.json                                                              0.0s
 => [8/9] RUN npm ci                                                                                              65.2s
 => [9/9] ADD . .                                                                                                  5.3s
 => exporting to image                                                                                            26.4s
 => => exporting layers                                                                                           26.4s
 => => writing image sha256:456cd162e8564e69254fee1961e6a29bce7a6688b05196f83028f4e67079101a                       0.0s
 => => naming to docker.io/library/ustaxes                                                                         0.0s

Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them

I ran into the same issue. In the current version docker-compose build will complete successfully (as demonstrated by @thegrims). However, if you run docker-compose up it will fail, with a complaint about required npm version.

ustaxes-app-1  | |------------------------------------|
ustaxes-app-1  | | Required npm version not found.    |
ustaxes-app-1  | | Required: >= 7.0                   |
ustaxes-app-1  | | Found:       6.14                  |
ustaxes-app-1  | | Consider using nvm: https://nvm.sh |
ustaxes-app-1  | |------------------------------------|
ustaxes-app-1  | npm ERR! code ELIFECYCLE
ustaxes-app-1  | npm ERR! errno 1
ustaxes-app-1  | npm ERR! ustaxes@0.1.16 start: `node ./notice.js && ts-node ./scripts/env.ts && ts-node ./scripts/setup.ts && concurrently npm:dev`
ustaxes-app-1  | npm ERR! Exit status 1
ustaxes-app-1  | npm ERR!
ustaxes-app-1  | npm ERR! Failed at the ustaxes@0.1.16 start script.
ustaxes-app-1  | npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
ustaxes-app-1  |
ustaxes-app-1  | npm ERR! A complete log of this run can be found in:
ustaxes-app-1  | npm ERR!     /root/.npm/_logs/2022-02-26T21_33_20_598Z-debug.log
ustaxes-app-1 exited with code 1

If you attempt to fix this by changing the Dockerfile to use a new version of Node the build no longer works, resulting in the error @kushtrimjunuzi posted. This has something to do with the RUN npm ci command in the Dockerfile not being able to execute correctly for newer versions of node.

I was able to get it working by removing this line from the Dockerfile

RUN npm ci

and adding it to the docker-compose.yml

version: '3.7'

services:
  app:
    build: .
    command: npm ci
    ports:
      - '3000:3000'
    volumes:
      - ./:/app
      - /app/node_modules

I then ran docker-compose up once, reverted to the original docker-compose.yml and ran everything normally. Now I can start and stop the container as expected.

This is obviously a hack and not a long term fix but unfortunately I am not familiar enough with node and docker to understand what changed between the versions that causes RUN npm ci to fail. It appears to be something classpath related but 🤷.

I don't use docker that often, so would you @dwstanley try checking out the branch from #957 and see if that solves your issue? Thank you.

@zakpatterson That fixed it for me. Thanks!

Great, based on @dwstanley's feedback, I'm going to merge that fix and close this issue, please feel free to reopen @kushtrimjunuzi if it's not working for you. Thanks!