[Limechain] Create sample hardhat project and deploy contract job in the pipeline #4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Push Docker Image | |
on: | |
pull_request: | |
types: [closed] | |
jobs: | |
# This job is triggered on merged PRs with the CI:Build label | |
# It builds a Docker image with a local geth devnet and pushes it to Docker Hub | |
build-and-push-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 | |
with: | |
fetch-depth: 0 | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_ACCESS_TOKEN }} | |
- name: Build and push Docker image | |
run: | | |
COMMIT=$(git rev-parse --short HEAD) | |
VERSION=$(git describe --tags --abbrev=0) | |
BUILDNUM=${{ github.run_number }} | |
docker build --build-arg COMMIT=$COMMIT --build-arg VERSION=$VERSION --build-arg BUILDNUM=$BUILDNUM -t ${{ secrets.DOCKER_USERNAME }}/go-ethereum-fork:latest . | |
docker push ${{ secrets.DOCKER_USERNAME }}/go-ethereum-fork:latest | |
# This job is triggered on merged PRs with the CI:Deploy label | |
# It runs a local geth devnet container in daemon mode using docker-compose with the image built in the previous job | |
# A sample hardhat project is mounted to the container from the hardhat directory | |
# The sample contract is deployed on the local geth devnet and tested | |
# After that, a new image with the contract is built and pushed to Docker Hub | |
hardhat-deploy-and-test: | |
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 | |
with: | |
fetch-depth: 0 | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_ACCESS_TOKEN }} | |
- name: Run local geth devnet container in daemon mode | |
run: | | |
docker-compose -f docker-compose.yml up -d geth-node | |
# Wait for geth to be ready | |
sleep 10 | |
- name: Copy entrypoint and the hardhat directory containing the sample project | |
run: | | |
docker cp ./hardhat ethereum-node:/hardhat | |
docker cp ./entrypoint.sh ethereum-node:/entrypoint.sh | |
docker exec ethereum-node chmod +x /entrypoint.sh | |
- name: Compile and deploy contracts inside the container by running the entrypoint script | |
run: | | |
docker exec ethereum-node sh /entrypoint.sh | |
- name: Commit the container state to a new Docker image and push it to Docker Hub | |
run: | | |
docker commit ethereum-node ${{ secrets.DOCKER_USERNAME }}/go-ethereum-fork:deployed | |
docker push ${{ secrets.DOCKER_USERNAME }}/go-ethereum-fork:deployed | |
- name: Stop and remove the geth-node container | |
run: docker-compose -f docker-compose.yml down |