Skip to content

Commit

Permalink
Bug fix, flag rename and Docker images
Browse files Browse the repository at this point in the history
  • Loading branch information
maoueh committed May 19, 2023
1 parent 49ed104 commit d55c5c8
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 18 deletions.
9 changes: 1 addition & 8 deletions .sfreleaser
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,5 @@ global:
language: golang
variant: application
release:
# You need a specialized goreleaser-cross image that contains WasmEdge (include/lib(s))
# for each supported platform. For now, we do not publish this image to a public
# Docker registry. So you need to build it manually with
#
# ./devel/docker/push.sh
#
# It will build the image locally, then you will be able to release.
goreleaser-docker-image: goreleaser-cross-wasmedge:v1.20.3
goreleaser-docker-image: ghcr.io/streamingfast/substreams-sink-kv-builder:v1.20.3
upload-substreams-spkg: substreams.yaml
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## v2.1.2

### Changed

* _Deprecation_ The flag `substreams-sink-kv inject --listen-addr=...` must now be used like `substreams-sink-kv inject --server-listen-addr=...`

### Fixed

* Added back missing flag `--server-api-prefix` to define API prefix when server mode is active.

## v2.1.1

### Added
Expand Down
15 changes: 12 additions & 3 deletions cmd/substreams-sink-kv/inject.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"github.com/streamingfast/cli"
. "github.com/streamingfast/cli"
"github.com/streamingfast/cli/sflags"
Expand All @@ -25,8 +24,12 @@ var injectCmd = Command(injectRunE,
sink.AddFlagsToSet(flags)

flags.Int("flush-interval", 1000, "When in catch up mode, flush every N blocks")
flags.String("listen-addr", "", "Launch query server on this address")
flags.String("module", "", "An explicit module to sink, if not provided, expecting the Substreams manifest to defined 'sink' configuration")
flags.String("server-listen-addr", "", "Launch query server on this address")
flags.String("server-api-prefix", "", "Launch query server with this API prefix so the URl to query is <server-listen-addr>/<server-api-prefix>")

flags.String("listen-addr", "", "Launch query server on this address")
flags.Lookup("listen-addr").Deprecated = "use --server-listen-addr instead"
}),
Description(`
Fills a KV store from a Substreams output and optionally runs a server. Authentication
Expand Down Expand Up @@ -108,7 +111,13 @@ func injectRunE(cmd *cobra.Command, args []string) error {
kvSinker.Run(ctx)
}()

if listenAddr := viper.GetString("inject-listen-addr"); listenAddr != "" {
listenAddr, provided := sflags.MustGetStringProvided(cmd, "server-listen-addr")
if !provided {
// Fallback to deprecated flag
listenAddr = sflags.MustGetString(cmd, "listen-addr")
}

if listenAddr != "" {
zlog.Info("setting up query server", zap.String("dsn", dsn), zap.String("listen_addr", listenAddr))
server, err := setupServer(cmd, sink.Package(), kvDB)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions cmd/substreams-sink-kv/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ var serveCmd = Command(serveRunE,
Flags(func(flags *pflag.FlagSet) {
flags.String("listen-addr", ":7878", "Listen via GRPC Connect-Web on this address")
flags.Bool("listen-ssl-self-signed", false, "Listen with an HTTPS server (with self-signed certificate)")
flags.String("api-prefix", "", "Prefix that will be added to the Connect Web routes")
}),
Description(`
Test
Expand Down Expand Up @@ -128,7 +127,7 @@ func setupServer(cmd *cobra.Command, pkg *pbsubstreams.Package, kvDB *db.DB) (se
return nil, fmt.Errorf("find proto file descriptor: %w", err)
}

config, err := wasmquery.NewServiceConfig(fileDesc, wasmServ.GrpcService, sflags.MustGetString(cmd, "api-prefix"))
config, err := wasmquery.NewServiceConfig(fileDesc, wasmServ.GrpcService, sflags.MustGetString(cmd, "server-api-prefix"))
if err != nil {
return nil, fmt.Errorf("failed to setup grpc config: %w", err)
}
Expand Down
File renamed without changes.
26 changes: 26 additions & 0 deletions devel/docker/Dockerfile.runtime
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM ubuntu:20.04

ARG TARGETOS
ARG TARGETARCH
ARG VERSION

RUN DEBIAN_FRONTEND=noninteractive apt-get update && \
apt-get -y install -y \
ca-certificates libssl1.1 vim htop iotop sysstat \
dstat strace lsof curl wget jq tzdata && \
rm /etc/localtime && \
ln -snf /usr/share/zoneinfo/America/Montreal /etc/localtime && \
dpkg-reconfigure -f noninteractive tzdata && \
apt-get -y install -y git && \
rm -rf /var/cache/apt /var/lib/apt/lists/*

RUN cd /root &&\
curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash -s -- --version 0.11.2

RUN cd /root &&\
wget -O substreams-sink-kv.tar.gz https://github.com/streamingfast/substreams-sink-kv/releases/download/$VERSION/substreams-sink-kv_linux_x86_64.tar.gz &&\
tar -xzvf substreams-sink-kv.tar.gz &&\
cp -R substreams-sink-kv /usr/local/bin/ &&\
rm -rf LICENSE README.md

ENTRYPOINT [ "/usr/local/bin/substreams-sink-kv" ]
31 changes: 26 additions & 5 deletions devel/docker/push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,44 @@

ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

tag_host="ghcr.io/streamingfast/"

main() {
pushd "$ROOT" &> /dev/null

while getopts "h" opt; do
while getopts "hl" opt; do
case $opt in
h) usage && exit 0;;
l) tag_host="";;
\?) usage_error "Invalid option: -$OPTARG";;
esac
done
shift $((OPTIND-1))

docker_file="$1"; shift
if [[ $docker_file == "" ]]; then
docker_file="Dockerfile.goreleaser"
if [[ $# -ge 1 ]]; then
version="$1"; shift
fi

if [[ ! -f "$docker_file" ]]; then
usage_error "Provided Dockerfile '$docker_file' does not exist"
fi

if [[ "$version" == "" ]]; then
version=`git -c 'versionsort.suffix=-' ls-remote --exit-code --refs --sort='version:refname' --tags origin '*.*.*' | tail -n1 | tr "\t" " " | cut -d ' ' -f 2 | sed 's|refs/tags/||g'`
fi

name="`printf $docker_file | sed 's/Dockerfile.//g'`"

if [[ "$name" == "runtime" ]]; then
build_args="--build-arg='VERSION=$version' --platform=linux/amd64 -t '${tag_host}substreams-sink-kv:$version'"
elif [[ "$name" == "builder" ]]; then
build_args="--build-arg='VERSION=$version' --platform=linux/amd64,linux/arm64 -t ${tag_host}substreams-sink-kv-builder:v1.20.3"
else
usage_error "Unknown Dockerfile '$docker_file'"
fi

docker build -f "$docker_file" . -t goreleaser-cross-wasmedge:v1.20.3
docker buildx build -f "$docker_file" . --push $build_args
}

usage_error() {
Expand All @@ -32,7 +53,7 @@ usage_error() {
}

usage() {
echo "usage: push.sh <Dockerfile>"
echo "usage: push.sh <dockerfile> [<version>]"
echo ""
echo "Builds and push the following Dockefile with the correct tags."
echo ""
Expand Down

0 comments on commit d55c5c8

Please sign in to comment.