Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
39 changes: 39 additions & 0 deletions .github/workflows/pipeline-go-ethereum.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: CI-Build

on:
pull_request:
types: [closed]
branches: ["master"]

jobs:
build-docker-image:
if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'CI:Build')
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- 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: Log in to Docker Hub Container Registry
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push Docker image to Docker Hub Registry
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ivaylorashkov/go-ethereum:latest
82 changes: 82 additions & 0 deletions .github/workflows/pipeline-hardhat.yml
Original file line number Diff line number Diff line change
@@ -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 }}
31 changes: 31 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
version: "3.9"

services:
geth:
container_name: geth-devnet-go-ethereum
image: ivaylorashkov/go-ethereum:latest
networks:
- devnet
ports:
- "8545:8545" # Map host port 8545 to container port 8545
- "8546:8546" # Map host port 8546 to container port 8546
- "30303:30303" # Map host port 30303 to container port 30303
- "30303:30303/udp" # Map UDP port 30303 to the container
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
17 changes: 17 additions & 0 deletions hardhat/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
node_modules
.env

# Hardhat files
/cache
/artifacts

# TypeChain files
/typechain
/typechain-types

# solidity-coverage files
/coverage
/coverage.json

# Hardhat Ignition default folder for deployments against a local node
ignition/deployments/chain-31337
13 changes: 13 additions & 0 deletions hardhat/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Sample Hardhat Project

This project demonstrates a basic Hardhat use case. It comes with a sample contract, a test for that contract, and a Hardhat Ignition module that deploys that contract.

Try running some of the following tasks:

```shell
npx hardhat help
npx hardhat test
REPORT_GAS=true npx hardhat test
npx hardhat node
npx hardhat ignition deploy ./ignition/modules/Lock.js
```
34 changes: 34 additions & 0 deletions hardhat/contracts/Lock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28;

// Uncomment this line to use console.log
// import "hardhat/console.sol";

contract Lock {
uint public unlockTime;
address payable public owner;

event Withdrawal(uint amount, uint when);

constructor(uint _unlockTime) payable {
require(
block.timestamp < _unlockTime,
"Unlock time should be in the future"
);

unlockTime = _unlockTime;
owner = payable(msg.sender);
}

function withdraw() public {
// Uncomment this line, and the import of "hardhat/console.sol", to print a log in your terminal
// console.log("Unlock time is %o and block timestamp is %o", unlockTime, block.timestamp);

require(block.timestamp >= unlockTime, "You can't withdraw yet");
require(msg.sender == owner, "You aren't the owner");

emit Withdrawal(address(this).balance, block.timestamp);

owner.transfer(address(this).balance);
}
}
11 changes: 11 additions & 0 deletions hardhat/hardhat.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require("@nomicfoundation/hardhat-toolbox");

/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
solidity: "0.8.28",
networks: {
devnet: {
url: "http://localhost:8545",
},
},
};
18 changes: 18 additions & 0 deletions hardhat/ignition/modules/Lock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// This setup uses Hardhat Ignition to manage smart contract deployments.
// Learn more about it at https://hardhat.org/ignition

const { buildModule } = require("@nomicfoundation/hardhat-ignition/modules");

const JAN_1ST_2030 = 1893456000;
const ONE_GWEI = 1_000_000_000n;

module.exports = buildModule("LockModule", (m) => {
const unlockTime = m.getParameter("unlockTime", JAN_1ST_2030);
const lockedAmount = m.getParameter("lockedAmount", ONE_GWEI);

const lock = m.contract("Lock", [unlockTime], {
value: lockedAmount,
});

return { lock };
});
Loading