adjusting pipelines, docker-compose and hardhat config file

This commit is contained in:
ivaylorashkov 2025-02-18 16:02:00 +02:00
parent e987cbd529
commit cc91691d15
5 changed files with 121 additions and 7 deletions

View file

@ -17,13 +17,13 @@ jobs:
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3 uses: docker/setup-buildx-action@v3
- name: Cache Docker layers # - name: Cache Docker layers
uses: actions/cache@v3 # uses: actions/cache@v3
with: # with:
path: /tmp/.buildx-cache # path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }} # key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: | # restore-keys: |
${{ runner.os }}-buildx- # ${{ runner.os }}-buildx-
- name: Log in to Docker Hub Container Registry - name: Log in to Docker Hub Container Registry
uses: docker/login-action@v3 uses: docker/login-action@v3

82
.github/workflows/pipeline-hardhat.yml vendored Normal file
View file

@ -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 }}

View file

@ -14,9 +14,18 @@ services:
volumes: volumes:
- eth_data:/root/.ethereum # Mount a Docker volume for persistent Ethereum data - 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: networks:
devnet: devnet:
driver: bridge driver: bridge
volumes: volumes:
eth_data: # Define the volume here eth_data: # Define the volume here

18
hardhat/Dockerfile Normal file
View file

@ -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"]

View file

@ -3,4 +3,9 @@ require("@nomicfoundation/hardhat-toolbox");
/** @type import('hardhat/config').HardhatUserConfig */ /** @type import('hardhat/config').HardhatUserConfig */
module.exports = { module.exports = {
solidity: "0.8.28", solidity: "0.8.28",
networks: {
devnet: {
url: "http://localhost:8545",
},
},
}; };