From 125ea8de590acef6f21cbc2c6688c456a9b5fc2f Mon Sep 17 00:00:00 2001 From: RS Date: Fri, 27 Dec 2024 12:32:29 +0200 Subject: [PATCH] Build and Run Devnet --- .github/workflows/ci-build.yml | 83 ++++++++++++++++++++++++++++++++++ Docker-Compose.yml | 13 ++++++ Dockerfile | 14 +++--- 3 files changed, 103 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/ci-build.yml create mode 100644 Docker-Compose.yml diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml new file mode 100644 index 000000000000..04984819f296 --- /dev/null +++ b/.github/workflows/ci-build.yml @@ -0,0 +1,83 @@ +name: CI Build and Push Docker Image + +on: + pull_request: + types: [closed] # Trigger when the PR is closed (merged or just closed) + branches: + - master # Trigger only when code is pushed to the master branch + +jobs: + build: + # Run the jobs only if the PR is merged and the label 'CI:Build' is present + if: contains(github.event.pull_request.labels.*.name, 'CI:Build') && github.event.pull_request.merged == true + runs-on: ubuntu:latest + + steps: + - name: Checkout Code + uses: actions/checkout@v4 + + - name: Get Version and Build number + run: | + VERSION="latest" # Simple static version; could be changed if needed + BUILDNUM=${GITHUB_RUN_NUMBER} # Use the GitHub run number as the build number + + # Set environment variables for later steps + echo "VERSION=${VERSION}" >> $GITHUB_ENV + echo "BUILDNUM=${BUILDNUM}" >> $GITHUB_ENV + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Set up Docker Login + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Build Docker image + run: | + docker build -t ${{ secrets.DOCKER_USERNAME }}/go-ethereum:${{ env.BUILDNUM }} . + + - name: Tag Docker image with 'latest' + run: | + docker tag ${{ secrets.DOCKER_USERNAME }}/go-ethereum:${{ env.BUILDNUM }} ${{ secrets.DOCKER_USERNAME }}/go-ethereum:latest + + - name: Push Docker image to Docker Hub + run: | + docker push ${{ secrets.DOCKER_USERNAME }}/go-ethereum:${{ env.BUILDNUM }} + docker push ${{ secrets.DOCKER_USERNAME }}/go-ethereum:latest + + run-devnet: + needs: build # Ensure this runs only after the build-and-push job + runs-on: ubuntu-latest + + steps: + - name: Checkout Code + uses: actions/checkout@v4 + + - name: Set up Docker Compose + run: | + sudo apt-get update + sudo apt-get install -y docker-compose + + - name: Log in to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Run Devnet with Docker Compose + run: | + export DOCKER_HUB_USER=${{ secrets.DOCKER_USERNAME }} + docker-compose up -d + + - name: Verify Devnet + run: | + sleep 10 # Allow time for the devnet to start + curl -X POST -H "Content-Type: application/json" \ + --data '{"jsonrpc":"2.0","method":"web3_clientVersion","params":[],"id":1}' \ + http://localhost:8545 + + - name: Stop Devnet container + run: | + docker-compose down # Stops the containers and removes the network diff --git a/Docker-Compose.yml b/Docker-Compose.yml new file mode 100644 index 000000000000..6a8231cbdd0b --- /dev/null +++ b/Docker-Compose.yml @@ -0,0 +1,13 @@ +services: + devnet: + image: $DOCKER_HUB_USER/go-ethereum:latest # Use the image built and pushed during build phase + container_name: devnet + ports: + - "8545:8545" # Exposing RPC endpoint for interaction + command: ["geth", "--dev", "--http", "--http.api", "web3,eth,net,personal", "--http.addr", "0.0.0.0", "--http.port", "8545"] + networks: + - devnet_network + +networks: + devnet_network: + driver: bridge diff --git a/Dockerfile b/Dockerfile index ff89e92f2568..4413d7f827ce 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ # Support setting various labels on the final image -ARG COMMIT="" -ARG VERSION="" -ARG BUILDNUM="" +# ARG COMMIT="" +# ARG VERSION="" +# ARG BUILDNUM="" # Build Geth in a stock Go builder container FROM golang:1.23-alpine AS builder @@ -26,8 +26,8 @@ EXPOSE 8545 8546 30303 30303/udp ENTRYPOINT ["geth"] # Add some metadata labels to help programmatic image consumption -ARG COMMIT="" -ARG VERSION="" -ARG BUILDNUM="" +# ARG COMMIT="" +# ARG VERSION="" +# ARG BUILDNUM="" -LABEL commit="$COMMIT" version="$VERSION" buildnum="$BUILDNUM" +# LABEL commit="$COMMIT" version="$VERSION" buildnum="$BUILDNUM"