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: Add ci tool support to operator, fix some errors #76

Merged
merged 7 commits into from
Apr 2, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/release-aggregator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ jobs:
secret-files: |
git_config=${{ env.HOME }}/.gitconfig
git_credentials=${{ env.XDG_CONFIG_HOME }}/git/credentials
file: aggregator.Dockerfile
file: ./ops/aggregator.Dockerfile
labels: ${{ steps.aggregator-meta.outputs.labels }}
tags: ${{ steps.aggregator-meta.outputs.tags }}

Expand Down
108 changes: 108 additions & 0 deletions .github/workflows/release-operator-tool.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
name: Release Operator Tool
on:
push:
tags: ["*"]
workflow_dispatch:
# pull_request: # for testing only
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
CARGO_TERM_COLOR: always
# https://github.com/mozilla/sccache/releases
SCCACHE_TAR_URL: https://github.com/mozilla/sccache/releases/download/v0.7.4/sccache-v0.7.4-x86_64-unknown-linux-musl.tar.gz
SCCACHE_CACHE_SIZE: "3G"
RUSTC_WRAPPER: sccache
SUBWASM_VERSION: v0.20.0
CARGO_INCREMENTAL: "0"
CARGO_NET_GIT_FETCH_WITH_CLI: true
ECR_REPO: 305587085711.dkr.ecr.us-west-2.amazonaws.com/mach-operator-tool
PUB_REPO: public.ecr.aws

jobs:
build-docker-image:
name: Build Docker Image and extract files
runs-on: ["self-hosted", "linux", "x64", "ubuntu-latest"]
steps:
- name: Login to ECR
uses: docker/login-action@v3
with:
registry: ${{ env.ECR_REPO }}
username: ${{ secrets.ECR_ACCESS_KEY_ID }}
password: ${{ secrets.ECR_ACCESS_KEY }}

- name: Login to public ECR
uses: docker/login-action@v3
with:
registry: ${{ env.PUB_REPO }}
username: ${{ secrets.ECR_ACCESS_KEY_ID }}
password: ${{ secrets.ECR_ACCESS_KEY }}

- name: Checkout Sources
uses: actions/checkout@v4
with:
submodules: "true"
token: ${{ secrets.GIT_CREDENTIALS }}

- uses: de-vri-es/setup-git-credentials@v2
with:
credentials: https://${{ secrets.GIT_USERNAME }}:${{ secrets.GIT_CREDENTIALS }}@github.com

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
id: docker-builder
uses: docker/setup-buildx-action@v3

- name: Prepare Environment Variables
run: |
echo "HOME=$HOME" | tee -a $GITHUB_ENV
echo "XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-$HOME/.config}" | tee -a $GITHUB_ENV
echo "SHORT_SHA=${GITHUB_SHA::7}" | tee -a $GITHUB_ENV
GIT_TAG=$(git tag --points-at HEAD)
echo "GIT_TAG=$GIT_TAG" | tee -a $GITHUB_ENV
GIT_BRANCH=$(git branch --show-current)
echo "GIT_BRANCH=$GIT_BRANCH" | tee -a $GITHUB_ENV
echo "REF_NAME=$(echo ${GIT_TAG:-$GITHUB_REF_NAME} | sed 's/[^a-zA-Z0-9._]/-/g')" | tee -a $GITHUB_ENV
- run: cat $HOME/.gitconfig && cat $XDG_CONFIG_HOME/git/credentials

- name: Extract operator metadata (tags, labels) for Docker
id: operator-meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.ECR_REPO }}
${{ env.PUB_REPO }}/altlayer/mach-operator-tool
flavor: |
prefix=
suffix=
tags: |
type=sha,format=short,prefix=
type=ref,event=branch
type=ref,event=branch,suffix=-${{ github.run_number }}
type=ref,event=tag
type=raw,value=${{ env.REF_NAME }},enable=${{ github.event_name == 'pull_request' }}
type=raw,value=${{ env.GIT_BRANCH }},enable=${{ env.GIT_BRANCH != '' }}
type=raw,value=latest,enable=${{ env.GIT_BRANCH == 'master' }}

- name: Build operator docker with cache and push images
uses: docker/build-push-action@v5
id: docker_operator_tool_build
with:
context: .
builder: ${{ steps.docker-builder.outputs.name }}
target: app
push: ${{ github.event_name != 'pull_request' }}
provenance: false
cache-from: |
type=registry,ref=${{ env.ECR_REPO }}:latest
type=registry,ref=${{ env.ECR_REPO }}:${{ env.REF_NAME }}
secret-files: |
git_config=${{ env.HOME }}/.gitconfig
git_credentials=${{ env.XDG_CONFIG_HOME }}/git/credentials
file: ops/operator-tool.Dockerfile
labels: ${{ steps.operator-meta.outputs.labels }}
tags: ${{ steps.operator-meta.outputs.tags }}


2 changes: 1 addition & 1 deletion .github/workflows/release-operator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ jobs:
secret-files: |
git_config=${{ env.HOME }}/.gitconfig
git_credentials=${{ env.XDG_CONFIG_HOME }}/git/credentials
file: operator.Dockerfile
file: ./ops/operator.Dockerfile
labels: ${{ steps.operator-meta.outputs.labels }}
tags: ${{ steps.operator-meta.outputs.tags }}

Expand Down
19 changes: 11 additions & 8 deletions cli/actions/deposit_into_strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@ func DepositIntoStrategy(ctx *cli.Context) error {

configPath := ctx.GlobalString(config.ConfigFileFlag.Name)
nodeConfig := config.NodeConfig{}
err := sdkutils.ReadYamlConfig(configPath, &nodeConfig)
if err != nil {
return err
}
configJson, err := json.MarshalIndent(nodeConfig, "", " ")
if err != nil {
log.Fatalf(err.Error())

if configPath != "" {
err := sdkutils.ReadYamlConfig(configPath, &nodeConfig)
if err != nil {
return err
}
configJson, err := json.MarshalIndent(nodeConfig, "", " ")
if err != nil {
log.Fatalf(err.Error())
}
log.Println("Config:", string(configJson))
}
log.Println("Config:", string(configJson))

operator, err := operator.NewOperatorFromConfig(nodeConfig)
if err != nil {
Expand Down
40 changes: 40 additions & 0 deletions cli/actions/deregister_operator_with_avs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package actions

import (
"encoding/json"
"log"

sdkutils "github.com/Layr-Labs/eigensdk-go/utils"
"github.com/alt-research/avs/core/config"
"github.com/alt-research/avs/operator"
"github.com/urfave/cli"
)

func DeregisterOperatorWithAvs(ctx *cli.Context) error {
configPath := ctx.GlobalString(config.ConfigFileFlag.Name)
nodeConfig := config.NodeConfig{}

if configPath != "" {
err := sdkutils.ReadYamlConfig(configPath, &nodeConfig)
if err != nil {
return err
}
configJson, err := json.MarshalIndent(nodeConfig, "", " ")
if err != nil {
log.Fatalf(err.Error())
}
log.Println("Config:", string(configJson))
}

operator, err := operator.NewOperatorFromConfig(nodeConfig)
if err != nil {
return err
}

err = operator.DeregisterOperatorWithAvs()
if err != nil {
return err
}

return nil
}
19 changes: 11 additions & 8 deletions cli/actions/print_operator_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ func PrintOperatorStatus(ctx *cli.Context) error {

configPath := ctx.GlobalString(config.ConfigFileFlag.Name)
nodeConfig := config.NodeConfig{}
err := sdkutils.ReadYamlConfig(configPath, &nodeConfig)
if err != nil {
return err
}
configJson, err := json.MarshalIndent(nodeConfig, "", " ")
if err != nil {
log.Fatalf(err.Error())

if configPath != "" {
err := sdkutils.ReadYamlConfig(configPath, &nodeConfig)
if err != nil {
return err
}
configJson, err := json.MarshalIndent(nodeConfig, "", " ")
if err != nil {
log.Fatalf(err.Error())
}
log.Println("Config:", string(configJson))
}
log.Println("Config:", string(configJson))

operator, err := operator.NewOperatorFromConfig(nodeConfig)
if err != nil {
Expand Down
21 changes: 12 additions & 9 deletions cli/actions/register_operator_with_avs.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@ func RegisterOperatorWithAvs(ctx *cli.Context) error {

configPath := ctx.GlobalString(config.ConfigFileFlag.Name)
nodeConfig := config.NodeConfig{}
err := sdkutils.ReadYamlConfig(configPath, &nodeConfig)
if err != nil {
return err
}
configJson, err := json.MarshalIndent(nodeConfig, "", " ")
if err != nil {
log.Fatalf(err.Error())

if configPath != "" {
err := sdkutils.ReadYamlConfig(configPath, &nodeConfig)
if err != nil {
return err
}
configJson, err := json.MarshalIndent(nodeConfig, "", " ")
if err != nil {
log.Fatalf(err.Error())
}
log.Println("Config:", string(configJson))
}
log.Println("Config:", string(configJson))

operator, err := operator.NewOperatorFromConfig(nodeConfig)
if err != nil {
Expand All @@ -36,7 +39,7 @@ func RegisterOperatorWithAvs(ctx *cli.Context) error {
log.Printf("OPERATOR_ECDSA_KEY_PASSWORD env var not set. using empty string")
}
operatorEcdsaPrivKey, err := sdkecdsa.ReadKey(
nodeConfig.EcdsaPrivateKeyStorePath,
operator.Config().EcdsaPrivateKeyStorePath,
ecdsaKeyPassword,
)
if err != nil {
Expand Down
19 changes: 11 additions & 8 deletions cli/actions/register_operator_with_eigenlayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@ func RegisterOperatorWithEigenlayer(ctx *cli.Context) error {

configPath := ctx.GlobalString(config.ConfigFileFlag.Name)
nodeConfig := config.NodeConfig{}
err := sdkutils.ReadYamlConfig(configPath, &nodeConfig)
if err != nil {
return err
}
configJson, err := json.MarshalIndent(nodeConfig, "", " ")
if err != nil {
log.Fatalf(err.Error())

if configPath != "" {
err := sdkutils.ReadYamlConfig(configPath, &nodeConfig)
if err != nil {
return err
}
configJson, err := json.MarshalIndent(nodeConfig, "", " ")
if err != nil {
log.Fatalf(err.Error())
}
log.Println("Config:", string(configJson))
}
log.Println("Config:", string(configJson))

operator, err := operator.NewOperatorFromConfig(nodeConfig)
if err != nil {
Expand Down
5 changes: 1 addition & 4 deletions cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ func main() {
{
Name: "deregister-operator-with-avs",
Aliases: []string{"d"},
Action: func(ctx *cli.Context) error {
log.Fatal("Command not implemented.")
return nil
},
Action: actions.DeregisterOperatorWithAvs,
},
{
Name: "print-operator-status",
Expand Down
1 change: 1 addition & 0 deletions core/config/avs_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ type NodeConfig struct {
EnableNodeApi bool `yaml:"enable_node_api"`
OperatorServerIpPortAddr string `yaml:"operator_server_ip_port_addr"`
MetadataURI string `yaml:"metadata_uri"`
OperatorSocket string `yaml:"operator_socket"`
}
2 changes: 1 addition & 1 deletion core/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ var (
/* Required Flags */
ConfigFileFlag = cli.StringFlag{
Name: "config",
Required: true,
Required: false,
Usage: "Load configuration from `FILE`",
}
DeploymentFileFlag = cli.StringFlag{
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ services:
contracts-deploy:
build:
context: .
dockerfile: contract-deployer.Dockerfile
dockerfile: ./ops/contract-deployer.Dockerfile
container_name: contracts-deploy
working_dir: /app/
volumes:
Expand Down
19 changes: 11 additions & 8 deletions operator/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,18 @@ func operatorMain(ctx *cli.Context) error {
log.Println("Initializing Operator")
configPath := ctx.GlobalString(config.ConfigFileFlag.Name)
nodeConfig := config.NodeConfig{}
err := sdkutils.ReadYamlConfig(configPath, &nodeConfig)
if err != nil {
return err
}
configJson, err := json.MarshalIndent(nodeConfig, "", " ")
if err != nil {
log.Fatalf(err.Error())

if configPath != "" {
err := sdkutils.ReadYamlConfig(configPath, &nodeConfig)
if err != nil {
return err
}
configJson, err := json.MarshalIndent(nodeConfig, "", " ")
if err != nil {
log.Fatalf(err.Error())
}
log.Println("Config from file:", string(configJson))
}
log.Println("Config from file:", string(configJson))

log.Println("initializing operator")
operator, err := operator.NewOperatorFromConfig(nodeConfig)
Expand Down
14 changes: 14 additions & 0 deletions operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ func withEnvConfig(c config.NodeConfig) config.NodeConfig {
// - `OPERATOR_SERVER_URL` : operator_server_ip_port_addr
// - `METADATA_URI` : metadata_uri

Production, ok := os.LookupEnv("OPERATOR_PRODUCTION")
if ok && Production != "" {
c.Production = Production == "true"
}

ethRpcUrl, ok := os.LookupEnv("ETH_RPC_URL")
if ok && ethRpcUrl != "" {
c.EthRpcUrl = ethRpcUrl
Expand Down Expand Up @@ -147,6 +152,11 @@ func withEnvConfig(c config.NodeConfig) config.NodeConfig {
c.MetadataURI = metadataURI
}

operatorSocket, ok := os.LookupEnv("OPERATOR_SOCKET")
if ok && operatorSocket != "" {
c.OperatorSocket = operatorSocket
}

configJson, err := json.MarshalIndent(c, "", " ")
if err != nil {
panic(err)
Expand Down Expand Up @@ -443,3 +453,7 @@ func (o *Operator) SignTaskResponse(taskResponse *message.AlertTaskInfo) (*messa
o.logger.Debug("Signed task response", "signedTaskResponse", signedTaskResponse)
return signedTaskResponse, nil
}

func (o Operator) Config() config.NodeConfig {
return o.config
}
Loading