Skip to content

Commit

Permalink
added a basic ion-connect-indexer cmd impl
Browse files Browse the repository at this point in the history
  • Loading branch information
ice-ares committed Dec 19, 2024
1 parent cef5879 commit 24b765e
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 2 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/CICD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ jobs:
make_latest: true
files: |
subzero-ion-connect.linux.amd64.bin
subzero-ion-connect-indexer.linux.amd64.bin
- name: Slack Notification For Failure/Cancellation
if: ${{ github.event_name == 'push' && (failure() || cancelled()) }}
uses: rtCamp/action-slack-notify@v2
Expand Down Expand Up @@ -376,13 +377,20 @@ jobs:
cmd: |
cd secret-infrastructure
yq e -i '.generic-service-chart.applicationImage.tag = strenv(APP_TAG)' helm/subzero-ion-connect/staging/common-values.yaml
- name: Update [staging] application tag version in helm/subzero-ion-connect-indexer/staging/common-values.yaml
uses: mikefarah/yq@master
with:
cmd: |
cd secret-infrastructure
yq e -i '.generic-service-chart.applicationImage.tag = strenv(APP_TAG)' helm/subzero-ion-connect-indexer/staging/common-values.yaml
- name: Commit and Push Changes to Application Tag Version
run: |
cd secret-infrastructure
git config user.name "ice CI/CD Bot"
git config user.email [email protected]
git add helm/subzero-ion-connect/staging/common-values.yaml
git commit -m "Updated 'subzero-ion-connect' tag version (${{env.APP_TAG}}) in application helm chart deployment manifests"
git add helm/subzero-ion-connect-indexer/staging/common-values.yaml
git commit -m "Updated 'subzero-ion-connect' & 'subzero-ion-connect-indexer' tag version (${{env.APP_TAG}}) in application helm chart deployment manifests"
git push --set-upstream origin master
- name: Slack Notification For Success
if: ${{ success() }}
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ format-imports:

buildAllBinaries:
set -xe; \
find ./cmd -mindepth 1 -maxdepth 1 -type d -print | grep -v 'fixture' | grep -v 'scripts' | while read service; do \
find ./cmd -mindepth 1 -maxdepth 1 -type d -print | grep -v 'fixture' | grep -v 'scripts' | grep -v 'subzero-ion-connect-keygen' | while read service; do \
env SERVICE_NAME=$${service##*/} env GOOS=$(GOOS) env GOARCH=$(GOARCH) $(MAKE) binary-specific-service; \
done;

Expand Down
18 changes: 18 additions & 0 deletions cmd/subzero-ion-connect-indexer/.testdata/regenerate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# SPDX-License-Identifier: ice License 1.0

# Generate a new ecdsa key/cert for local development of WebTransport
HOST="localhost"
CRT="$HOST.crt"
KEY="$HOST.key"
# Install the system certificate if it's not already
go get filippo.io/mkcert
go run filippo.io/mkcert -ecdsa -install
cp $(go run filippo.io/mkcert -CAROOT)/rootCA.pem ca.pem

# Generate a new certificate for localhost
NETWORK_IP=$(ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1' | tail -1)
go run filippo.io/mkcert -ecdsa -days 13 -cert-file "$CRT" -key-file "$KEY" localhost $(hostname) 127.0.0.1 ::1 $NETWORK_IP

# Compute the sha256 fingerprint of the certificate for WebTransport
rm fingerprint.base64 || true
openssl x509 -in localhost.crt | openssl dgst -sha256 -binary | base64 > fingerprint.base64
96 changes: 96 additions & 0 deletions cmd/subzero-ion-connect-indexer/subzero_ion_connect_indexer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// SPDX-License-Identifier: ice License 1.0

package main

import (
"context"
"log"
"os"
"os/signal"
"syscall"

"github.com/cockroachdb/errors"
"github.com/spf13/cobra"

"github.com/ice-blockchain/subzero/cfg"
"github.com/ice-blockchain/subzero/database/command"
"github.com/ice-blockchain/subzero/database/query"
"github.com/ice-blockchain/subzero/dvm"
"github.com/ice-blockchain/subzero/model"
"github.com/ice-blockchain/subzero/server"
wsserver "github.com/ice-blockchain/subzero/server/ws"
)

var (
configPath string
ionConnectIndexer = &cobra.Command{
Use: "subzero-ion-connect-indexer",
Short: "subzero-ion-connect-indexer",
Run: func(cmd *cobra.Command, _ []string) {
cfg.MustInit(configPath)
query.MustInit(cmd.Context())
dvm.MustInit()
server.MustListenAndServe(cmd.Context())
},
}
initFlags = func() {
ionConnectIndexer.Flags().StringVar(&configPath, "config", cfg.DefaultYAMLConfigurationFilePath, "absolute path to the service config yaml file")
}
)

func init() {
initFlags()
wsserver.RegisterReqMustAuthenticate(func(_ context.Context, sub *model.Subscription) (authRequired bool) {
authRequired = sub != nil

return authRequired
})
wsserver.RegisterEventMustAuthenticate(func(_ context.Context, _ ...*model.Event) (authRequired bool) {
authRequired = true

return authRequired
})
wsserver.RegisterWSEventListener(func(ctx context.Context, events ...*model.Event) error {
if err := command.AcceptEvents(ctx, events...); err != nil {
return errors.Wrapf(err, "failed to command.AcceptEvent(%#v)", events)
}
if err := query.AcceptEvents(ctx, events...); err != nil {
return errors.Wrapf(err, "failed to query.AcceptEvent(%#v)", events)
}
if err := dvm.AcceptJob(ctx, events[0]); err != nil {
return errors.Wrapf(err, "failed to dvm.AcceptEvent(%#v)", events[0])
}

return nil
})
wsserver.RegisterWSSubscriptionListener(query.GetStoredEvents)
}

func newContext() context.Context {
ctx, cancel := context.WithCancel(context.Background())

c := make(chan os.Signal, 2)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
force := false
for sig := range c {
if force {
log.Println("force shutdown", "signal", sig.String())
os.Exit(2)
} else {
log.Println("graceful shutdown", "signal", sig.String())
cancel()
force = true
}
}
}()

return ctx
}

func main() {
err := ionConnectIndexer.ExecuteContext(newContext())
if err != nil {
log.Panic(err)
}
}

0 comments on commit 24b765e

Please sign in to comment.