Problem with Dockerized OpenZeppelin add command

npx openzeppelin add results in error message: - Contract Contract.sol not found in path /src/build/contracts/Contract.sol.json

Any suggestions?

:computer: Environment
OpenZeppelin SDK 2.7.1, Docker Engine (MacOS) 19.03.5

:memo:Details
Docker files, Contract.sol etc below all located in same directory

To reproduce:
docker-compose up -d --build app
and
docker logs test_app_1
…to review log

Output from Docker log:

start oz deploy
{
“name”: “src”,
“version”: “1.0.0”,
“description”: “”,
“main”: “index.js”,
“scripts”: {
“test”: “echo “Error: no test specified” && exit 1”
},
“keywords”: ,
“author”: “”,
“license”: “ISC”
}
/src

  • Project initialized. Write a new contract in the contracts folder and run ‘openzeppelin create’ to deploy it.
    {
    “manifestVersion”: “2.2”,
    “contracts”: {},
    “dependencies”: {},
    “name”: “patra”,
    “version”: “0.1.0”,
    “compiler”: {
    “compilerSettings”: {
    “optimizer”: {}
    },
    “typechain”: {
    “enabled”: false
    }
    }
    }
    .:
    total 24
    drwxr-xr-x 1 root root 4096 Feb 28 19:53 .
    drwxr-xr-x 1 root root 4096 Feb 28 19:53 …
    drwxr-xr-x 2 root root 4096 Feb 28 19:53 .openzeppelin
    drwxr-xr-x 1 root root 4096 Feb 28 19:53 contracts
    -rw-r–r-- 1 root root 197 Feb 28 19:53 networks.js
    -rw-r–r-- 1 root root 217 Feb 28 19:53 package.json

./.openzeppelin:
total 12
drwxr-xr-x 2 root root 4096 Feb 28 19:53 .
drwxr-xr-x 1 root root 4096 Feb 28 19:53 …
-rw-r–r-- 1 root root 237 Feb 28 19:53 project.json

./contracts:
total 12
drwxr-xr-x 1 root root 4096 Feb 28 19:53 .
drwxr-xr-x 1 root root 4096 Feb 28 19:53 …
-rw-r–r-- 1 root root 184 Feb 28 19:49 Contract.sol

  • Compiling contracts with solc 0.5.16 (commit.9c3226ce)
  • Compiled contracts with solc 0.5.16 (commit.9c3226ce)
  • Contract Contract.sol not found in path /src/build/contracts/Contract.sol.json

:1234: Code to reproduce
Contract.sol

pragma solidity ^0.5.16;

contract Contract {
  address payable owner;

  // persist contract owner for self-destruct feature
  constructor() public
  {
    owner = msg.sender;
  }
}

docker-compose.yml:

version: “3”
services:
app:
build: .

Dockerfile:
FROM node:10.19-alpine3.9

RUN apk add --update git python g++ make && \

rm -rf /tmp/* /var/cache/apk/*

RUN npm config set unsafe-perm true && npm -g config set user root && npm install -g @openzeppelin/cli@2.7.1

WORKDIR /src/contracts

COPY ./Contract.sol ./

#WORKDIR /src/build/contracts

WORKDIR /src

RUN npm init -y

#COPY ./project.json ./.openzeppelin

CMD echo ‘start oz deploy’ && cat package.json && pwd && npx openzeppelin init patra --no-interactive && cat ./.openzeppelin/project.json && ls -alR && npx openzeppelin add Contract.sol --no-interactive && ls -alR && echo ‘finish oz deploy’

1 Like

Hi @dnesbitt,

Welcome to the community :wave:

We don’t need to use add with the OpenZeppelin CLI, we can go directly to oz create to deploy (or oz deploy in OpenZeppelin CLI 2.8: Release Candidate)

If you want to use src to contain contracts and build/contracts directories you could either use OpenZeppelin CLI in the src directory or change artifactsDir and contractsDir in .openzeppelin/project.json from the detaults:

"artifactsDir": "build/contracts",
"contractsDir": "contracts"

For my projects I generally have OpenZeppelin installed and used in the project root directory, and use the defaults of contracts and build/contracts.

If you need the artifacts you could create a symlink so that the artifacts can be accessed from src. See the example in the guides:
https://docs.openzeppelin.com/learn/sending-gasless-transactions#creating-the-dapp

Feel free to ask all the questions that you need.

Hi @abcoathup, thanks for the feedback. I updated my Docker file to install oz locally and use it from the src dir. I also separately tried copying over the project.json to modify to set the artifactsDir and contractsDir. (Is there a better way to do this? I didn’t see a CLI option to set these). I tried create (2.7.1) and deploy (2.8 RC2) and they fail to complete as below:

v2.7.1 (create)
✓ Compiled contracts with solc 0.5.16 (commit.9c3226ce)
Could not find dependency ./contracts.

V2.8RC2 (deploy)
w/ --kind regular
✓ Compiled contracts with solc 0.5.16 (commit.9c3226ce)
Invalid contract './contracts/Contract.sol'

w/ --kind upgradeable
✓ Compiled contracts with solc 0.5.16 (commit.9c3226ce)
Could not find dependency ./contracts.

Updated Docker files below. I added a Ganache CLI container to use to test deployment.
To build/run: docker-compose -p test -f ./docker-compose.yml up -d

docker-compose.yml:

version: "3"
services:
  devnet:
    image: trufflesuite/ganache-cli:latest
    ports:
      - "8545:8545"
  app:
    build:
      context: .
      dockerfile: ./Dockerfile.test
    volumes:
      - build:./contracts/build
    tty: true
    depends_on:
      - "devnet"
volumes:
  build:

Dockerfile.test:

FROM node:10.19-alpine3.9

RUN apk add --update git python g++ make && \

rm -rf /tmp/* /var/cache/apk/*

WORKDIR /src

RUN npm config set unsafe-perm true && npm config set user root && npm install @openzeppelin/cli@2.8.0-rc.2

#RUN npm config set unsafe-perm true && npm config set user root && npm install @openzeppelin/cli@2.7.1

WORKDIR /src/contracts

COPY ./Contract.sol ./

WORKDIR /src/build/contracts

WORKDIR /src

RUN npm init -y

RUN npx openzeppelin init test --no-interactive

#COPY ./project.json ./.openzeppelin

COPY ./networks.js ./

#CMD echo 'start oz deploy' && cat package.json && pwd && cat ./networks.js && cat ./.openzeppelin/project.json && npx openzeppelin create ./contracts/Contract.sol --no-interactive --network local && ls -alR ./contracts && echo 'finish oz deploy'

CMD echo 'start oz deploy' && cat package.json && pwd && cat ./networks.js && cat ./.openzeppelin/project.json && npx openzeppelin deploy ./contracts/Contract.sol --kind regular --no-interactive --network local && ls -alR ./contracts && echo 'finish oz deploy'
1 Like

Hi @dnesbitt,

I was able to deploy using the following.

deploy takes the contract name (in my case Box, see contract below).
The default network.js has a development network.

$ npx oz deploy Box --no-interactive --kind regular --network development
✓ Compiled contracts with solc 0.5.16 (commit.9c3226ce)
✓ Deployed instance of Box
0xc021b01489d08d82b79054941b44a39bB6c4F58F

In your docker script you specify the contract location rather than its name. I assume that you have a local network declared in your network.js

Box.sol

// contracts/Box.sol
pragma solidity ^0.5.0;

contract Box {
    uint256 private value;

    // Emitted when the stored value changes
    event ValueChanged(uint256 newValue);

    // Stores a new value in the contract
    function store(uint256 newValue) public {
        value = newValue;
        emit ValueChanged(newValue);
    }

    // Reads the last stored value
    function retrieve() public view returns (uint256) {
        return value;
    }
}

network.js

module.exports = {
  networks: {
    development: {
      protocol: 'http',
      host: 'localhost',
      port: 8545,
      gas: 5000000,
      gasPrice: 5e9,
      networkId: '*',
    },
  },
};

Hi @dnesbitt,

I wanted to check if the above worked for you in Docker?

I was also curious about your setup. Would you mind sharing why you use Docker for your setup?

Hi @abcoathup, yes this worked for me. Thanks for clarifying that the CLI parameter for deploy is the contract name, I had misunderstood this to be filename.

With v2.8 RC2 deploy with the Box contract works with the --kind regular, however with the --kind upgradeable it fails as follows:

✓ Compiled contracts with solc 0.5.16 (commit.9c3226ce)
Contract Box not found in this project

Is this expected behavior?

With regards to Docker question, the intended application is a scalable, cloud deployed application which requires Docker containerization.

1 Like

@abcoathup Actually this is not a Docker issue, it is a general problem with the non-interactive usage of oz deploy with --kind upgradeable (with --kind regular it works as expected as you demonstrated).

For instance (with v2.8) from CLI in a terminal…

Non-interactive version fails:

npx oz init
? Welcome to the OpenZeppelin SDK! Choose a name for your project test
? Initial project version 1.0.0
Project initialized. Write a new contract in the contracts folder and run ‘openzeppelin deploy’ to deploy it.
% npx openzeppelin deploy Box --kind upgradeable --no-interactive --network development
✓ Compiled contracts with solc 0.5.17 (commit.d19bba13)
Contract Box not found in this project

Interactive version works as expected:
% npx oz init
? Welcome to the OpenZeppelin SDK! Choose a name for your project test
? Initial project version 1.0.0
Project initialized. Write a new contract in the contracts folder and run ‘openzeppelin deploy’ to deploy it.
% npx oz deploy
✓ Compiled contracts with solc 0.5.17 (commit.d19bba13)
? Choose the kind of deployment upgradeable
? Pick a network development
? Pick a contract to deploy Box
✓ Added contract Box
✓ Contract Box deployed
All implementations have been deployed
? Call a function to initialize the instance after creating it? Yes
? Select which function store(newValue: uint256)
? newValue: uint256: 1
✓ Setting everything up to create contract instances
✓ Instance created at 0x26b4AFb60d6C903165150C6F0AA14F8016bE4aec
0x26b4AFb60d6C903165150C6F0AA14F8016bE4aec

Interestingly, if I do oz init, then the interactive deploy then the non-interactive way in a consecutive sequence then the non-interactive option works

% npx oz init
? Welcome to the OpenZeppelin SDK! Choose a name for your project test
? Initial project version 1.0.0
Project initialized. Write a new contract in the contracts folder and run ‘openzeppelin deploy’ to deploy it.
% npx oz deploy
✓ Compiled contracts with solc 0.5.17 (commit.d19bba13)
? Choose the kind of deployment upgradeable
? Pick a network development
? Pick a contract to deploy Box
✓ Added contract Box
✓ Contract Box deployed
All implementations have been deployed
? Call a function to initialize the instance after creating it? Yes
? Select which function store(newValue: uint256)
? newValue: uint256: 1
✓ Setting everything up to create contract instances
✓ Instance created at 0xFC628dd79137395F3C9744e33b1c5DE554D94882
0xFC628dd79137395F3C9744e33b1c5DE554D94882
% npx oz deploy Box --kind upgradeable --no-interactive --network development
Nothing to compile, all contracts are up to date.
✓ Instance created at 0x5f8e26fAcC23FA4cbd87b8d9Dbbd33D5047abDE1
0x5f8e26fAcC23FA4cbd87b8d9Dbbd33D5047abDE1

1 Like

Submitted as issue #1518

1 Like

A post was split to a new topic: OpenZeppelin CLI and docker: Could not connect to the development Ethereum network on http://localhost:8545