Compare commits

..
Author SHA1 Message Date
Michael Shaw 5636eb6a4b first pass setting up statediff stack in cicd
Former-commit-id: c5a39404266977b1d9607723850f032fbbe29f49
2023-03-01 17:26:08 -05:00
18 changed files with 147 additions and 171 deletions
@@ -5,9 +5,8 @@ services:
image: cerc/laconicd:local
command: ["sh", "/docker-entrypoint-scripts.d/create-fixturenet.sh"]
volumes:
# TODO: look at folding these scripts into the container
# TODO: look at folding this script into the container
- ../config/fixturenet-laconicd/create-fixturenet.sh:/docker-entrypoint-scripts.d/create-fixturenet.sh
- ../config/fixturenet-laconicd/export-mykey.sh:/docker-entrypoint-scripts.d/export-mykey.sh
# TODO: determine which of the ports below is really needed
ports:
- "6060"
@@ -19,7 +18,4 @@ services:
- "9090"
- "9091"
- "1317"
cli:
image: cerc/laconic-registry-cli:local
volumes:
- ../config/fixturenet-laconicd/registry-cli-config-template.yml:/registry-cli-config-template.yml
@@ -1,5 +0,0 @@
# Add-on pod to include foundry tooling within a fixturenet
services:
foundry:
image: ghcr.io/foundry-rs/foundry:latest
command: ["while :; do sleep 600; done"]
@@ -1,2 +0,0 @@
#!/bin/sh
echo y | laconicd keys export mykey --unarmored-hex --unsafe
@@ -1,7 +0,0 @@
services:
cns:
restEndpoint: 'http://laconicd:1317'
gqlEndpoint: 'http://laconicd:9473/api'
userKey: REPLACE_WITH_MYKEY
bondId:
chainId: laconic_9000-1
@@ -48,13 +48,10 @@ RUN npm config set @lirewine:registry ${CERC_NPM_URL} \
# TODO: the image at this point could be made a base image for several different CLI images
# that install different Node-based CLI commands
# DEBUG, remove
RUN yarn info @cerc-io/laconic-registry-cli
# Globally install the cli package
RUN yarn global add @cerc-io/laconic-registry-cli
# Add scripts
RUN mkdir /scripts
ENV PATH="${PATH}:/scripts"
COPY ./import-key.sh /scripts
# Default command sleeps forever so docker doesn't kill it
CMD ["sh", "-c", "while :; do sleep 600; done"]
ENTRYPOINT ["laconic"]
@@ -1,2 +0,0 @@
#!/bin/sh
sed 's/REPLACE_WITH_MYKEY/'${1}'/' registry-cli-config-template.yml > config.yml
-1
View File
@@ -19,4 +19,3 @@ eth-probe
keycloak
tx-spammer
kubo
foundry
+4 -9
View File
@@ -11,25 +11,20 @@ To use a user-supplied registry set these environment variables:
Leave `CERC_NPM_REGISTRY_URL` un-set to use the local gitea registry.
### 1. Build support containers
### Build support containers
```
$ laconic-so --stack build-support build-containers
```
Note that the scheme/gerbil builder container can take a while to build so if you aren't going to build scheme projects it can be skipped with:
```
$ laconic-so --stack build-support build-containers --exclude cerc/builder-gerbil
```
### 2. Deploy Gitea Package Registry
### Deploy Gitea Package Registry
```
$ laconic-so --stack package-registry setup-repositories
$ laconic-so --stack package-registry deploy up
$ laconic-so --stack package-registry deploy-system up
This is your gitea access token: 84fe66a73698bf11edbdccd0a338236b7d1d5c45. Keep it safe and secure, it can not be fetched again from gitea.
$ export CERC_NPM_AUTH_TOKEN=84fe66a73698bf11edbdccd0a338236b7d1d5c45
```
Now npm packages can be built:
### Build npm Packages
Ensure that `CERC_NPM_AUTH_TOKEN` is set with the token printed above when the package-registry stack was deployed (the actual token value will be different than shown in this example):
```
$ export CERC_NPM_AUTH_TOKEN=84fe66a73698bf11edbdccd0a338236b7d1d5c45
$ laconic-so build-npms --include laconic-sdk
```
@@ -0,0 +1,98 @@
# fixturenet-eth
Instructions for deploying a local a geth + lighthouse blockchain "fixturenet" for development and testing purposes using laconic-stack-orchestrator (the installation of which is covered [here](https://github.com/cerc-io/stack-orchestrator#user-mode)):
## Clone required repositories
```
$ laconic-so --stack fixturenet-eth setup-repositories
```
## Build the fixturenet-eth containers
```
$ laconic-so --stack fixturenet-eth build-containers
```
This should create several container images in the local image registry:
* cerc/go-ethereum
* cerc/lighthouse
* cerc/fixturenet-eth-geth
* cerc/fixturenet-eth-lighthouse
## Deploy the stack
```
$ laconic-so --stack fixturenet-eth deploy-system up
```
## Check status
```
$ container-build/cerc-fixturenet-eth-lighthouse/scripts/status.sh
Waiting for geth to generate DAG ..................................................... DONE!
Waiting for beacon phase0 .... DONE!
Waiting for beacon altair .... DONE!
Waiting for beacon bellatrix pre-merge .... DONE!
Waiting for beacon bellatrix merge .... DONE!
$ docker ps -f 'name=laconic' --format 'table {{.Names}}\t{{.Ports}}' | cut -d'-' -f3- | sort
NAMES PORTS
fixturenet-eth-bootnode-geth-1 8545-8546/tcp, 30303/udp, 0.0.0.0:55847->9898/tcp, 0.0.0.0:55848->30303/tcp
fixturenet-eth-bootnode-lighthouse-1
fixturenet-eth-geth-1-1 8546/tcp, 30303/tcp, 30303/udp, 0.0.0.0:55851->8545/tcp
fixturenet-eth-geth-2-1 8545-8546/tcp, 30303/tcp, 30303/udp
fixturenet-eth-lighthouse-1-1 0.0.0.0:55858->8001/tcp
fixturenet-eth-lighthouse-2-1
```
## Additional pieces
Several other containers can used with the basic `fixturenet-eth`:
* `ipld-eth-db` (enables statediffing)
* `ipld-eth-server` (GQL and Ethereum API server, requires `ipld-eth-db`)
* `ipld-eth-beacon-db` and `ipld-eth-beacon-indexer` (for indexing Beacon chain blocks)
* `eth-probe` (captures eth1 tx gossip)
* `keycloak` (nginx proxy with keycloak auth for API authentication)
* `tx-spammer` (generates and sends automated transactions to the fixturenet)
It is not necessary to use them all at once, but a complete example follows:
```
# Setup
$ laconic-so setup-repositories --include cerc-io/go-ethereum,cerc-io/ipld-eth-db,cerc-io/ipld-eth-server,cerc-io/ipld-eth-beacon-db,cerc-io/ipld-eth-beacon-indexer,cerc-io/eth-probe,cerc-io/tx-spammer
# Build
$ laconic-so build-containers --include cerc/go-ethereum,cerc/lighthouse,cerc/fixturenet-eth-geth,cerc/fixturenet-eth-lighthouse,cerc/ipld-eth-db,cerc/ipld-eth-server,cerc/ipld-eth-beacon-db,cerc/ipld-eth-beacon-indexer,cerc/eth-probe,cerc/keycloak,cerc/tx-spammer
# Deploy
$ laconic-so deploy-system --include db,fixturenet-eth,ipld-eth-server,ipld-eth-beacon-db,ipld-eth-beacon-indexer,eth-probe,keycloak,tx-spammer up
# Status
$ container-build/cerc-fixturenet-eth-lighthouse/scripts/status.sh
Waiting for geth to generate DAG.... DONE!
Waiting for beacon phase0.... DONE!
Waiting for beacon altair.... DONE!
Waiting for beacon bellatrix pre-merge.... DONE!
Waiting for beacon bellatrix merge.... DONE!
$ docker ps -f 'name=laconic' --format 'table {{.Names}}\t{{.Ports}}' | cut -d'-' -f3- | sort
NAMES PORTS
eth-probe-db-1 0.0.0.0:55849->5432/tcp
eth-probe-mq-1
eth-probe-probe-1
fixturenet-eth-bootnode-geth-1 8545-8546/tcp, 30303/udp, 0.0.0.0:55847->9898/tcp, 0.0.0.0:55848->30303/tcp
fixturenet-eth-bootnode-lighthouse-1
fixturenet-eth-geth-1-1 8546/tcp, 30303/tcp, 30303/udp, 0.0.0.0:55851->8545/tcp
fixturenet-eth-geth-2-1 8545-8546/tcp, 30303/tcp, 30303/udp
fixturenet-eth-lighthouse-1-1 0.0.0.0:55858->8001/tcp
fixturenet-eth-lighthouse-2-1
ipld-eth-beacon-db-1 127.0.0.1:8076->5432/tcp
ipld-eth-beacon-indexer-1
ipld-eth-db-1 127.0.0.1:8077->5432/tcp
ipld-eth-server-1 127.0.0.1:8081-8082->8081-8082/tcp
keycloak-1 8443/tcp, 0.0.0.0:55857->8080/tcp
keycloak-db-1 0.0.0.0:55850->5432/tcp
keycloak-nginx-1 0.0.0.0:55859->80/tcp
migrations-1
tx-spammer-1
```
@@ -0,0 +1,17 @@
version: "1.0"
name: fixturenet-eth-statediff
decription: "Loaded Ethereum Fixturenet"
repos:
- cerc-io/go-ethereum
- cerc-io/tx-spammer
- cerc-io/ipld-eth-db
containers:
- cerc/lighthouse
- cerc/fixturenet-eth-geth
- cerc/fixturenet-eth-lighthouse
- cerc/ipld-eth-db
- cerc/tx-spammer
pods:
- fixturenet-eth
- tx-spammer
- ipld-eth-db
-1
View File
@@ -11,4 +11,3 @@ containers:
- cerc/fixturenet-eth-lighthouse
pods:
- fixturenet-eth
- foundry
+9 -41
View File
@@ -1,50 +1,18 @@
# Laconicd Fixturenet
Instructions for deploying a local Laconic blockchain "fixturenet" for development and testing purposes using laconic-stack-orchestrator.
Instructions for deploying a local Laconic blockchain "fixturenet" for development and testing purposes using laconic-stack-orchestrator (the installation of which is covered [here](https://github.com/cerc-io/stack-orchestrator#user-mode)):
## 1. Install Laconic Stack Orchestrator
Installation is covered in detail [here](https://github.com/cerc-io/stack-orchestrator#user-mode) but if you're on Linux and already have docker installed it should be as simple as:
## Clone required repositories
```
$ mkdir my-working-dir
$ cd my-working-dir
$ curl -L -o ./laconic-so https://github.com/cerc-io/stack-orchestrator/releases/latest/download/laconic-so
$ chmod +x ./laconic-so
$ export PATH=$PATH:$(pwd) # Or move laconic-so to ~/bin or your favorite on-path directory
$ laconic-so setup-repositories --include cerc-io/laconicd,cerc-io/laconic-sdk,cerc-io/laconic-registry-cli
```
## 2. Prepare the local build environment
Note that this step needs only to be done once on a new machine.
Detailed instructions can be found [here](../build-support/README.md). For the impatient run these commands:
## Build the laconicd container
```
$ laconic-so --stack build-support build-containers --exclude cerc/builder-gerbil
$ laconic-so --stack package-registry setup-repositories
$ laconic-so --stack package-registry deploy-system up
$ laconic-so build-containers --include cerc/laconicd
```
Then add the localhost alias `gitea.local` and set `CERC_NPM_AUTH_TOKEN` to the token printed when the package-registry stack was deployed above:
This should create a container with tag `cerc/laconicd` in the local image registry.
## Deploy the stack
```
$ sudo vi /etc/hosts
$ export CERC_NPM_AUTH_TOKEN=<my-token>
```
## 3. Clone required repositories
```
$ laconic-so --stack fixturenet-laconicd setup-repositories
```
## 4. Build the stack's packages and containers
```
$ laconic-so --stack fixturenet-laconicd build-npms
$ laconic-so --stack fixturenet-laconicd build-containers
```
## 5. Deploy the stack
```
$ laconic-so --stack fixturenet-laconicd deploy up
```
Correct operation should be verified by checking the laconicd container's logs with:
```
$ laconic-so --stack fixturenet-laconicd deploy logs
```
## 6. Test with the Registry CLI
```
$ laconic-so --stack fixturenet-laconicd deploy exec laconicd "sh /docker-entrypoint-scripts.d/export-mykey.sh"
$ laconic-so --stack fixturenet-laconicd deploy exec cli "sh /scripts/import-key.sh xxxxxxxxxxxxxxxxxxxxxxx"
$ laconic-so --stack fixturenet-laconicd deploy exec cli "laconic cns status"
$ laconic-so deploy-system --include fixturenet-laconicd up
```
Correct operation should be verified by checking the laconicd container's log.
@@ -13,6 +13,3 @@ containers:
- cerc/laconic-registry-cli
pods:
- fixturenet-laconicd
config:
cli:
key: laconicd.mykey
@@ -1,5 +0,0 @@
# Package Registry Stack
The Package Registry Stack supports a build environment that requires a package registry (initially for NPM packages only).
Setup instructions can be found [here](../build-support/README.md).
+1 -1
View File
@@ -1,2 +1,2 @@
# This file should be re-generated running: scripts/update-version-file.sh script
v1.0.25-75376d7
v1.0.21-c52f9e6
+12 -73
View File
@@ -19,7 +19,6 @@ import hashlib
import copy
import os
import sys
from dataclasses import dataclass
from decouple import config
import subprocess
from python_on_whales import DockerClient
@@ -57,19 +56,15 @@ def command(ctx, include, exclude, cluster, command, extra_args):
if not dry_run:
if command == "up":
container_exec_env = _make_runtime_env(ctx.obj)
for attr, value in container_exec_env.items():
os.environ[attr] = value
if debug:
os.environ["CERC_SCRIPT_DEBUG"] = "true"
if verbose:
print(f"Running compose up with container_exec_env: {container_exec_env}, extra_args: {extra_args_list}")
print(f"Running compose up for extra_args: {extra_args_list}")
for pre_start_command in cluster_context.pre_start_commands:
_run_command(ctx.obj, cluster_context.cluster, pre_start_command)
docker.compose.up(detach=True, services=extra_args_list)
for post_start_command in cluster_context.post_start_commands:
_run_command(ctx.obj, cluster_context.cluster, post_start_command)
_orchestrate_cluster_config(ctx.obj, cluster_context.config, docker, container_exec_env)
elif command == "down":
if verbose:
print("Running compose down")
@@ -79,8 +74,10 @@ def command(ctx, include, exclude, cluster, command, extra_args):
print("Usage: exec <service> <cmd>")
sys.exit(1)
service_name = extra_args_list[0]
command_to_exec = ["sh", "-c"] + extra_args_list[1:]
container_exec_env = _make_runtime_env(ctx.obj)
command_to_exec = extra_args_list[1:]
container_exec_env = {
"CERC_SCRIPT_DEBUG": "true"
} if debug else {}
if verbose:
print(f"Running compose exec {service_name} {command_to_exec}")
docker.compose.execute(service_name, command_to_exec, envs=container_exec_env)
@@ -118,8 +115,7 @@ def command(ctx, include, exclude, cluster, command, extra_args):
elif command == "logs":
if verbose:
print("Running compose logs")
logs_output = docker.compose.logs(services=extra_args_list if extra_args_list is not None else [])
print(logs_output)
docker.compose.logs()
def get_stack_status(ctx, stack):
@@ -143,15 +139,6 @@ def get_stack_status(ctx, stack):
False
def _make_runtime_env(ctx):
container_exec_env = {
"CERC_HOST_UID": f"{os.getuid()}",
"CERC_HOST_GID": f"{os.getgid()}"
}
container_exec_env.update({"CERC_SCRIPT_DEBUG": "true"} if ctx.debug else {})
return container_exec_env
def _make_cluster_context(ctx, include, exclude, cluster):
if ctx.local_stack:
@@ -164,13 +151,10 @@ def _make_cluster_context(ctx, include, exclude, cluster):
compose_dir = Path(__file__).absolute().parent.joinpath("data", "compose")
if cluster is None:
# Create default unique, stable cluster name from confile file path and stack name if provided
# Create default unique, stable cluster name from confile file path
# TODO: change this to the config file path
path = os.path.realpath(sys.argv[0])
unique_cluster_descriptor = f"{path},{ctx.stack},{include},{exclude}"
if ctx.debug:
print(f"pre-hash descriptor: {unique_cluster_descriptor}")
hash = hashlib.md5(unique_cluster_descriptor.encode()).hexdigest()
hash = hashlib.md5(path.encode()).hexdigest()
cluster = f"laconic-{hash}"
if ctx.verbose:
print(f"Using cluster name: {cluster}")
@@ -185,10 +169,8 @@ def _make_cluster_context(ctx, include, exclude, cluster):
stack_config = get_parsed_stack_config(ctx.stack)
# TODO: syntax check the input here
pods_in_scope = stack_config['pods']
cluster_config = stack_config['config'] if 'config' in stack_config else None
else:
pods_in_scope = all_pods
cluster_config = None
# Convert all pod definitions to v1.1 format
pods_in_scope = _convert_to_new_format(pods_in_scope)
@@ -225,16 +207,15 @@ def _make_cluster_context(ctx, include, exclude, cluster):
if ctx.verbose:
print(f"files: {compose_files}")
return cluster_context(cluster, compose_files, pre_start_commands, post_start_commands, cluster_config)
return cluster_context(cluster, compose_files, pre_start_commands, post_start_commands)
class cluster_context:
def __init__(self, cluster, compose_files, pre_start_commands, post_start_commands, config) -> None:
def __init__(self, cluster, compose_files, pre_start_commands, post_start_commands) -> None:
self.cluster = cluster
self.compose_files = compose_files
self.pre_start_commands = pre_start_commands
self.post_start_commands = post_start_commands
self.config = config
def _convert_to_new_format(old_pod_array):
@@ -265,45 +246,3 @@ def _run_command(ctx, cluster_name, command):
if command_result.returncode != 0:
print(f"FATAL Error running command: {command}")
sys.exit(1)
def _orchestrate_cluster_config(ctx, cluster_config, docker, container_exec_env):
@dataclass
class ConfigDirective:
source_container: str
source_variable: str
destination_container: str
destination_variable: str
if cluster_config is not None:
for container in cluster_config:
container_config = cluster_config[container]
if ctx.verbose:
print(f"{container} config: {container_config}")
for directive in container_config:
pd = ConfigDirective(
container_config[directive].split(".")[0],
container_config[directive].split(".")[1],
container,
directive
)
if ctx.verbose:
print(f"Setting {pd.destination_container}.{pd.destination_variable} = {pd.source_container}.{pd.source_variable}")
# TODO: fix the script paths so they're consistent between containers
source_value = docker.compose.execute(pd.source_container,
["sh", "-c",
f"sh /docker-entrypoint-scripts.d/export-{pd.source_variable}.sh"],
tty=False,
envs=container_exec_env)
# TODO: handle the case that the value is not yet available
if ctx.debug:
print(f"fetched source value: {source_value}")
destination_output = docker.compose.execute(pd.destination_container,
["sh", "-c",
f"sh /scripts/import-{pd.destination_variable}.sh {pd.source_variable}"],
tty=False,
envs=container_exec_env)
if ctx.debug:
print(f"destination output: {destination_output}")
# TODO: detect errors here
-1
View File
@@ -55,6 +55,5 @@ def cli(ctx, stack, quiet, verbose, dry_run, local_stack, debug, continue_on_err
cli.add_command(setup_repositories.command, "setup-repositories")
cli.add_command(build_containers.command, "build-containers")
cli.add_command(build_npms.command, "build-npms")
cli.add_command(deploy_system.command, "deploy") # deploy is an alias for deploy-system
cli.add_command(deploy_system.command, "deploy-system")
cli.add_command(version.command, "version")
-7
View File
@@ -24,11 +24,4 @@ $TEST_TARGET_SO --stack test deploy-system up
# TODO: test that we can use the deployed container somehow
# Clean up
$TEST_TARGET_SO --stack test deploy-system down
# Run same test but not using the stack definition
# Test building the a stack container
$TEST_TARGET_SO build-containers --include cerc/test-container
# Deploy the test container
$TEST_TARGET_SO deploy-system --include test up
# Clean up
$TEST_TARGET_SO deploy-system --include test down
echo "Test passed"