Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(geth-all-in-one): add ethereum test image and helper class #2578

Merged
merged 1 commit into from
Sep 18, 2023
Merged
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
60 changes: 60 additions & 0 deletions .github/workflows/geth-all-in-one-publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: geth-all-in-one-publish

on:
push:
# Publish `main` as Docker `latest` image.
branches:
- main

# Publish `v1.2.3` tags as releases.
tags:
- v*

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

env:
IMAGE_NAME: cactus-geth-all-in-one

jobs:
# Push image to GitHub Packages.
# See also https://docs.docker.com/docker-hub/builds/
build-tag-push-container:
runs-on: ubuntu-20.04
env:
DOCKER_BUILDKIT: 1
DOCKERFILE_PATH: ./tools/docker/geth-all-in-one/Dockerfile
DOCKER_BUILD_DIR: ./tools/docker/geth-all-in-one/
permissions:
packages: write
contents: read

steps:
- uses: actions/[email protected]

- name: Build image
run: docker build $DOCKER_BUILD_DIR --file $DOCKERFILE_PATH --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}"

- name: Log in to registry
# This is where you will update the PAT to GITHUB_TOKEN
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin

- name: Push image
run: |
SHORTHASH=$(git rev-parse --short "$GITHUB_SHA")
TODAYS_DATE="$(date +%F)"
DOCKER_TAG="$TODAYS_DATE-$SHORTHASH"
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Do not use the `latest` tag at all, tag with date + git short hash if there is no git tag
[ "$VERSION" == "main" ] && VERSION=$DOCKER_TAG
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
74 changes: 74 additions & 0 deletions packages/cactus-test-geth-ledger/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# `@hyperledger/cactus-test-geth-ledger`

Helpers for running test `go-ethereum` ledger in test scripts.

## Summary

- [Getting Started](#getting-started)
- [Usage](#usage)
- [Runing the tests](#running-the-tests)
- [Contributing](#contributing)
- [License](#license)
- [Acknowledgments](#acknowledgments)

## Getting Started

Clone the git repository on your local machine. Follow these instructions that will get you a copy of the project up and running on
your local machine for development and testing purposes.

### Prerequisites

In the root of the project to install the dependencies execute the command:

```sh
npm run configure
```

## Usage

- In order to start the new test ledger, you must import `GethTestLedger` and `start()` it.
- Options can be modified by supplying constructor argument object.
- See tests for more complete usage examples.

```typescript
import { GethTestLedger } from "@hyperledger/cactus-test-geth-ledger";

// You can supply empty object, suitable default values will be used.
const options = {
containerImageName: "cactus_geth_all_in_one", // geth AIO container name
containerImageVersion: "local-build", // geth AIO container tag
logLevel: "info" as LogLevelDesc, // log verbosity of test class, not ethereum node!
emitContainerLogs: false, // will print ethereum node logs here if `true`
envVars: [], // environment variables to provide when starting the ledger
useRunningLedger: false, // test flag to search for already running ledger instead of starting new one (only for development)
};

const ledger = new GethTestLedger(options);
await ledger.start();
// await ledger.start(true); // don't pull image, use one from local storage

// Use
const rpcApiHttpHost = await ledger.getRpcApiHttpHost();
```

## Running the tests

To check that all has been installed correctly and that the test class has no errors:

- Run this command at the project's root:

```sh
npx jest cactus-test-geth-ledger
```

## Contributing

We welcome contributions to Hyperledger Cactus in many forms, and there’s always plenty to do!

Please review [CONTIRBUTING.md](../../CONTRIBUTING.md) to get started.

## License

This distribution is published under the Apache License Version 2.0 found in the [LICENSE](../../LICENSE) file.

## Acknowledgments
74 changes: 74 additions & 0 deletions packages/cactus-test-geth-ledger/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"name": "@hyperledger/cactus-test-geth-ledger",
"version": "2.0.0-alpha.1",
"description": "Helpers for running test go-ethereum ledger in test scripts.",
"keywords": [
"Hyperledger",
"Cactus",
"Integration",
"Blockchain",
"Distributed Ledger Technology"
],
"homepage": "https://github.com/hyperledger/cactus#readme",
"bugs": {
"url": "https://github.com/hyperledger/cactus/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/hyperledger/cactus.git"
},
"license": "Apache-2.0",
"author": {
"name": "Hyperledger Cactus Contributors",
"email": "[email protected]",
"url": "https://www.hyperledger.org/use/cactus"
},
"contributors": [
{
"name": "Please add yourself to the list of contributors",
"email": "[email protected]",
"url": "https://example.com"
},
{
"name": "Michal Bajer",
"email": "[email protected]",
"url": "https://www.fujitsu.com/global/"
}
],
"main": "dist/lib/main/typescript/index.js",
"module": "dist/lib/main/typescript/index.js",
"browser": "dist/cactus-test-geth-ledger.web.umd.js",
"types": "dist/lib/main/typescript/index.d.ts",
"files": [
"dist/*"
],
"scripts": {
"watch": "npm-watch",
"webpack": "npm-run-all webpack:dev",
"webpack:dev": "npm-run-all webpack:dev:node webpack:dev:web",
"webpack:dev:node": "webpack --env=dev --target=node --config ../../webpack.config.js",
"webpack:dev:web": "webpack --env=dev --target=web --config ../../webpack.config.js"
},
"dependencies": {
"@hyperledger/cactus-common": "2.0.0-alpha.1",
"@hyperledger/cactus-test-tooling": "2.0.0-alpha.1",
"dockerode": "3.3.0",
"internal-ip": "6.2.0",
"run-time-error": "1.4.0",
"web3": "4.0.3",
"web3-eth-accounts": "4.0.3"
},
"devDependencies": {
"@types/dockerode": "3.2.7"
},
"engines": {
"node": ">=10",
"npm": ">=6"
},
"publishConfig": {
"access": "public"
},
"browserMinified": "dist/cactus-test-geth-ledger.web.umd.min.js",
"mainMinified": "dist/cactus-test-geth-ledger.node.umd.min.js",
"watch": {}
}
Loading
Loading