Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bcf 3281 ability to deploy node using docker compose #13721

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 2 additions & 38 deletions tools/docker/.env
Original file line number Diff line number Diff line change
@@ -1,40 +1,4 @@
# All of these variables can be overridden by
# setting the same variable within your shell

# Chainlink env vars
# Postgres env vars
CHAINLINK_PGUSER=chainlink-dev
CHAINLINK_DB_NAME=node_dev
CL_DEV=true
CHAINLINK_PGPASSWORD=thispasswordislongenough

# Explorer env vars
EXPLORER_DB_NAME=explorer_dev
EXPLORER_DB_PORT=5432
EXPLORER_PGPASSWORD=explorer
EXPLORER_SERVER_PORT=3001
EXPLORER_COOKIE_SECRET=testingtestingtestingtestingtesting

# Ingester
INGESTER_DB_HOST=chainlink-explorer-db
INGESTER_DB_USERNAME=postgres

# Integration test env vars
SRCROOT=/chainlink

ECHO_SERVER_PORT=6690
ECHO_SERVER_URL=http://echo-server:6690/count

CHAINLINK_PORT=6688
CHAINLINK_URL=http://node:6688
CLIENT_NODE_URL=http://node:6688

CYPRESS_EXPLORER_URL=http://explorer:3001
CYPRESS_JOB_SERVER_HOST=cypress-job-server
CYPRESS_JOB_SERVER_PORT=6692

EXTERNAL_ADAPTER_PORT=6644
EXTERNAL_ADAPTER_URL=http://external-adapter:6644

NODE_1_CONTAINER=chainlink-node
NODE_2_CONTAINER=chainlink-node-2
CLIENT_NODE_2_URL=http://node-2:6688
EXTERNAL_ADAPTER_2_URL=http://external-adapter-2:6644
217 changes: 30 additions & 187 deletions tools/docker/README.md
Original file line number Diff line number Diff line change
@@ -1,159 +1,79 @@
# Using docker-compose for local development

The docker-compose configuration present in this directory allows for a user to quickly setup all of chainlink's services to perform actions like integration tests, acceptance tests, and development across multiple services.
The docker-compose configuration present in this directory allows to quickly run a local development environment.

# Requirements

- [docker-compose](https://docs.docker.com/compose/install/)

# Using the compose script

Inside the `chainlink/tools/docker` directory, there is a helper script that is included which should cover all cases of integration / acceptance / development needs acroos multiple services. To see a list of available commands, perform the following:
Inside the `chainlink/tools/docker` directory, there is a helper script that is included
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this still a part of the sentence?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm updating the sentence to be more clear

To see a list of available commands, perform the following:

```sh
cd tools/docker
./compose help
```

## Examples
## Env vars
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please also explain what ".env" file does in this section?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure


### Acceptance testing

Acceptance can be accomplished by using the `acceptance` command.
You can use the following env vars :
- `GETH_MODE=true` to use geth instead of parity
- `CHAIN_ID=<number>` to specify the chainID (default is 34055 for parity and 1337 for geth)
- `HTTPURL=<url>` to specify the RPC node HTTP url (default is set if you use geth or parity)
- `WSURL=<url>` to specify the RPC node WS url (default is set if you use geth or parity)

for example :
```sh
./compose acceptance
CHAIN_ID=11155111 WSURL=wss://eth.sepolia HTTPURL=https://eth.sepolia ./compose dev
```

- The chainlink node can be reached at `http://localhost:6688`

Credentials for logging into the operator-ui can be found [here](../../tools/secrets/apicredentials)

###
## Dev

### Doing local development on the core node

Doing quick, iterative changes on the core codebase can still be achieved within the compose setup with the `cld` or `cldo` commands.
The `cld` command will bring up the services that a chainlink node needs to connect to (parity/geth, postgres), and then attach the users terminal to a docker container containing the host's chainlink repository bind-mounted inside the container at `/usr/local/src/chainlink`. What this means is that any changes made within the host's repository will be synchronized to the container, and vice versa for changes made within the container at `/usr/local/src/chainlink`.

This enables a user to make quick changes on either the container or the host, run `cldev` within the attached container, check the new behaviour of the re-built node, and repeat this process until the desired results are achieved.
Will run one node with a postgres database and optionally by default a devnet RPC node that can be either geth or parity.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this "optionally" make sense? (I.e., it just runs one node with postgres db and a devnet RPC [parity by default]).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar for "./compose up"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure will commit the changes soon 👍


```sh
./compose cld
#
# Now you are inside the container
cldev # cldev without the "core" postfix simply calls the core node cli
#
# NAME:
# main - CLI for Chainlink
#
# USAGE:
# main [global options] command [command options] [arguments...]
#
# VERSION:
# unset@unset
#
# COMMANDS:
# admin Commands for remotely taking admin related actions
# bridges Commands for Bridges communicating with External Adapters
# config Commands for the node's configuration
# jobs Commands for managing Jobs
# node, local Commands for admin actions that must be run locally
# runs Commands for managing Runs
# txs Commands for handling Ethereum transactions
# agreements, agree Commands for handling service agreements
# attempts, txas Commands for managing Ethereum Transaction Attempts
# createextrakey Create a key in the node's keystore alongside the existing key; to create an original key, just run the node
# initiators Commands for managing External Initiators
# help, h Shows a list of commands or help for one command
#
# GLOBAL OPTIONS:
# --json, -j json output as opposed to table
# --help, -h show help
# --version, -v print the version
cldev core # import our testing key and api credentials, then start the node
#
# ** Importing default key 0x9ca9d2d5e04012c9ed24c0e513c9bfaa4a2dd77f
# 2019-12-11T20:31:18Z [INFO] Locking postgres for exclusive access with 500ms timeout orm/orm.go:74 #
# 2019-12-11T20:31:18Z [WARN] pq: relation "migrations" does not exist migrations/migrate.go:149
# ** Running node
# 2019-12-11T20:31:20Z [INFO] Starting Chainlink Node 0.7.0 at commit 7324e9c476ed6b5c0a08d5a38779d4a6bfbb3880 cmd/local_client.go:27
# ...
# ...
./compose dev
```

### Cleaning up

To remove any containers, volumes, and networks related to our docker-compose setup, we can run the `clean` command:
The chainlink node can be reached at `http://localhost:6688`

```sh
./compose clean
```

### Running your own commands based off of docker-compose

The following commands allow you do just about anything:
Credentials for logging into the operator-ui can be found [here](../../tools/secrets/apicredentials)

```sh
./compose <subcommand>
./compose dev <subcommand>
```
## Up

For example, to see what our compose configuration looks like:
Runs all services including two nodes with two postgres databases and optionally by default a devnet RPC node that can be either geth or parity.

```sh
./compose config # base config
./compose up
```

Or, to run just an ethereum node:
## Cleaning up

```sh
./compose up devnet # start a parity devnet node
```
To remove any containers, volumes, and networks related to our docker-compose setup, we can run the `clean` command:

```sh
GETH_MODE=true ./compose up devnet # start a geth devnet node
./compose clean
```

# Environment Variables

For more information regarding environment variables, the docker [documentation](https://docs.docker.com/compose/environment-variables/) explains it in great detail.
All of the environment variables listed under the `environment` key in each service contains a default entry under the `.env` file of this directory. Additional environment variables can be added by using the `chainlink-variables.env` file. Both files are further expanded upon below.
## Logs

## Overriding existing variables

The existing variables listed under the `environment` key in each service can be overridden by setting a shell environment variable of the same key. For example, referring to `ETH_CHAIN_ID` variable under the `node` service, the default value of `ETH_CHAIN_ID` in `.env` is `34055`. If we wanted to change this to `1337`, we could set a shell variable to override this value.
You can use logs command to see the logs of a specific service or all services.

```sh
export ETH_CHAIN_ID=1337
./compose acceptance # ETH_CHAIN_ID now has the value of 1337, instead of the default value of 34055
./compose logs node # shows the logs of the node service
```

## Adding new environment variables

What if we want to add new environment variables that are not listed under the `environment` key of a service? `docker-compose` provides us with a way to pass our own variables that are not defined under the `environment` key by using an [env_file](https://docs.docker.com/compose/compose-file/#env_file). We can see from our `docker-compose.yaml` file that there is an env file under the name of `chainlink-variables.env`. In this file, you can specify any extra environment variables that you'd like to pass to the associated container.

For example, lets say we want to pass the variable `ALLOW_ORIGINS` defined in `store/orm/schema.go`, so that we can serve our api from a different port without getting CORS errors. We can't pass this in as a shell variable, as the variable is not defined under the `environment` key under the `node` service. What we can do though, is specify `ALLOW_ORIGINS` in `chainlink-variables.env`, which will get passed to the container.

```sh
# assuming that we're in the tools/docker directory

# Add our custom environment variable
echo "ALLOW_ORIGINS=http://localhost:1337" > chainlink-variables.env

# now the node will allow requests from the origin of http://localhost:1337 rather than the default value of http://localhost:3000,http://localhost:6688
./compose acceptance
./compose logs # shows the combined logs of all running services
```

# Following logs

The `logs` command will allow you to follow the logs of any running service. For example:
## Connecting to the dev environment

```bash
./compose up node # starts the node service and all it's dependencies, including devnet, the DB...
./compose logs devnet # shows the blockchain logs
# ^C to exit
./compose logs # shows the combined logs of all running services
```sh
# connect to the container by opening bash prompts
./compose connect
```

# Troubleshooting
Expand Down Expand Up @@ -187,80 +107,3 @@ docker ps
# Follow logs using name of container
docker logs -f chainlink-node
```

## Logging into via the frontend results in HTTP Status Forbidden (403)

This is most likely due to the (Allow Origins access policy](https://docs.chain.link/docs/configuration-variables#section-allow-origins). Make sure you are using 'http://localhost' (not 127.0.0.1), or try disabling ALLOW_ORIGINS.

```
# Disable ALLOW_ORIGINS for testing
echo "ALLOW_ORIGINS=*" >> chainlink-variables.env
```

# Using the dockerized development environment

The dockerized development environment provides an alternative development and testing environment to the docker-compose setup as described above. The goals for this environment are to:

- create a development environment that is easily configured by interview candidates, potential contributors, etc.
- contain all dependencies in a single docker image
- contain sensible, pre-configured defaults

The entire chainlink repo is bind-mounted so any changes will take effect immediately - this makes the env good for TDD. Node modules are also bind-mounted, so you shouldn't have to install many deps after launching the container. Go deps are not bind-mounted, so you will have to install those after starting the container. You should only need to do this once, as long as you re-use the container.

The docker env contains direnv, so whatever changes you make locally to your (bind-mounted) `.envrc` will be reflected in the docker container. The container is built with a default ENV that should require minimal changes for basic testing and development.

### Building the dev environment

```bash
# build the image and tag it as chainlink-develop
docker build ./tools/docker/ -t chainlink-develop:latest -f ./tools/docker/develop.Dockerfile
# create the image
docker container create -v /home/ryan/chainlink/chainlink:/root/chainlink --name chainlink-dev chainlink-develop:latest
# if you want to access the db, chain, node, or from the host... expose the relevant ports
# This could also be used in case you want to run some services in the container, and others directly
# on the host
docker container create -v /home/ryan/chainlink/chainlink:/root/chainlink --name chainlink-dev -p 5432:5432 -p 6688:6688 -p 6689:6689 -p 3000:3000 -p 3001:3001 -p 8545:8545 -p 8546:8546 chainlink-develop:latest
# start the container (this will run in the background until you stop it)
docker start chainlink-dev
```

### Connecting to the dev environment

```bash
# connect to the container by opening bash prompts - you can open as many as you'd like
docker exec -ti chainlink-dev bash
```

### Run services / tests inside container

\$ --> inside container bash prompt

This is nothing new, just a demonstration that you should be able to run all the commands/tests/services you normally do for development/testing, but now inside of the docker container. As mentioned above, if you want access to these services on the host machine, you will have to expose their ports.

```bash
# install deps and chainlink
$ make install

# run go tests
$ make testdb
$ go test ./...

# run evm tests
$ cd contracts
$ pnpm test

# start geth
$ geth --dev --datadir ./tools/gethnet/datadir --mine --ipcdisable --dev.period 2 --unlock 0x9ca9d2d5e04012c9ed24c0e513c9bfaa4a2dd77f --password ./tools/clroot/password.txt --config ./tools/gethnet/config.toml

# run chainlink node (will require changing env vars from defaults)
$ chainlink local node -a ./tools/secrets/apicredentials -p ./tools/secrets/password.txt
```

### Included Tooling:

This image contains the following additional tools:

- geth, openethereum, ganache
- delve, gofuzz
- slither, echidna
- web3.py
3 changes: 0 additions & 3 deletions tools/docker/chainlink-variables.env

This file was deleted.

8 changes: 0 additions & 8 deletions tools/docker/cldev.Dockerfile

This file was deleted.

Loading
Loading