From 23eb56eb7b687950a84af9361ff1ce041edafc9b Mon Sep 17 00:00:00 2001 From: Stefan Iliev <46542846+StefanIliev545@users.noreply.github.com> Date: Mon, 30 Dec 2024 16:35:09 +0200 Subject: [PATCH] Added dev container for development (#2229) * Added dev container for development Dev container added that vs code uses in order to recreate environment everywhere; Sim tests pass, docker compose fails on ego unfortunately. * Fix for wrong docker version * Correct go version * Update go.sum * Update ManagementContract.go * Go mod tidy * Start up of eth2 network with launcher This starts eth2 network; In the code we use a lot of 127.0.0.1, which is not available inside docker so rest might not start --- .devcontainer/devcontainer.json | 43 ++++++++++++++++++++++++++ .devcontainer/install-deps.sh | 5 +++ .github/dependabot.yml | 12 +++++++ contracts/README.md | 6 ++++ contracts/tasks/abigen.ts | 8 +++-- go.mod | 6 ++-- go.sum | 12 +++---- testnet/launcher/eth2network/docker.go | 9 +++++- 8 files changed, 88 insertions(+), 13 deletions(-) create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/install-deps.sh create mode 100644 .github/dependabot.yml diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000000..d122b0f195 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,43 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/go +{ + "name": "Go", + // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile + "image": "mcr.microsoft.com/devcontainers/go:1-1.21-bookworm", + "features": { + "ghcr.io/dhoeric/features/act:1": {}, + "ghcr.io/devcontainers/features/node:1": { + "version": "18" + }, + "ghcr.io/devcontainers/features/docker-outside-of-docker:1": {} + }, + "customizations": { + "vscode": { + "extensions": [ + "766b.go-outliner", + "golang.go" + ], + "settings": { + "go.testTimeout": "10m" + } + } + }, + "postCreateCommand": "bash -i ./.devcontainer/install-deps.sh", + "containerEnv": { + "LOCALHOST_URL": "http://host.docker.internal" + } + + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Use 'postCreateCommand' to run commands after the container is created. + // "postCreateCommand": "go version", + // Configure tool-specific properties. + // "customizations": {}, + + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} diff --git a/.devcontainer/install-deps.sh b/.devcontainer/install-deps.sh new file mode 100644 index 0000000000..40b5419d38 --- /dev/null +++ b/.devcontainer/install-deps.sh @@ -0,0 +1,5 @@ +go install github.com/ethereum/go-ethereum/cmd/abigen@v1.13.15; +nvm install 18; +cd contracts; +npm install; +cd .. \ No newline at end of file diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000000..f33a02cd16 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,12 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for more information: +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates +# https://containers.dev/guide/dependabot + +version: 2 +updates: + - package-ecosystem: "devcontainers" + directory: "/" + schedule: + interval: weekly diff --git a/contracts/README.md b/contracts/README.md index 711e676af9..6b7287c616 100644 --- a/contracts/README.md +++ b/contracts/README.md @@ -16,6 +16,12 @@ brew tap ethereum/ethereum brew install ethereum ``` +Notice that for generating the go bindings, you need to have the `abigen` executable installed, which comes from the ethereum package, but can be independently installed using (recommended for the devcontainer): + +```shell +go install github.com/ethereum/go-ethereum/cmd/abigen@latest +``` + Running the following command will pull all of the relevant dependencies for node and solidity. ```shell diff --git a/contracts/tasks/abigen.ts b/contracts/tasks/abigen.ts index 22e46e6a59..d957810967 100644 --- a/contracts/tasks/abigen.ts +++ b/contracts/tasks/abigen.ts @@ -59,12 +59,14 @@ task("generate-abi-bindings", "Using the evm bytecode and exported abi's of the fs.mkdirSync(outputFileDir); } - const abigenSpawn = spawnSync("abigen", [ + const abigenArgs = [ `--abi=${abiFilePath}`, `--bin=${binFilePath}`, `--pkg=${contractName}`, - `--out=${outputFilePath}`] - ); + `--out=${outputFilePath}` + ]; + console.log(`Running: abigen ${abigenArgs.join(' ')}`); + const abigenSpawn = spawnSync("abigen", abigenArgs); if (abigenSpawn.status == 0) { console.log(`Successfully generated go binding for ${sourceName}`); diff --git a/go.mod b/go.mod index 099944eea5..1ccad740b8 100644 --- a/go.mod +++ b/go.mod @@ -47,9 +47,9 @@ require ( github.com/urfave/cli/v2 v2.27.5 github.com/valyala/fasthttp v1.57.0 gitlab.com/NebulousLabs/fastrand v0.0.0-20181126182046-603482d69e40 - golang.org/x/crypto v0.29.0 + golang.org/x/crypto v0.30.0 golang.org/x/exp v0.0.0-20240318143956-a85f2c67cd81 - golang.org/x/sync v0.9.0 + golang.org/x/sync v0.10.0 google.golang.org/grpc v1.67.1 google.golang.org/protobuf v1.35.1 gopkg.in/natefinch/lumberjack.v2 v2.2.1 @@ -171,7 +171,7 @@ require ( golang.org/x/arch v0.11.0 // indirect golang.org/x/net v0.30.0 // indirect golang.org/x/sys v0.28.0 // indirect - golang.org/x/text v0.20.0 // indirect + golang.org/x/text v0.21.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20241021214115-324edc3d5d38 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gotest.tools/v3 v3.5.1 // indirect diff --git a/go.sum b/go.sum index f77e511b1a..b76ab7ac18 100644 --- a/go.sum +++ b/go.sum @@ -408,8 +408,8 @@ golang.org/x/arch v0.11.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ= -golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg= +golang.org/x/crypto v0.30.0 h1:RwoQn3GkWiMkzlX562cLB7OxWvjH1L8xutO2WoJcRoY= +golang.org/x/crypto v0.30.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= golang.org/x/exp v0.0.0-20240318143956-a85f2c67cd81 h1:6R2FC06FonbXQ8pK11/PDFY6N6LWlf9KlzibaCapmqc= golang.org/x/exp v0.0.0-20240318143956-a85f2c67cd81/go.mod h1:CQ1k9gNrJ50XIzaKCRR2hssIjF07kZFEiieALBM/ARQ= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= @@ -428,8 +428,8 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ= -golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ= +golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -453,8 +453,8 @@ golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug= -golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4= +golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= +golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/testnet/launcher/eth2network/docker.go b/testnet/launcher/eth2network/docker.go index 8c681eb85e..de34b30df5 100644 --- a/testnet/launcher/eth2network/docker.go +++ b/testnet/launcher/eth2network/docker.go @@ -3,6 +3,7 @@ package eth2network import ( "context" "fmt" + "os" "strings" "time" @@ -59,7 +60,13 @@ func (n *Eth2Network) IsReady() error { // retry the connection err = retry.Do(func() error { - dial, err = ethclient.Dial(fmt.Sprintf("http://127.0.0.1:%d", n.cfg.gethHTTPPort)) + host := os.Getenv("LOCALHOST_URL") + if host == "" { + host = "http://127.0.0.1" + } + url := fmt.Sprintf("%s:%d", host, n.cfg.gethHTTPPort) + + dial, err = ethclient.Dial(url) if err != nil { return err }