trufflesuite / ganache

:warning: The Truffle Suite is being sunset. For information on ongoing support, migration options and FAQs, visit the Consensys blog. Thank you for all the support over the years.
https://consensys.io/blog/consensys-announces-the-sunset-of-truffle-and-ganache-and-new-hardhat?utm_source=github&utm_medium=referral&utm_campaign=2023_Sep_truffle-sunset-2023_announcement_
MIT License
2.61k stars 675 forks source link

Docker build fails #4273

Open 0x416e746f6e opened 1 year ago

0x416e746f6e commented 1 year ago

I get an error if I try to build the docker image (as suggested in README.md):

$ docker build --tag trufflesuite/ganache --file ./src/packages/ganache/Dockerfile .
...

 => [stage-1 2/4] WORKDIR /app                                                                             3.5s
 => [builder 2/7] WORKDIR /app                                                                             2.9s
 => [builder 3/7] COPY . .                                                                                 2.0s
 => ERROR [builder 4/7] RUN npm run clean                                                                 32.6s
------
 > [builder 4/7] RUN npm run clean:
#0 0.594
#0 0.594 > root@ clean /app
#0 0.594 > npm run tsc.clean && npx lerna clean -y && npx shx rm -rf node_modules
#0 0.594
#0 0.882
#0 0.882 > root@ tsc.clean /app
#0 0.882 > npx lerna exec -- npx shx rm -rf lib dist typings
#0 0.882
#0 30.93 sh: 1: node-gyp-build: Permission denied
#0 31.14 npm ERR! Maximum call stack size exceeded
#0 31.17
#0 31.17 npm ERR! A complete log of this run can be found in:
#0 31.17 npm ERR!     /root/.npm/_logs/2023-03-02T16_02_48_654Z-debug.log
#0 31.23 Install for [ 'lerna@latest' ] failed with code 1
#0 32.39 npm ERR! code ELIFECYCLE
#0 32.39 npm ERR! errno 1
#0 32.40 npm ERR! root@ tsc.clean: `npx lerna exec -- npx shx rm -rf lib dist typings`
#0 32.40 npm ERR! Exit status 1
#0 32.40 npm ERR!
#0 32.40 npm ERR! Failed at the root@ tsc.clean script.
#0 32.40 npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
#0 32.41
#0 32.41 npm ERR! A complete log of this run can be found in:
#0 32.41 npm ERR!     /root/.npm/_logs/2023-03-02T16_02_49_888Z-debug.log
#0 32.42 npm ERR! code ELIFECYCLE
#0 32.42 npm ERR! errno 1
#0 32.43 npm ERR! root@ clean: `npm run tsc.clean && npx lerna clean -y && npx shx rm -rf node_modules`
#0 32.43 npm ERR! Exit status 1
#0 32.43 npm ERR!
#0 32.43 npm ERR! Failed at the root@ clean script.
#0 32.43 npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
#0 32.43
#0 32.43 npm ERR! A complete log of this run can be found in:
#0 32.43 npm ERR!     /root/.npm/_logs/2023-03-02T16_02_49_916Z-debug.log
------
Dockerfile:9
--------------------
   7 |
   8 |     # clean and install dependencies
   9 | >>> RUN npm run clean
  10 |     RUN npm ci --unsafe-perm
  11 |
--------------------
ERROR: failed to solve: process "/bin/sh -c npm run clean" did not complete successfully: exit code: 1
davidmurdoch commented 1 year ago

Does checking out commit e0bb8e3ab900e94f882365fb68a9dbcd7ea07872 work for you? (git checkout e0bb8e3ab900e94f882365fb68a9dbcd7ea07872)

0x416e746f6e commented 1 year ago

Nope. Checking out v7.7.5 (and v7.0.0 for that matter as well) does not help.

There is more that one issue, though, from what I can see:

  1. Running npx leerna ... fails to install something under root user => but it works if I create ganache user and su - ganache.
  2. Further on, it complains about python3 being too old (3.5.3 while at least 3.6.0 is expected) => if I bump base image to node:14.21.3-buster it seems to help.
  3. Running npm run build demands INFURA_KEY env var to be set.. What if I don't have one?

For p.p. 1, 2 I can push a PR. But what do I do about p.3? Can I just feed it a nonsense key (e.g. 01234567890123456789012345678901)?

davidmurdoch commented 1 year ago

Looks like the instructions are out missing some instructions. You'll need to pass a build arg, INFURA_KEY for now (--build-arg flag to the docker build command), as the Docker file doesn't currently import the CREATE_BROKEN_BUILD flag (which must be set to "I WILL NOT PUBLISH THIS" if you don't provide an INFURA_KEY).

If you don't provide a valid INFURA_KEY forking via ganache --fork mainnet won't work. You can provide a nonsense key to just make it build, if you want (it must be 32 hex characters, IIRC)

.

Building is working as expected in CI and on my machine (Linux). I'm unsure what could be going wrong for you, do you have other changes? Have you ever run npm as root on your host machine?

0x416e746f6e commented 1 year ago

It fails on my local Mac (M1). If fails on remote ubuntu 20.04.5 LTS (x86_64). Here's the output of the above command (on ubuntu machine, on top of v7.7.5):

Status: Downloaded newer image for node:14.17.4@sha256:cd98882c1093f758d09cf6821dc8f96b241073b38e8ed294ca1f9e484743858f
 ---> 7528ad312b56
Step 2/16 : WORKDIR /app
 ---> Running in 73a0b3c0ea8d
Removing intermediate container 73a0b3c0ea8d
 ---> ac9fdc6a8b1e
Step 3/16 : COPY . .
 ---> 050a3d268586
Step 4/16 : RUN npm run clean
 ---> Running in a99aa799e07d

> root@ clean /app
> npm run tsc.clean && npx lerna clean -y && npx shx rm -rf node_modules

> root@ tsc.clean /app
> npx lerna exec -- npx shx rm -rf lib dist typings

npm ERR! cb() never called!

npm ERR! This is an error with npm itself. Please report this error at:
npm ERR!     <https://npm.community>

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2023-03-02T17_18_14_723Z-debug.log
Install for [ 'lerna@latest' ] failed with code 1
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! root@ tsc.clean: `npx lerna exec -- npx shx rm -rf lib dist typings`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the root@ tsc.clean script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2023-03-02T17_18_14_793Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! root@ clean: `npm run tsc.clean && npx lerna clean -y && npx shx rm -rf node_modules`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the root@ clean script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2023-03-02T17_18_14_814Z-debug.log
The command '/bin/sh -c npm run clean' returned a non-zero code: 1
0x416e746f6e commented 1 year ago

do you have other changes?

nope.

Have you ever run npm as root on your host machine?

nope. running all inside docker.

davidmurdoch commented 1 year ago

What OS and version?

0x416e746f6e commented 1 year ago
$ uname -a
Linux localhost 5.4.0-135-generic #152-Ubuntu SMP Wed Nov 23 20:19:22 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
$ cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04.5 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.5 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal
$ docker --version
Docker version 20.10.22, build 3a2c30b
$ cd /tmp
$ git clone https://github.com/trufflesuite/ganache.git
Cloning into 'ganache'...
remote: Enumerating objects: 45776, done.
remote: Counting objects: 100% (162/162), done.
remote: Compressing objects: 100% (90/90), done.
remote: Total 45776 (delta 84), reused 137 (delta 70), pack-reused 45614
Receiving objects: 100% (45776/45776), 319.38 MiB | 24.28 MiB/s, done.
Resolving deltas: 100% (31748/31748), done.
$ cd ganache
$ git checkout e0bb8e3ab900e94f882365fb68a9dbcd7ea07872
Note: switching to 'e0bb8e3ab900e94f882365fb68a9dbcd7ea07872'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at e0bb8e3a chore(release): publish v7.7.5
$ docker build --tag trufflesuite/ganache --file ./src/packages/ganache/Dockerfile .
Sending build context to Docker daemon  371.1MB
Step 1/16 : FROM node:14.17.4@sha256:cd98882c1093f758d09cf6821dc8f96b241073b38e8ed294ca1f9e484743858f AS builder
 ---> 7528ad312b56
Step 2/16 : WORKDIR /app
 ---> Using cache
 ---> ac9fdc6a8b1e
Step 3/16 : COPY . .
 ---> a3004e187194
Step 4/16 : RUN npm run clean
 ---> Running in aad54fd9ad29

> root@ clean /app
> npm run tsc.clean && npx lerna clean -y && npx shx rm -rf node_modules

> root@ tsc.clean /app
> npx lerna exec -- npx shx rm -rf lib dist typings

sh: 1: node-gyp-build: Permission denied
npm ERR! Maximum call stack size exceeded

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2023-03-02T19_14_48_840Z-debug.log
Install for [ 'lerna@latest' ] failed with code 1
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! root@ tsc.clean: `npx lerna exec -- npx shx rm -rf lib dist typings`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the root@ tsc.clean script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2023-03-02T19_14_49_684Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! root@ clean: `npm run tsc.clean && npx lerna clean -y && npx shx rm -rf node_modules`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the root@ clean script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2023-03-02T19_14_49_717Z-debug.log
The command '/bin/sh -c npm run clean' returned a non-zero code: 1
0x416e746f6e commented 1 year ago

Meanwhile with the following diff it all works:

diff --git a/src/packages/ganache/Dockerfile b/src/packages/ganache/Dockerfile
index 70645d6f..8d36c434 100644
--- a/src/packages/ganache/Dockerfile
+++ b/src/packages/ganache/Dockerfile
@@ -1,9 +1,39 @@
+ARG UID=2000
+ARG GID=2000
+
+ARG INFURA_KEY=00000000000000000000000000000000
+
+# Stage: Prepare build layer ---------------------------------------------------
+
 # use full node to install dependencies
-FROM node:14.17.4@sha256:cd98882c1093f758d09cf6821dc8f96b241073b38e8ed294ca1f9e484743858f AS builder
+FROM node:14.21.3-buster AS base-build

-WORKDIR /app
+ARG UID
+ARG GID
+
+RUN addgroup --gid ${GID} ganache; \
+    adduser --uid ${UID} --gid ${GID} ganache --disabled-password
+
+# Stage: Prepare runtime layer -------------------------------------------------
+
+FROM node:14.21.3-slim AS base-runtime
+
+ARG UID
+ARG GID

-COPY . .
+RUN addgroup --gid ${GID} ganache; \
+    adduser --uid ${UID} --gid ${GID} ganache --disabled-password
+
+# Stage: Build -----------------------------------------------------------------
+
+FROM base-build as builder
+
+ARG UID
+ARG GID
+USER ${UID}
+
+WORKDIR /app
+COPY --chown=${UID}:${GID} . .

 # clean and install dependencies
 RUN npm run clean
@@ -18,16 +48,21 @@ RUN npm run build
 # prune development dependencies
 RUN npx lerna exec --scope ganache -- npm prune --production

-# we use node "slim" instead of "alpine" until we create a uwebsockets build for alpine.
-FROM node:14.17.4-slim@sha256:766e2dcf4461582f7f750656807edbc28019753cecae92b1f2b25d13d3401ef3
+# Stage: Run -------------------------------------------------------------------
+
+FROM base-runtime as runtime
+
+ARG UID
+ARG GID
+USER ${UID}

 WORKDIR /app

 # copy from build image
-COPY --from=builder /app/src/packages/ganache/node_modules node_modules
+COPY --from=builder --chown=${UID}:${GID} /app/src/packages/ganache/node_modules node_modules
 # TODO(perf): we don't need everything in here. Maybe either create a separate
 # build for docker or cherry-pick the files we actually need.
-COPY --from=builder /app/src/packages/ganache/dist/node dist/node
+COPY --from=builder --chown=${UID}:${GID} /app/src/packages/ganache/dist/node dist/node

 ENV DOCKER true
 ENV NODE_ENV production
docker build --tag trufflesuite/ganache --file ./src/packages/ganache/Dockerfile .
[+] Building 264.5s (19/19) FINISHED                                                                                                 
 => [internal] load build definition from Dockerfile                                                                            0.0s
 => => transferring dockerfile: 1.77kB                                                                                          0.0s
 => [internal] load .dockerignore                                                                                               0.0s
 => => transferring context: 2B                                                                                                 0.0s
 => [internal] load metadata for docker.io/library/node:14.21.3-slim                                                            0.0s
 => [internal] load metadata for docker.io/library/node:14.21.3-buster                                                          0.0s
 => [base-build 1/2] FROM docker.io/library/node:14.21.3-buster                                                                 0.0s
 => [base-runtime 1/2] FROM docker.io/library/node:14.21.3-slim                                                                 0.0s
 => CACHED [base-runtime 2/2] RUN addgroup --gid 2000 ganache;     adduser --uid 2000 --gid 2000 ganache --disabled-password    0.0s
 => CACHED [runtime 1/3] WORKDIR /app                                                                                           0.0s
 => [internal] load build context                                                                                               0.1s
 => => transferring context: 136.35kB                                                                                           0.0s
 => CACHED [base-build 2/2] RUN addgroup --gid 2000 ganache;     adduser --uid 2000 --gid 2000 ganache --disabled-password      0.0s
 => CACHED [builder 1/6] WORKDIR /app                                                                                           0.0s
 => [builder 2/6] COPY --chown=2000:2000 . .                                                                                    1.2s
 => [builder 3/6] RUN npm run clean                                                                                           122.7s
 => [builder 4/6] RUN npm ci --unsafe-perm                                                                                     94.6s 
 => [builder 5/6] RUN npm run build                                                                                            39.7s 
 => [builder 6/6] RUN npx lerna exec --scope ganache -- npm prune --production                                                  5.6s 
 => [runtime 2/3] COPY --from=builder --chown=2000:2000 /app/src/packages/ganache/node_modules node_modules                     0.2s 
 => [runtime 3/3] COPY --from=builder --chown=2000:2000 /app/src/packages/ganache/dist/node dist/node                           0.1s 
 => exporting to image                                                                                                          0.1s 
 => => exporting layers                                                                                                         0.1s 
 => => writing image sha256:b8440f6d409a3d355428bb6fd6fbe168309fabad0522f0dbd25427d3b9f3381d                                    0.0s 
 => => naming to docker.io/trufflesuite/ganache                                                                                 0.0s

Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
davidmurdoch commented 1 year ago

Hm, interesting. Maybe updating your Docker installation could do the trick?

0x416e746f6e commented 1 year ago

If I upgrade to latest Docker version 23.0.1, build a5ee5b1, then it's even worse:

[+] Building 3.6s (10/16)                                                                                                              
 => [internal] load build definition from Dockerfile                                                                              0.0s
 => => transferring dockerfile: 1.11kB                                                                                            0.0s
 => [internal] load .dockerignore                                                                                                 0.0s
 => => transferring context: 2B                                                                                                   0.0s
 => [internal] load metadata for docker.io/library/node:14.17.4-slim@sha256:766e2dcf4461582f7f750656807edbc28019753cecae92b1f2b2  1.3s
 => [internal] load metadata for docker.io/library/node:14.17.4@sha256:cd98882c1093f758d09cf6821dc8f96b241073b38e8ed294ca1f9e484  0.0s
 => [builder 1/7] FROM docker.io/library/node:14.17.4@sha256:cd98882c1093f758d09cf6821dc8f96b241073b38e8ed294ca1f9e484743858f     0.0s
 => CANCELED [stage-1 1/4] FROM docker.io/library/node:14.17.4-slim@sha256:766e2dcf4461582f7f750656807edbc28019753cecae92b1f2b25  2.3s
 => => resolve docker.io/library/node:14.17.4-slim@sha256:766e2dcf4461582f7f750656807edbc28019753cecae92b1f2b25d13d3401ef3        0.0s
 => => sha256:766e2dcf4461582f7f750656807edbc28019753cecae92b1f2b25d13d3401ef3 776B / 776B                                        0.0s
 => => sha256:05c6986d66fc6bc3d4a9f834b7f6e0f9d6ece837d4e7f048084371886f10ea6e 1.37kB / 1.37kB                                    0.0s
 => => sha256:0e961fa3b333ae23536203ba2ab5a13798046411b6d5e9b5bd1995babd5668d2 6.89kB / 6.89kB                                    0.0s
 => => sha256:778066204fb734c2fb80cb8127cb35d67d742806a4eaf1aba0b5393c4ae6f2a4 22.53MB / 22.53MB                                  0.4s
 => => sha256:ceb3dca82da7d368ca5d9fd584b0f88713a7e5f94a7b32695e5875445d44ba00 4.17kB / 4.17kB                                    0.4s
 => => sha256:9581178a254a2be081109797260100750af113ca8d3401aa956e4a04a7f0f4b7 35.51MB / 35.51MB                                  0.7s
 => => extracting sha256:778066204fb734c2fb80cb8127cb35d67d742806a4eaf1aba0b5393c4ae6f2a4                                         0.8s
 => => sha256:4c3cfb58978dc6f16cb0011dd9c47b2824f640c6c8a355ccb4f11a6b360b64ef 2.78MB / 2.78MB                                    0.7s
 => => sha256:cf646259b15a5fb428959a60ccc5ad7b645cf37faa1fc1a6f4d96d94dcc3b433 293B / 293B                                        0.5s
 => => extracting sha256:ceb3dca82da7d368ca5d9fd584b0f88713a7e5f94a7b32695e5875445d44ba00                                         0.0s
 => => extracting sha256:9581178a254a2be081109797260100750af113ca8d3401aa956e4a04a7f0f4b7                                         1.0s
 => [internal] load build context                                                                                                 1.4s
 => => transferring context: 378.00MB                                                                                             1.4s
 => [builder 2/7] WORKDIR /app                                                                                                    0.0s
 => [builder 3/7] COPY . .                                                                                                        0.6s
 => ERROR [builder 4/7] RUN npm run clean                                                                                         0.3s
------
 > [builder 4/7] RUN npm run clean:
#0 0.227 runc run failed: unable to start container process: error during container init: unable to apply apparmor profile: apparmor failed to apply profile: write /proc/self/attr/apparmor/exec: no such file or directory
------
Dockerfile:9
--------------------
   7 |     
   8 |     # clean and install dependencies
   9 | >>> RUN npm run clean
  10 |     RUN npm ci --unsafe-perm
  11 |     
--------------------
ERROR: failed to solve: process "/bin/sh -c npm run clean" did not complete successfully: exit code: 1
0x416e746f6e commented 1 year ago

...and then after fixing the apparmor thingy:

[+] Building 34.7s (11/16)                                                                                                             
 => [internal] load build definition from Dockerfile                                                                              0.0s
 => => transferring dockerfile: 1.11kB                                                                                            0.0s
 => [internal] load .dockerignore                                                                                                 0.0s
 => => transferring context: 2B                                                                                                   0.0s
 => [internal] load metadata for docker.io/library/node:14.17.4-slim@sha256:766e2dcf4461582f7f750656807edbc28019753cecae92b1f2b2  0.7s
 => [internal] load metadata for docker.io/library/node:14.17.4@sha256:cd98882c1093f758d09cf6821dc8f96b241073b38e8ed294ca1f9e484  0.0s
 => [builder 1/7] FROM docker.io/library/node:14.17.4@sha256:cd98882c1093f758d09cf6821dc8f96b241073b38e8ed294ca1f9e484743858f     0.0s
 => [stage-1 1/4] FROM docker.io/library/node:14.17.4-slim@sha256:766e2dcf4461582f7f750656807edbc28019753cecae92b1f2b25d13d3401e  3.0s
 => => resolve docker.io/library/node:14.17.4-slim@sha256:766e2dcf4461582f7f750656807edbc28019753cecae92b1f2b25d13d3401ef3        0.0s
 => => sha256:9581178a254a2be081109797260100750af113ca8d3401aa956e4a04a7f0f4b7 35.51MB / 35.51MB                                  1.4s
 => => sha256:766e2dcf4461582f7f750656807edbc28019753cecae92b1f2b25d13d3401ef3 776B / 776B                                        0.0s
 => => sha256:05c6986d66fc6bc3d4a9f834b7f6e0f9d6ece837d4e7f048084371886f10ea6e 1.37kB / 1.37kB                                    0.0s
 => => sha256:0e961fa3b333ae23536203ba2ab5a13798046411b6d5e9b5bd1995babd5668d2 6.89kB / 6.89kB                                    0.0s
 => => sha256:778066204fb734c2fb80cb8127cb35d67d742806a4eaf1aba0b5393c4ae6f2a4 22.53MB / 22.53MB                                  0.4s
 => => sha256:ceb3dca82da7d368ca5d9fd584b0f88713a7e5f94a7b32695e5875445d44ba00 4.17kB / 4.17kB                                    0.4s
 => => sha256:cf646259b15a5fb428959a60ccc5ad7b645cf37faa1fc1a6f4d96d94dcc3b433 293B / 293B                                        0.6s
 => => sha256:4c3cfb58978dc6f16cb0011dd9c47b2824f640c6c8a355ccb4f11a6b360b64ef 2.78MB / 2.78MB                                    1.0s
 => => extracting sha256:778066204fb734c2fb80cb8127cb35d67d742806a4eaf1aba0b5393c4ae6f2a4                                         0.8s
 => => extracting sha256:ceb3dca82da7d368ca5d9fd584b0f88713a7e5f94a7b32695e5875445d44ba00                                         0.0s
 => => extracting sha256:9581178a254a2be081109797260100750af113ca8d3401aa956e4a04a7f0f4b7                                         1.3s
 => => extracting sha256:4c3cfb58978dc6f16cb0011dd9c47b2824f640c6c8a355ccb4f11a6b360b64ef                                         0.1s
 => => extracting sha256:cf646259b15a5fb428959a60ccc5ad7b645cf37faa1fc1a6f4d96d94dcc3b433                                         0.0s
 => [internal] load build context                                                                                                 1.4s
 => => transferring context: 378.00MB                                                                                             1.4s
 => CACHED [builder 2/7] WORKDIR /app                                                                                             0.0s
 => [builder 3/7] COPY . .                                                                                                        0.7s
 => ERROR [builder 4/7] RUN npm run clean                                                                                        31.9s
 => [stage-1 2/4] WORKDIR /app                                                                                                    0.1s
------                                                                                                                                 
 > [builder 4/7] RUN npm run clean:                                                                                                    
#0 0.484                                                                                                                               
#0 0.484 > root@ clean /app                                                                                                            
#0 0.484 > npm run tsc.clean && npx lerna clean -y && npx shx rm -rf node_modules                                                      
#0 0.484                                                                                                                               
#0 0.626 
#0 0.626 > root@ tsc.clean /app
#0 0.626 > npx lerna exec -- npx shx rm -rf lib dist typings
#0 0.626 
#0 31.07 sh: 1: node-gyp-build: Permission denied
#0 31.17 npm ERR! Maximum call stack size exceeded
#0 31.19 
#0 31.19 npm ERR! A complete log of this run can be found in:
#0 31.19 npm ERR!     /root/.npm/_logs/2023-03-02T22_15_55_594Z-debug.log
#0 31.23 Install for [ 'lerna@latest' ] failed with code 1
#0 31.78 npm ERR! code ELIFECYCLE
#0 31.78 npm ERR! errno 1
#0 31.79 npm ERR! root@ tsc.clean: `npx lerna exec -- npx shx rm -rf lib dist typings`
#0 31.79 npm ERR! Exit status 1
#0 31.79 npm ERR! 
#0 31.79 npm ERR! Failed at the root@ tsc.clean script.
#0 31.79 npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
#0 31.79 
#0 31.79 npm ERR! A complete log of this run can be found in:
#0 31.79 npm ERR!     /root/.npm/_logs/2023-03-02T22_15_56_195Z-debug.log
#0 31.80 npm ERR! code ELIFECYCLE
#0 31.80 npm ERR! errno 1
#0 31.81 npm ERR! root@ clean: `npm run tsc.clean && npx lerna clean -y && npx shx rm -rf node_modules`
#0 31.81 npm ERR! Exit status 1
#0 31.81 npm ERR! 
#0 31.81 npm ERR! Failed at the root@ clean script.
#0 31.81 npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
#0 31.81 
#0 31.81 npm ERR! A complete log of this run can be found in:
#0 31.81 npm ERR!     /root/.npm/_logs/2023-03-02T22_15_56_215Z-debug.log
------
Dockerfile:9
--------------------
   7 |     
   8 |     # clean and install dependencies
   9 | >>> RUN npm run clean
  10 |     RUN npm ci --unsafe-perm
  11 |     
--------------------
ERROR: failed to solve: process "/bin/sh -c npm run clean" did not complete successfully: exit code: 1
davidmurdoch commented 1 year ago

Do you think your particular system is in an odd state, since it seems that docker itself was complaining?

0x416e746f6e commented 1 year ago

I tried this on 3 different machies with the same result.

0x416e746f6e commented 1 year ago

meanwhile, the patch quoted above does the trick even for docker 23.0.1..

I will push the PR - you decide.

davidmurdoch commented 1 year ago

Odd. You might need to run npm ci before running the Docker command (an odd step, but that's what our CI does).

I'll look into this more next week.

FYI: we can't use that patch as is, as the node versions would all need to be pinned.

0x416e746f6e commented 1 year ago

is node:14.21.3-buster or node:14.21.3-slim not pinning it enough?

I saw you pin down to digest SHA, but then you build for different platforms (that have different SHA's for their base images). so I am not sure how this is supposed to really work.

0x416e746f6e commented 1 year ago

and adding npm ci does not help either (it just fails with the same error a bit later):

[+] Building 77.3s (14/17)                                                                                                             
 => [internal] load .dockerignore                                                                                                 0.0s
 => => transferring context: 2B                                                                                                   0.0s
 => [internal] load build definition from Dockerfile                                                                              0.0s
 => => transferring dockerfile: 1.12kB                                                                                            0.0s
 => [internal] load metadata for docker.io/library/node:14.17.4-slim@sha256:766e2dcf4461582f7f750656807edbc28019753cecae92b1f2b2  1.2s
 => [internal] load metadata for docker.io/library/node:14.17.4@sha256:cd98882c1093f758d09cf6821dc8f96b241073b38e8ed294ca1f9e484  1.1s
 => [stage-1 1/4] FROM docker.io/library/node:14.17.4-slim@sha256:766e2dcf4461582f7f750656807edbc28019753cecae92b1f2b25d13d3401e  2.9s
 => => resolve docker.io/library/node:14.17.4-slim@sha256:766e2dcf4461582f7f750656807edbc28019753cecae92b1f2b25d13d3401ef3        0.0s
 => => sha256:ceb3dca82da7d368ca5d9fd584b0f88713a7e5f94a7b32695e5875445d44ba00 4.17kB / 4.17kB                                    0.1s
 => => sha256:9581178a254a2be081109797260100750af113ca8d3401aa956e4a04a7f0f4b7 35.51MB / 35.51MB                                  0.7s
 => => sha256:766e2dcf4461582f7f750656807edbc28019753cecae92b1f2b25d13d3401ef3 776B / 776B                                        0.0s
 => => sha256:05c6986d66fc6bc3d4a9f834b7f6e0f9d6ece837d4e7f048084371886f10ea6e 1.37kB / 1.37kB                                    0.0s
 => => sha256:0e961fa3b333ae23536203ba2ab5a13798046411b6d5e9b5bd1995babd5668d2 6.89kB / 6.89kB                                    0.0s
 => => sha256:778066204fb734c2fb80cb8127cb35d67d742806a4eaf1aba0b5393c4ae6f2a4 22.53MB / 22.53MB                                  0.5s
 => => sha256:4c3cfb58978dc6f16cb0011dd9c47b2824f640c6c8a355ccb4f11a6b360b64ef 2.78MB / 2.78MB                                    0.6s
 => => sha256:cf646259b15a5fb428959a60ccc5ad7b645cf37faa1fc1a6f4d96d94dcc3b433 293B / 293B                                        0.7s
 => => extracting sha256:778066204fb734c2fb80cb8127cb35d67d742806a4eaf1aba0b5393c4ae6f2a4                                         0.8s
 => => extracting sha256:ceb3dca82da7d368ca5d9fd584b0f88713a7e5f94a7b32695e5875445d44ba00                                         0.0s
 => => extracting sha256:9581178a254a2be081109797260100750af113ca8d3401aa956e4a04a7f0f4b7                                         1.2s
 => => extracting sha256:4c3cfb58978dc6f16cb0011dd9c47b2824f640c6c8a355ccb4f11a6b360b64ef                                         0.1s
 => => extracting sha256:cf646259b15a5fb428959a60ccc5ad7b645cf37faa1fc1a6f4d96d94dcc3b433                                         0.0s
 => [builder 1/8] FROM docker.io/library/node:14.17.4@sha256:cd98882c1093f758d09cf6821dc8f96b241073b38e8ed294ca1f9e484743858f    12.9s
 => => resolve docker.io/library/node:14.17.4@sha256:cd98882c1093f758d09cf6821dc8f96b241073b38e8ed294ca1f9e484743858f             0.0s
 => => sha256:7528ad312b56c3fde80242e27629841c581ebdc5fa16ade80c75afb37a7ff5cf 7.63kB / 7.63kB                                    0.0s
 => => sha256:cd98882c1093f758d09cf6821dc8f96b241073b38e8ed294ca1f9e484743858f 776B / 776B                                        0.0s
 => => sha256:341976f40d963a425d627a349a9b0034e1eafffbf4c82a173c1465ee403878d9 2.21kB / 2.21kB                                    0.0s
 => => sha256:08224db8ce18b31a78a0a26d1b344d173528e50a7067797c9df4de5d8df353e2 45.38MB / 45.38MB                                  1.3s
 => => sha256:abd3caf86f5b9d8f8e63437571297df5fa6d454140b9c1985c47d6ad526da824 11.29MB / 11.29MB                                  1.3s
 => => sha256:71c316554a558d4aa95c0be17c01e4a0366d6026a98eeba53dca5baa6091e815 4.34MB / 4.34MB                                    1.0s
 => => sha256:721081de66bfc648ce19234c6333d6e031344f6ac90904476c9ec2dba2917e3a 49.76MB / 49.76MB                                 76.1s
 => => extracting sha256:08224db8ce18b31a78a0a26d1b344d173528e50a7067797c9df4de5d8df353e2                                         1.3s
 => => sha256:239fb482263d7865a4a15a52e4a4be892393343c0c4318a930f770d6da32cba0 214.42MB / 214.42MB                                4.2s
 => => sha256:26d24e5f0efd7c5c58ddff4cfec92f90d66e3d2f0c622b21a130dc694690a7f5 4.19kB / 4.19kB                                    1.5s
 => => sha256:5da5632c9c23188d7ca078dbb47f58c9a3b8f8f25bad1b164ac5fafba4511fb8 35.01MB / 35.01MB                                  2.4s
 => => sha256:df05aab91a5a559559bb2e11bab056e426b8fd125d616fb5450e407fdf3445ea 2.34MB / 2.34MB                                    2.6s
 => => sha256:7284fe187258517cc19e44ab4a003a25e9058c606319a885e3df113cafafa31a 294B / 294B                                        3.1s
 => => extracting sha256:abd3caf86f5b9d8f8e63437571297df5fa6d454140b9c1985c47d6ad526da824                                         0.4s
 => => extracting sha256:71c316554a558d4aa95c0be17c01e4a0366d6026a98eeba53dca5baa6091e815                                         0.2s
 => => extracting sha256:721081de66bfc648ce19234c6333d6e031344f6ac90904476c9ec2dba2917e3a                                         1.7s
 => => extracting sha256:239fb482263d7865a4a15a52e4a4be892393343c0c4318a930f770d6da32cba0                                         6.1s
 => => extracting sha256:26d24e5f0efd7c5c58ddff4cfec92f90d66e3d2f0c622b21a130dc694690a7f5                                         0.0s
 => => extracting sha256:5da5632c9c23188d7ca078dbb47f58c9a3b8f8f25bad1b164ac5fafba4511fb8                                         1.2s
 => => extracting sha256:df05aab91a5a559559bb2e11bab056e426b8fd125d616fb5450e407fdf3445ea                                         0.1s
 => => extracting sha256:7284fe187258517cc19e44ab4a003a25e9058c606319a885e3df113cafafa31a                                         0.0s
 => [internal] load build context                                                                                                 1.5s
 => => transferring context: 378.00MB                                                                                             1.5s
 => [stage-1 2/4] WORKDIR /app                                                                                                    0.5s
 => [builder 2/8] WORKDIR /app                                                                                                    0.4s
 => [builder 3/8] COPY . .                                                                                                        0.4s
 => [builder 4/8] RUN npm ci                                                                                                      5.3s
 => [builder 5/8] RUN npm run clean                                                                                               2.5s
 => [builder 6/8] RUN npm ci --unsafe-perm                                                                                       51.2s
 => ERROR [builder 7/8] RUN npm run build                                                                                         3.4s
------
 > [builder 7/8] RUN npm run build:
#0 0.446 
#0 0.446 > root@ build /app
#0 0.446 > npm run tsc && cross-env NODE_OPTIONS=--max_old_space_size=4096 lerna run build
#0 0.446 
#0 0.587 
#0 0.587 > root@ tsc /app
#0 0.587 > tsc --build src
#0 0.587 
#0 1.094 lerna notice cli v4.0.0
#0 1.096 lerna info versioning independent
#0 1.133 lerna info Executing command in 3 packages: "npm run build"
#0 3.349 lerna ERR! npm run build exited 2 in 'ganache'
#0 3.349 lerna ERR! npm run build stdout:
#0 3.350 
#0 3.350 > ganache@7.7.5 build /app/src/packages/ganache
#0 3.350 > npm run tsc && npx shx rm -rf ./dist && webpack && npm run types
#0 3.350 
#0 3.350 
#0 3.350 > ganache@7.7.5 tsc /app/src/packages/ganache
#0 3.350 > tsc --build
#0 3.350 
#0 3.350 lerna ERR! npm run build stderr:
#0 3.350 [webpack-cli] Failed to load '/app/src/packages/ganache/webpack.config.ts' config
#0 3.350 [webpack-cli] Error: The `INFURA_KEY` environment variable was not supplied at build time. To bypass this check set the environment variable `CREATE_BROKEN_BUILD` to `"I WILL NOT PUBLISH THIS"`.
#0 3.350     at Object.<anonymous> (/app/src/packages/ganache/webpack/webpack.common.config.ts:22:9)
#0 3.350     at Module._compile (internal/modules/cjs/loader.js:1072:14)
#0 3.350     at Module.m._compile (/app/src/packages/ganache/node_modules/ts-node/src/index.ts:1618:23)
#0 3.350     at Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
#0 3.350     at Object.require.extensions.<computed> [as .ts] (/app/src/packages/ganache/node_modules/ts-node/src/index.ts:1621:12)
#0 3.350     at Module.load (internal/modules/cjs/loader.js:937:32)
#0 3.350     at Function.Module._load (internal/modules/cjs/loader.js:778:12)
#0 3.350     at Module.require (internal/modules/cjs/loader.js:961:19)
#0 3.350     at require (internal/modules/cjs/helpers.js:92:18)
#0 3.350     at Object.<anonymous> (/app/src/packages/ganache/webpack/webpack.browser.config.ts:1:1)
#0 3.350 npm ERR! code ELIFECYCLE
#0 3.350 npm ERR! errno 2
#0 3.350 npm ERR! ganache@7.7.5 build: `npm run tsc && npx shx rm -rf ./dist && webpack && npm run types`
#0 3.350 npm ERR! Exit status 2
#0 3.350 npm ERR! 
#0 3.350 npm ERR! Failed at the ganache@7.7.5 build script.
#0 3.350 npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
#0 3.350 
#0 3.350 npm ERR! A complete log of this run can be found in:
#0 3.350 npm ERR!     /root/.npm/_logs/2023-03-02T22_46_09_968Z-debug.log
#0 3.350 lerna ERR! npm run build exited 2 in 'ganache'
#0 3.350 lerna WARN complete Waiting for 1 child process to exit. CTRL-C to exit immediately.
#0 3.360 npm ERR! code ELIFECYCLE
#0 3.360 npm ERR! errno 2
#0 3.364 npm ERR! root@ build: `npm run tsc && cross-env NODE_OPTIONS=--max_old_space_size=4096 lerna run build`
#0 3.364 npm ERR! Exit status 2
#0 3.364 npm ERR! 
#0 3.364 npm ERR! Failed at the root@ build script.
#0 3.364 npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
#0 3.366 
#0 3.366 npm ERR! A complete log of this run can be found in:
#0 3.366 npm ERR!     /root/.npm/_logs/2023-03-02T22_46_09_990Z-debug.log
------
Dockerfile:17
--------------------
  15 |     
  16 |     # build application
  17 | >>> RUN npm run build
  18 |     
  19 |     # prune development dependencies
--------------------
ERROR: failed to solve: process "/bin/sh -c npm run build" did not complete successfully: exit code: 2
0x416e746f6e commented 1 year ago

https://github.com/trufflesuite/ganache/pull/4285

jeffsmale90 commented 1 year ago

I was able to reproduce the issue, and it resolved when I installing npm dependencies on the host.

In https://github.com/trufflesuite/ganache/issues/4273#issuecomment-1452669883 it looks like this did resolve the issue, and is now complaining about the INFURA_KEY variable not being set.

#0 3.350 [webpack-cli] Error: The `INFURA_KEY` environment variable was not supplied at build time. To bypass this check set the environment variable `CREATE_BROKEN_BUILD` to `"I WILL NOT PUBLISH THIS"`.
#0 3.350     at Object.<anonymous> (/app/src/packages/ganache/webpack/webpack.common.config.ts:22:9)
#0 3.350     at Module._compile (internal/modules/cjs/loader.js:1072:14)
#0 3.350     at Module.m._compile (/app/src/packages/ganache/node_modules/ts-node/src/index.ts:1618:23)
#0 3.350     at Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
#0 3.350     at Object.require.extensions.<computed> [as .ts] (/app/src/packages/ganache/node_modules/ts-node/src/index.ts:1621:12)
#0 3.350     at Module.load (internal/modules/cjs/loader.js:937:32)
#0 3.350     at Function.Module._load (internal/modules/cjs/loader.js:778:12)
#0 3.350     at Module.require (internal/modules/cjs/loader.js:961:19)
#0 3.350     at require (internal/modules/cjs/helpers.js:92:18)
#0 3.350     at Object.<anonymous> (/app/src/packages/ganache/webpack/webpack.browser.config.ts:1:1)

With npm deps installed, the following works for me: docker build --build-arg="INFURA_KEY=xxx" --tag localganache --file src/packages/ganache/Dockerfile .

There may well be improvements we need to make, but can you please confirm whether this workaround helps?

davidmurdoch commented 1 year ago

Sounds like we need 3 changes:

  1. we should update our node version in our docker file, even if @0x416e746f6e's problem is solved without it.
  2. our README need to be updated to be, you know, actually correct
  3. our Dockerfile needs a way of disabling the INFURA_KEY requirement like we have for npm build.
0x416e746f6e commented 1 year ago

@davidmurdoch the PR that I pushed addresses all 3 points.