diff --git a/.github/workflows/deploy-devnet.yml b/.github/workflows/deploy-devnet.yml index 1c9b3a95ad..20b02c09f8 100644 --- a/.github/workflows/deploy-devnet.yml +++ b/.github/workflows/deploy-devnet.yml @@ -20,6 +20,11 @@ jobs: - name: Checkout repo uses: actions/checkout@v3 + # capture SHA as an env variable + - name: Get short commit SHA + id: vars + run: echo "COMMIT_SHA=$(echo $GITHUB_SHA | cut -c1-7)" >> $GITHUB_ENV + - name: Set up Docker uses: docker/setup-buildx-action@v3 @@ -31,8 +36,12 @@ jobs: $BASE_IMAGE \ --dev --http --http.api eth,net,web3,personal - # Give devnet time to start up - sleep 5 + # Wait until the devnet RPC is ready + until curl -s http://localhost:8545 > /dev/null; do + echo "Waiting for Geth RPC..." + sleep 2 + done + echo "Geth RPC is up, proceeding with deployment" - name: Set up Node.js uses: actions/setup-node@v3 @@ -51,6 +60,11 @@ jobs: run: | docker commit $CONTAINER_NAME $FINAL_IMAGE + - name: Stop and remove container + run: | + docker commit $CONTAINER_NAME $FINAL_IMAGE:latest + docker tag $FINAL_IMAGE:latest $FINAL_IMAGE:${{ env.COMMIT_SHA }} + - name: Log in to Docker Hub uses: docker/login-action@v3 with: @@ -59,4 +73,5 @@ jobs: - name: Push image to Docker Hub run: | - docker push $FINAL_IMAGE + docker push $FINAL_IMAGE:latest + docker push $FINAL_IMAGE:${{ env.COMMIT_SHA }} diff --git a/hardhat/scripts/deploy.js b/hardhat/scripts/deploy.js index 1b9e575a68..e87c0ffd4e 100644 --- a/hardhat/scripts/deploy.js +++ b/hardhat/scripts/deploy.js @@ -1,9 +1,23 @@ +const { ethers } = require("hardhat"); + async function main() { - const [deployer] = await ethers.getSigners(); + // Connect to local devnet RPC explicitly + const provider = new ethers.providers.JsonRpcProvider("http://localhost:8545"); - console.log("Deploying contracts with the account:", deployer.address); + // Get signer from provider + const [deployer] = await provider.listAccounts().then(accounts => + accounts.length > 0 ? [provider.getSigner(accounts[0])] : [] + ); + + if (!deployer) { + throw new Error("No accounts found on the devnet."); + } + + console.log("Deploying contracts with the account:", await deployer.getAddress()); + + // Connect contract factory with the deployer signer + const Lock = await ethers.getContractFactory("Lock", deployer); - const Lock = await ethers.getContractFactory("Lock"); const lock = await Lock.deploy(); await lock.deployed(); @@ -14,6 +28,6 @@ async function main() { main() .then(() => process.exit(0)) .catch(error => { - console.error(error); + console.error("Deployment failed:", error); process.exit(1); - }); \ No newline at end of file + });