From 132120794822370887f9c224b50b993a5d24fdfa Mon Sep 17 00:00:00 2001 From: Clement Erena Date: Fri, 28 Jun 2024 16:08:28 +0200 Subject: [PATCH 1/7] feat(docker): upgrade to new docker compose version --- tools/docker/.env | 3 ++- tools/docker/docker-compose.deps.yaml | 2 +- tools/docker/docker-compose.dev.yaml | 2 +- tools/docker/docker-compose.gethnet.local.yaml | 2 +- tools/docker/docker-compose.gethnet.yaml | 2 +- tools/docker/docker-compose.paritynet.local.yaml | 2 +- tools/docker/docker-compose.paritynet.yaml | 2 +- tools/docker/docker-compose.postgres.yaml | 12 +++++++----- tools/docker/docker-compose.yaml | 2 +- tools/docker/wait-postgres.Dockerfile | 2 +- 10 files changed, 17 insertions(+), 14 deletions(-) diff --git a/tools/docker/.env b/tools/docker/.env index 05f4314ff22..c8e8f4a4507 100644 --- a/tools/docker/.env +++ b/tools/docker/.env @@ -2,8 +2,9 @@ # setting the same variable within your shell # Chainlink env vars -CHAINLINK_DB_NAME=node_dev CL_DEV=true +CHAINLINK_PGUSER=chainlink-dev +CHAINLINK_DB_NAME=node_dev CHAINLINK_PGPASSWORD=thispasswordislongenough # Explorer env vars diff --git a/tools/docker/docker-compose.deps.yaml b/tools/docker/docker-compose.deps.yaml index 43071e152ac..91861c91dde 100644 --- a/tools/docker/docker-compose.deps.yaml +++ b/tools/docker/docker-compose.deps.yaml @@ -1,4 +1,4 @@ -version: '3.5' +version: '3.8' services: wait-db: diff --git a/tools/docker/docker-compose.dev.yaml b/tools/docker/docker-compose.dev.yaml index 2138d1c2af9..dede89d1d3c 100644 --- a/tools/docker/docker-compose.dev.yaml +++ b/tools/docker/docker-compose.dev.yaml @@ -1,4 +1,4 @@ -version: '3.5' +version: '3.8' services: node: entrypoint: '/bin/sh -c "while sleep 1000; do :; done"' diff --git a/tools/docker/docker-compose.gethnet.local.yaml b/tools/docker/docker-compose.gethnet.local.yaml index ae2a1e17007..5d240604459 100644 --- a/tools/docker/docker-compose.gethnet.local.yaml +++ b/tools/docker/docker-compose.gethnet.local.yaml @@ -1,4 +1,4 @@ -version: '3.5' +version: '3.8' services: node: diff --git a/tools/docker/docker-compose.gethnet.yaml b/tools/docker/docker-compose.gethnet.yaml index 6ab388dc8f9..d0bb8e5e304 100644 --- a/tools/docker/docker-compose.gethnet.yaml +++ b/tools/docker/docker-compose.gethnet.yaml @@ -1,4 +1,4 @@ -version: '3.5' +version: '3.8' services: node: diff --git a/tools/docker/docker-compose.paritynet.local.yaml b/tools/docker/docker-compose.paritynet.local.yaml index 518e2cce4f2..543da2d94ae 100644 --- a/tools/docker/docker-compose.paritynet.local.yaml +++ b/tools/docker/docker-compose.paritynet.local.yaml @@ -1,4 +1,4 @@ -version: '3.5' +version: '3.8' services: node: diff --git a/tools/docker/docker-compose.paritynet.yaml b/tools/docker/docker-compose.paritynet.yaml index b5e6a6311ed..07bcec41276 100644 --- a/tools/docker/docker-compose.paritynet.yaml +++ b/tools/docker/docker-compose.paritynet.yaml @@ -1,4 +1,4 @@ -version: '3.5' +version: '3.8' services: node: diff --git a/tools/docker/docker-compose.postgres.yaml b/tools/docker/docker-compose.postgres.yaml index d7356897b96..f038a408dc3 100644 --- a/tools/docker/docker-compose.postgres.yaml +++ b/tools/docker/docker-compose.postgres.yaml @@ -1,33 +1,35 @@ -version: '3.5' +version: '3.8' services: node: depends_on: - node-db environment: - - CL_DATABASE_URL=postgresql://postgres:$CHAINLINK_PGPASSWORD@node-db:5432/$CHAINLINK_DB_NAME?sslmode=disable + - CL_DATABASE_URL=postgresql://$CHAINLINK_PGUSER:$CHAINLINK_PGPASSWORD@node-db:5432/$CHAINLINK_DB_NAME?sslmode=disable node-2: depends_on: - node-db-2 environment: - - CL_DATABASE_URL=postgresql://postgres:$CHAINLINK_PGPASSWORD@node-db-2:5432/$CHAINLINK_DB_NAME?sslmode=disable + - CL_DATABASE_URL=postgresql://$CHAINLINK_PGUSER:$CHAINLINK_PGPASSWORD@node-db-2:5432/$CHAINLINK_DB_NAME?sslmode=disable node-db: container_name: chainlink-db - image: postgres:14 + image: postgres:15 volumes: - node-db-data:/var/lib/postgresql/data environment: + POSTGRES_USER: $CHAINLINK_PGUSER POSTGRES_DB: $CHAINLINK_DB_NAME POSTGRES_PASSWORD: $CHAINLINK_PGPASSWORD node-db-2: container_name: chainlink-db-2 - image: postgres:14 + image: postgres:15 volumes: - node-db-2-data:/var/lib/postgresql/data environment: + POSTGRES_USER: $CHAINLINK_PGUSER POSTGRES_DB: $CHAINLINK_DB_NAME POSTGRES_PASSWORD: $CHAINLINK_PGPASSWORD diff --git a/tools/docker/docker-compose.yaml b/tools/docker/docker-compose.yaml index c01d3579356..ffae94de14b 100644 --- a/tools/docker/docker-compose.yaml +++ b/tools/docker/docker-compose.yaml @@ -1,4 +1,4 @@ -version: '3.5' +version: '3.8' services: node: diff --git a/tools/docker/wait-postgres.Dockerfile b/tools/docker/wait-postgres.Dockerfile index b663d131beb..668ada67402 100644 --- a/tools/docker/wait-postgres.Dockerfile +++ b/tools/docker/wait-postgres.Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:18.04 +FROM ubuntu:22 RUN apt-get update RUN apt-get install -y postgresql-client From 37dfbe3248c41d4ccae05063d128c23e4aa72159 Mon Sep 17 00:00:00 2001 From: Clement Erena Date: Fri, 28 Jun 2024 16:09:03 +0200 Subject: [PATCH 2/7] fix(docker): update name to avoid duplicate with core node --- tools/docker/docker-compose.dev.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/docker/docker-compose.dev.yaml b/tools/docker/docker-compose.dev.yaml index dede89d1d3c..542dfac945f 100644 --- a/tools/docker/docker-compose.dev.yaml +++ b/tools/docker/docker-compose.dev.yaml @@ -1,6 +1,6 @@ version: '3.8' services: - node: + cldev: entrypoint: '/bin/sh -c "while sleep 1000; do :; done"' build: context: ../../ From a1298a6a2ba8c57442d775c813642705b4bda52a Mon Sep 17 00:00:00 2001 From: Clement Erena Date: Mon, 1 Jul 2024 11:11:38 +0200 Subject: [PATCH 3/7] feat(docker): remove unused env vars --- tools/docker/.env | 33 +-------------------------------- 1 file changed, 1 insertion(+), 32 deletions(-) diff --git a/tools/docker/.env b/tools/docker/.env index c8e8f4a4507..c4af4e93627 100644 --- a/tools/docker/.env +++ b/tools/docker/.env @@ -1,41 +1,10 @@ # All of these variables can be overridden by # setting the same variable within your shell -# Chainlink env vars -CL_DEV=true +# Postgres env vars CHAINLINK_PGUSER=chainlink-dev CHAINLINK_DB_NAME=node_dev 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 From abca1376e3950d334fe9cd2a11e32416dc2f3ea8 Mon Sep 17 00:00:00 2001 From: Clement Erena Date: Tue, 2 Jul 2024 12:30:04 +0200 Subject: [PATCH 4/7] feat(docker): enable dev mode with rebuild + cleanup --- tools/docker/cldev.Dockerfile | 8 --- tools/docker/compose | 39 +++++--------- tools/docker/develop.Dockerfile | 66 ----------------------- tools/docker/docker-compose.dev.yaml | 16 ++---- tools/docker/docker-compose.postgres.yaml | 4 +- tools/docker/docker-compose.yaml | 8 --- tools/docker/wait-for-postgres.sh | 15 ------ tools/docker/wait-postgres.Dockerfile | 7 --- 8 files changed, 21 insertions(+), 142 deletions(-) delete mode 100644 tools/docker/cldev.Dockerfile delete mode 100644 tools/docker/develop.Dockerfile delete mode 100755 tools/docker/wait-for-postgres.sh delete mode 100644 tools/docker/wait-postgres.Dockerfile diff --git a/tools/docker/cldev.Dockerfile b/tools/docker/cldev.Dockerfile deleted file mode 100644 index 72f2f06d7ce..00000000000 --- a/tools/docker/cldev.Dockerfile +++ /dev/null @@ -1,8 +0,0 @@ -FROM golang:1.21-bullseye - -ARG SRCROOT=/usr/local/src/chainlink -WORKDIR ${SRCROOT} - -ADD go.* ./ -RUN go mod download -RUN mkdir -p tools/bin diff --git a/tools/docker/compose b/tools/docker/compose index b16c1e19332..6039f2b0a7f 100755 --- a/tools/docker/compose +++ b/tools/docker/compose @@ -1,5 +1,4 @@ -#!/usr/bin/env bash -set -ex +#!/bin/sh export DOCKER_BUILDKIT=1 export COMPOSE_DOCKER_CLI_BUILD=1 @@ -12,32 +11,26 @@ else base_files="$base_files -f docker-compose.paritynet.yaml" fi -base="docker-compose $base_files" # base config, used standalone for acceptance -dev="$base -f docker-compose.dev.yaml" # config for cldev +base="docker-compose $base_files" +dev="$base -f docker-compose.dev.yaml" clean_docker() { $base down -v --remove-orphans $dev down -v --remove-orphans } -function usage() { +usage() { echo "compose -- A helper script for running common docker-compose commands\ Commands: help Displays this help menu clean Remove any containers and volumes related to compose files logs Display the logs of any service(s) by name - - cld Runs the chainlink node container in dev mode - - acceptance Run the services required to perform an acceptance test - - dev Run docker-compose with dev config for the core node - - eth:restart Reset blockchain data to genesis state - cl:restart Reset chainlink database - - * Run docker-compose with base config" + dev Runs the chainlink node container in dev mode + connect Connect to chainlink node container + up Run the chainlink cluster with base config + eth:restart Reset blockchain data to genesis state + cl:restart Reset chainlink database" } case "$1" in @@ -50,21 +43,17 @@ clean) logs) $base logs -f ${@:2} ;; -cld) +dev) $dev build $dev up -d node + $dev watch --no-up node + ;; +connect) docker exec -it chainlink-node bash - $dev down -v --remove-orphans ;; - -acceptance) +up) $base up ;; - -dev) - $dev ${@:2} - ;; - eth:restart) $base rm --force --stop devnet if [ $GETH_MODE ]; then diff --git a/tools/docker/develop.Dockerfile b/tools/docker/develop.Dockerfile deleted file mode 100644 index f663eaf1cf2..00000000000 --- a/tools/docker/develop.Dockerfile +++ /dev/null @@ -1,66 +0,0 @@ -FROM ubuntu:20.04 - -# Add the PostgreSQL PGP key & repository -RUN apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8 -RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" > /etc/apt/sources.list.d/pgdg.list - -# Install deps -RUN apt-get update && apt-get install -y postgresql postgresql-contrib direnv build-essential cmake libudev-dev unzip - -# Install additional tooling -RUN mkdir -p ~/.local/bin/ -ENV PATH="/root/.local/bin:${PATH}" -RUN go get github.com/go-delve/delve/cmd/dlv -RUN go get github.com/google/gofuzz -RUN pnpm install -g ganache-cli -RUN pip3 install web3 slither-analyzer crytic-compile -RUN curl -L https://github.com/crytic/echidna/releases/download/v1.5.1/echidna-test-v1.5.1-Ubuntu-18.04.tar.gz | tar -xz -C ~/.local/bin -RUN curl -L https://github.com/openethereum/openethereum/releases/download/v3.2.4/openethereum-linux-v3.2.4.zip --output openethereum.zip -RUN unzip openethereum.zip -d ~/.local/bin/ && rm openethereum.zip -RUN chmod +x ~/.local/bin/* - -# Setup direnv -RUN echo 'eval "$(direnv hook bash)"' > /root/.bashrc - -# Setup postgres -USER postgres -RUN echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/10/main/pg_hba.conf -RUN echo "listen_addresses='*'" >> /etc/postgresql/10/main/postgresql.conf -RUN /etc/init.d/postgresql start &&\ - createdb chainlink_test &&\ - createdb node_dev &&\ - createuser --superuser --no-password root &&\ - psql -c "ALTER USER postgres PASSWORD 'node';" - -USER root - -# add init file - this file starts postgres and keeps container alive after started -RUN touch ~/init -RUN chmod +x ~/init -RUN echo "#!/usr/local/bin/dumb-init /bin/sh" >> ~/init -RUN echo "/etc/init.d/postgresql start" >> ~/init -RUN echo "while true; do sleep 1; done" >> ~/init - -ARG SRCROOT=/root/chainlink -WORKDIR ${SRCROOT} - -EXPOSE 5432 -EXPOSE 6688 -EXPOSE 6689 -EXPOSE 3000 -EXPOSE 3001 -EXPOSE 8545 -EXPOSE 8546 - -# Default env setup for testing -ENV CHAINLINK_DB_NAME chainlink_test -ENV CHAINLINK_PGPASSWORD=thispasswordislongenough -ENV CL_DATABASE_URL=postgresql://postgres:$CHAINLINK_PGPASSWORD@localhost:5432/$CHAINLINK_DB_NAME?sslmode=disable -ENV TYPEORM_USERNAME=postgres -ENV TYPEORM_PASSWORD=node -ENV ETH_CHAIN_ID=1337 -ENV CHAINLINK_DEV=true -ENV CHAINLINK_TLS_PORT=0 -ENV SECURE_COOKIES=false - -ENTRYPOINT [ "/root/init" ] diff --git a/tools/docker/docker-compose.dev.yaml b/tools/docker/docker-compose.dev.yaml index 542dfac945f..b74cb74ecb7 100644 --- a/tools/docker/docker-compose.dev.yaml +++ b/tools/docker/docker-compose.dev.yaml @@ -1,13 +1,7 @@ version: '3.8' services: - cldev: - entrypoint: '/bin/sh -c "while sleep 1000; do :; done"' - build: - context: ../../ - dockerfile: tools/docker/cldev.Dockerfile - args: - - SRCROOT - command: '' - image: smartcontract/chainlink-dev - volumes: - - ../..:$SRCROOT + node: + develop: + watch: + - action: rebuild + path: ../../core \ No newline at end of file diff --git a/tools/docker/docker-compose.postgres.yaml b/tools/docker/docker-compose.postgres.yaml index f038a408dc3..87f6f261d4d 100644 --- a/tools/docker/docker-compose.postgres.yaml +++ b/tools/docker/docker-compose.postgres.yaml @@ -15,7 +15,7 @@ services: node-db: container_name: chainlink-db - image: postgres:15 + image: postgres:16 volumes: - node-db-data:/var/lib/postgresql/data environment: @@ -25,7 +25,7 @@ services: node-db-2: container_name: chainlink-db-2 - image: postgres:15 + image: postgres:16 volumes: - node-db-2-data:/var/lib/postgresql/data environment: diff --git a/tools/docker/docker-compose.yaml b/tools/docker/docker-compose.yaml index ffae94de14b..a8630f1dd67 100644 --- a/tools/docker/docker-compose.yaml +++ b/tools/docker/docker-compose.yaml @@ -12,8 +12,6 @@ services: # parity/geth node to be prefunded with eth. entrypoint: /bin/sh -c "chainlink -c /run/secrets/config node start -d -p /run/secrets/node_password -a /run/secrets/apicredentials" restart: always - environment: - - CL_DATABASE_URL env_file: - chainlink-variables.env ports: @@ -32,8 +30,6 @@ services: dockerfile: core/chainlink.Dockerfile entrypoint: /bin/sh -c "chainlink -c /run/secrets/config node start -d -p /run/secrets/node_password -a /run/secrets/apicredentials" restart: always - environment: - - CL_DATABASE_URL env_file: - chainlink-variables.env ports: @@ -44,10 +40,6 @@ services: - keystore - config -# TODO -# - replace clroot with secrets -# - extract tools into separate docker-compose files - secrets: node_password: file: ../clroot/password.txt diff --git a/tools/docker/wait-for-postgres.sh b/tools/docker/wait-for-postgres.sh deleted file mode 100755 index b7548085d00..00000000000 --- a/tools/docker/wait-for-postgres.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env bash - -RETRIES=5 -THRESHOLD=2 - -until [ $THRESHOLD -eq 0 ] || [ $RETRIES -eq 0 ]; do - if pg_isready $@; then - ((THRESHOLD--)) - fi - echo "Waiting for postgres server, $((RETRIES--)) remaining attempts..." - sleep 2 -done - -if [ $THRESHOLD -eq 0 ]; then exit 0; fi -exit 1 diff --git a/tools/docker/wait-postgres.Dockerfile b/tools/docker/wait-postgres.Dockerfile deleted file mode 100644 index 668ada67402..00000000000 --- a/tools/docker/wait-postgres.Dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -FROM ubuntu:22 - -RUN apt-get update -RUN apt-get install -y postgresql-client -COPY wait-for-postgres.sh /bin/wait-for-postgres - -ENTRYPOINT ["wait-for-postgres"] \ No newline at end of file From 3b441cacb2de818b3c8edcd313a59a2ff285dc0d Mon Sep 17 00:00:00 2001 From: Clement Erena Date: Thu, 4 Jul 2024 16:07:44 +0200 Subject: [PATCH 5/7] feat(docker): cleanup and update README --- tools/docker/.env | 6 - tools/docker/README.md | 217 +++--------------- tools/docker/chainlink-variables.env | 3 - tools/docker/compose | 48 +++- .../docker/{config.toml => config.toml.tmpl} | 8 +- tools/docker/docker-compose.deps.yaml | 21 -- tools/docker/docker-compose.dev.yaml | 11 +- .../docker/docker-compose.gethnet.local.yaml | 4 - tools/docker/docker-compose.gethnet.yaml | 4 - tools/docker/docker-compose.yaml | 4 +- 10 files changed, 82 insertions(+), 244 deletions(-) delete mode 100644 tools/docker/chainlink-variables.env rename tools/docker/{config.toml => config.toml.tmpl} (70%) delete mode 100644 tools/docker/docker-compose.deps.yaml diff --git a/tools/docker/.env b/tools/docker/.env index c4af4e93627..35583b43636 100644 --- a/tools/docker/.env +++ b/tools/docker/.env @@ -1,10 +1,4 @@ -# All of these variables can be overridden by -# setting the same variable within your shell - # Postgres env vars CHAINLINK_PGUSER=chainlink-dev CHAINLINK_DB_NAME=node_dev CHAINLINK_PGPASSWORD=thispasswordislongenough - -# Integration test env vars -SRCROOT=/chainlink diff --git a/tools/docker/README.md b/tools/docker/README.md index 58c1e196699..28d30e6e0e5 100644 --- a/tools/docker/README.md +++ b/tools/docker/README.md @@ -1,6 +1,6 @@ # 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 @@ -8,152 +8,72 @@ The docker-compose configuration present in this directory allows for a user to # 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 +To see a list of available commands, perform the following: ```sh cd tools/docker ./compose help ``` -## Examples +## Env vars -### 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=` to specify the chainID (default is 34055 for parity and 1337 for geth) +- `HTTPURL=` to specify the RPC node HTTP url (default is set if you use geth or parity) +- `WSURL=` 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. ```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 -./compose dev -``` +## 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 @@ -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 diff --git a/tools/docker/chainlink-variables.env b/tools/docker/chainlink-variables.env deleted file mode 100644 index c9495248925..00000000000 --- a/tools/docker/chainlink-variables.env +++ /dev/null @@ -1,3 +0,0 @@ -# Add in your environment variables here -# if you want to add more environment variables not listed -# in .env diff --git a/tools/docker/compose b/tools/docker/compose index 6039f2b0a7f..0e754a5ffcb 100755 --- a/tools/docker/compose +++ b/tools/docker/compose @@ -4,19 +4,44 @@ export DOCKER_BUILDKIT=1 export COMPOSE_DOCKER_CLI_BUILD=1 base_files="-f docker-compose.yaml -f docker-compose.postgres.yaml" -# Allow for choosing between geth or parity -if [ $GETH_MODE ]; then - base_files="$base_files -f docker-compose.gethnet.yaml" -else - base_files="$base_files -f docker-compose.paritynet.yaml" + +# No RPC URL provided, default to Devnet +if [ -z "$WSURL" ] && [ -z "$HTTPURL" ]; then + # Allow for choosing between geth or parity + if [ "$GETH_MODE" ]; then + export CHAIN_ID=1337 + base_files="$base_files -f docker-compose.gethnet.yaml" + else + base_files="$base_files -f docker-compose.paritynet.yaml" + fi fi base="docker-compose $base_files" dev="$base -f docker-compose.dev.yaml" +configure() { + if [ -z "$CHAIN_ID" ]; then + export CHAIN_ID=34055 + fi + + if [ -z "$WSURL" ]; then + export WSURL="ws://devnet:8546" + fi + + if [ -z "$HTTPURL" ]; then + export HTTPURL="http://devnet:8545" + fi + + sed -e "s/SET_CHAIN_ID/$CHAIN_ID/" \ + -e "s,SET_WSURL,$WSURL," \ + -e "s,SET_HTTPURL,$HTTPURL," \ + config.toml.tmpl > config.toml +} + clean_docker() { $base down -v --remove-orphans $dev down -v --remove-orphans + rm -f config.toml } usage() { @@ -30,7 +55,7 @@ Commands: connect Connect to chainlink node container up Run the chainlink cluster with base config eth:restart Reset blockchain data to genesis state - cl:restart Reset chainlink database" + db:restart Reset chainlink database" } case "$1" in @@ -41,9 +66,10 @@ clean) clean_docker ;; logs) - $base logs -f ${@:2} + $base logs -f "${@:2}" ;; dev) + configure $dev build $dev up -d node $dev watch --no-up node @@ -52,25 +78,23 @@ connect) docker exec -it chainlink-node bash ;; up) + configure $base up ;; eth:restart) $base rm --force --stop devnet - if [ $GETH_MODE ]; then + if [ "$GETH_MODE" ]; then docker volume rm --force docker_geth-db-data else docker volume rm --force docker_parity-db-data fi $base up -d devnet ;; -cl:restart) +db:restart) $base stop node $base rm --force --stop node-db docker volume rm --force docker_node-db-data ./compose eth:restart $base start node ;; -*) - $base $@ - ;; esac diff --git a/tools/docker/config.toml b/tools/docker/config.toml.tmpl similarity index 70% rename from tools/docker/config.toml rename to tools/docker/config.toml.tmpl index 23108ae295c..abd38981adb 100644 --- a/tools/docker/config.toml +++ b/tools/docker/config.toml.tmpl @@ -12,11 +12,11 @@ HTTPSPort = 0 DefaultTimeout = '5s' [[EVM]] -ChainID = '34055' +ChainID = 'SET_CHAIN_ID' MinIncomingConfirmations = 1 MinContractPayment = '0.000001 link' [[EVM.Nodes]] -Name = 'primary-0-34055' -WSURL = 'ws://devnet:8546' -HTTPURL = 'http://devnet:8545' +Name = 'primary-0-SET_CHAIN_ID' +WSURL = 'SET_WSURL' +HTTPURL = 'SET_HTTPURL' diff --git a/tools/docker/docker-compose.deps.yaml b/tools/docker/docker-compose.deps.yaml deleted file mode 100644 index 91861c91dde..00000000000 --- a/tools/docker/docker-compose.deps.yaml +++ /dev/null @@ -1,21 +0,0 @@ -version: '3.8' - -services: - wait-db: - container_name: wait-for-db - build: - context: . - dockerfile: wait-postgres.Dockerfile - command: '-h node-db -p 5432 -U postgres -d $CHAINLINK_DB_NAME --timeout=600' - depends_on: - - node-db - wait-db-2: - container_name: wait-for-db-2 - build: - context: . - dockerfile: wait-postgres.Dockerfile - command: '-h node-db-2 -p 5432 -U postgres -d $CHAINLINK_DB_NAME --timeout=600' - depends_on: - - node-db-2 -volumes: - node-db-data: diff --git a/tools/docker/docker-compose.dev.yaml b/tools/docker/docker-compose.dev.yaml index b74cb74ecb7..58f798d9efe 100644 --- a/tools/docker/docker-compose.dev.yaml +++ b/tools/docker/docker-compose.dev.yaml @@ -4,4 +4,13 @@ services: develop: watch: - action: rebuild - path: ../../core \ No newline at end of file + path: ../../ + ignore: + - '.changeset/' + - '.github/' + - 'charts/' + - 'core/sgx/target/' + - 'docs/' + - 'fuzz/' + - 'integration-tests/' + - 'tools/' \ No newline at end of file diff --git a/tools/docker/docker-compose.gethnet.local.yaml b/tools/docker/docker-compose.gethnet.local.yaml index 5d240604459..d4d1544cf44 100644 --- a/tools/docker/docker-compose.gethnet.local.yaml +++ b/tools/docker/docker-compose.gethnet.local.yaml @@ -2,13 +2,9 @@ version: '3.8' services: node: - environment: - - ETH_CHAIN_ID=1337 depends_on: - devnet node-2: - environment: - - ETH_CHAIN_ID=1337 depends_on: - devnet devnet: diff --git a/tools/docker/docker-compose.gethnet.yaml b/tools/docker/docker-compose.gethnet.yaml index d0bb8e5e304..9c9106556c6 100644 --- a/tools/docker/docker-compose.gethnet.yaml +++ b/tools/docker/docker-compose.gethnet.yaml @@ -2,13 +2,9 @@ version: '3.8' services: node: - environment: - - ETH_CHAIN_ID=1337 depends_on: - devnet node-2: - environment: - - ETH_CHAIN_ID=1337 depends_on: - devnet devnet: diff --git a/tools/docker/docker-compose.yaml b/tools/docker/docker-compose.yaml index a8630f1dd67..58083c7794c 100644 --- a/tools/docker/docker-compose.yaml +++ b/tools/docker/docker-compose.yaml @@ -13,7 +13,7 @@ services: entrypoint: /bin/sh -c "chainlink -c /run/secrets/config node start -d -p /run/secrets/node_password -a /run/secrets/apicredentials" restart: always env_file: - - chainlink-variables.env + - .env ports: - 6688:6688 secrets: @@ -31,7 +31,7 @@ services: entrypoint: /bin/sh -c "chainlink -c /run/secrets/config node start -d -p /run/secrets/node_password -a /run/secrets/apicredentials" restart: always env_file: - - chainlink-variables.env + - .env ports: - 6699:6688 secrets: From 5b5711b6d1c5afccfed6caa53646df1882be8ea3 Mon Sep 17 00:00:00 2001 From: Clement Erena Date: Fri, 5 Jul 2024 00:11:24 +0200 Subject: [PATCH 6/7] doc(docker): update README --- tools/docker/README.md | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tools/docker/README.md b/tools/docker/README.md index 28d30e6e0e5..ebbfcff61aa 100644 --- a/tools/docker/README.md +++ b/tools/docker/README.md @@ -8,7 +8,7 @@ The docker-compose configuration present in this directory allows to quickly run # Using the compose script -Inside the `chainlink/tools/docker` directory, there is a helper script that is included +You should use the script `compose` located in the `chainlink/tools/docker` directory To see a list of available commands, perform the following: ```sh @@ -18,12 +18,18 @@ cd tools/docker ## Env vars -You can use the following env vars : +### .env file +.env file is used to set the environment variables for the docker-compose commands + +### Compose script env vars +The following env vars are used for the compose script : - `GETH_MODE=true` to use geth instead of parity - `CHAIN_ID=` to specify the chainID (default is 34055 for parity and 1337 for geth) - `HTTPURL=` to specify the RPC node HTTP url (default is set if you use geth or parity) - `WSURL=` to specify the RPC node WS url (default is set if you use geth or parity) +If you specify both `HTTPURL` and `WSURL`, it won't run the devnet RPC node. + for example : ```sh CHAIN_ID=11155111 WSURL=wss://eth.sepolia HTTPURL=https://eth.sepolia ./compose dev @@ -31,7 +37,7 @@ CHAIN_ID=11155111 WSURL=wss://eth.sepolia HTTPURL=https://eth.sepolia ./compose ## Dev -Will run one node with a postgres database and optionally by default a devnet RPC node that can be either geth or parity. +Will run one node with a postgres database and by default a devnet RPC node that can be either geth or parity. ```sh ./compose dev @@ -43,7 +49,7 @@ Credentials for logging into the operator-ui can be found [here](../../tools/sec ## Up -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. +Runs all services including two nodes with two postgres databases and by default a devnet RPC node that can be either geth or parity. ```sh ./compose up From 7192dafe7bd0795e06e861eaaca97a37b2a42a5f Mon Sep 17 00:00:00 2001 From: Clement Erena Date: Fri, 5 Jul 2024 11:06:05 +0200 Subject: [PATCH 7/7] doc(docker): update README missing punctuation --- tools/docker/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/docker/README.md b/tools/docker/README.md index ebbfcff61aa..e0ccadd68c3 100644 --- a/tools/docker/README.md +++ b/tools/docker/README.md @@ -8,7 +8,7 @@ The docker-compose configuration present in this directory allows to quickly run # Using the compose script -You should use the script `compose` located in the `chainlink/tools/docker` directory +You should use the script `compose` located in the `chainlink/tools/docker` directory. To see a list of available commands, perform the following: ```sh