-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added a basic ion-connect-indexer cmd impl
- Loading branch information
Showing
4 changed files
with
124 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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() }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
96
cmd/subzero-ion-connect-indexer/subzero_ion_connect_indexer.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |