From cc91691d157d1f76be4cd9ebf1a16c0cc2344b03 Mon Sep 17 00:00:00 2001 From: ivaylorashkov Date: Tue, 18 Feb 2025 16:02:00 +0200 Subject: [PATCH] adjusting pipelines, docker-compose and hardhat config file --- ...{pipeline.yml => pipeline-go-ethereum.yml} | 14 ++-- .github/workflows/pipeline-hardhat.yml | 82 +++++++++++++++++++ docker-compose.yaml | 9 ++ hardhat/Dockerfile | 18 ++++ hardhat/hardhat.config.js | 5 ++ 5 files changed, 121 insertions(+), 7 deletions(-) rename .github/workflows/{pipeline.yml => pipeline-go-ethereum.yml} (77%) create mode 100644 .github/workflows/pipeline-hardhat.yml create mode 100644 hardhat/Dockerfile diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline-go-ethereum.yml similarity index 77% rename from .github/workflows/pipeline.yml rename to .github/workflows/pipeline-go-ethereum.yml index d0c3c78a28..7f1513a650 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline-go-ethereum.yml @@ -17,13 +17,13 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - name: Cache Docker layers - uses: actions/cache@v3 - with: - path: /tmp/.buildx-cache - key: ${{ runner.os }}-buildx-${{ github.sha }} - restore-keys: | - ${{ runner.os }}-buildx- + # - name: Cache Docker layers + # uses: actions/cache@v3 + # with: + # path: /tmp/.buildx-cache + # key: ${{ runner.os }}-buildx-${{ github.sha }} + # restore-keys: | + # ${{ runner.os }}-buildx- - name: Log in to Docker Hub Container Registry uses: docker/login-action@v3 diff --git a/.github/workflows/pipeline-hardhat.yml b/.github/workflows/pipeline-hardhat.yml new file mode 100644 index 0000000000..9dd29d8c64 --- /dev/null +++ b/.github/workflows/pipeline-hardhat.yml @@ -0,0 +1,82 @@ +name: CI-Deploy to Local Devnet + +on: + pull_request: + types: [closed] + branches: ["master"] + +env: + IMAGE: ivaylorashkov/geth-devnet-go-ethereum + OWNER: ivaylorashkov + IMAGE_TAG: latest + REGISTRY: docker.io + +jobs: + deploy-hardhat-ethereum: + if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'CI:Deploy') + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to Docker Hub Container Registry + uses: docker/login-action@v3 + with: + username: ${{ vars.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Pull Docker image + run: docker pull ${{ env.REGISTRY }}/${{ env.IMAGE }}:${{ env.IMAGE_TAG }} + + # Workspace: /git_repo/hardhat + - name: Running image container + run: | + docker run -d --name geth-devnet-geth-devnet-go-ethereum -p 8545:8545 -p 8546:8546 ${{ env.REGISTRY }}/${{ env.IMAGE }}:${{ env.IMAGE_TAG }} \ + --dev --http --http.addr 0.0.0.0 --http.port 8545 \ + --http.api personal,db,eth,net,web3 --dev.period 5 + + # Here I copy over files from the current git_repo repo over to the container + - name: Copy over hardhat files to running container + run: | + docker exec geth-devnet-go-ethereum mkdir -p /git_repo/hardhat + docker cp ${{ github.workspace }}/hardhat geth-devnet-go-ethereum:/git_repo/ + docker exec geth-devnet-go-ethereum ls /git_repo/hardhat + docker exec geth-devnet-go-ethereum ls -l /git_repo/hardhat + + # install nodejs and npm in docker container + - name: Installing Node.js and npm in the container + run: | + docker exec geth-devnet-go-ethereum apk add --no-cache nodejs npm + + # install hardhat locally within the pod + - name: Install local version of hardhat + run: docker exec geth-devnet-go-ethereum sh -c "cd /git_repo/hardhat && npm install hardhat" + + # Check hardhat version if its installed properly + - name: Check Hardhat version + run: | + docker exec geth-devnet-go-ethereum npx hardhat --version + + - name: Deploy hardhat sample project + run: | + docker exec geth-devnet-go-ethereum sh -c "cd /git_repo/hardhat && yes | npx hardhat ignition deploy ./ignition/modules/Lock.js --network devnet" + + - name: Testing contracts + run: | + docker exec geth-devnet-go-ethereum sh -c "cd /git_repo/hardhat && npx hardhat test" + + - name: Build a new docker image + run: | + docker commit geth-devnet-go-ethereum go-eth-hardhat:latest + docker tag go-eth-hardhat:latest ${{ env.REGISTRY }}/${{ env.OWNER }}/go-ethereum-hardhat:${{ env.IMAGE_TAG }} + + - name: Build and push Docker image to Docker Hub Registry + uses: docker/build-push-action@v6 + with: + context: . + push: true + tags: ${{env.OWNER}}/go-ethereum-hardhat:${{ env.IMAGE_TAG }} diff --git a/docker-compose.yaml b/docker-compose.yaml index f16dc9b155..8ffcff1604 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -14,9 +14,18 @@ services: volumes: - eth_data:/root/.ethereum # Mount a Docker volume for persistent Ethereum data + command: > + --dev + --http + --http.addr=0.0.0.0 + --http.port=8545 + --http.api=web3,eth,net,personal + --dev.period 5 + networks: devnet: driver: bridge + volumes: eth_data: # Define the volume here \ No newline at end of file diff --git a/hardhat/Dockerfile b/hardhat/Dockerfile new file mode 100644 index 0000000000..7e0bc5f373 --- /dev/null +++ b/hardhat/Dockerfile @@ -0,0 +1,18 @@ +# Use an official Node.js runtime as a parent image +FROM node:16 + +# Set the working directory inside the container +WORKDIR /usr/src/app + +# Install dependencies +COPY package.json package-lock.json ./ +RUN npm install + +# Copy the Hardhat project files into the container +COPY . . + +# Expose the port (optional depending on your app) +EXPOSE 8545 + +# Default command to run when the container starts +CMD ["npm", "run", "start"] diff --git a/hardhat/hardhat.config.js b/hardhat/hardhat.config.js index b63f0c2f2e..77d2e9163a 100755 --- a/hardhat/hardhat.config.js +++ b/hardhat/hardhat.config.js @@ -3,4 +3,9 @@ require("@nomicfoundation/hardhat-toolbox"); /** @type import('hardhat/config').HardhatUserConfig */ module.exports = { solidity: "0.8.28", + networks: { + devnet: { + url: "http://localhost:8545", + }, + }, };