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

chore: add local sequencer and docker file #20

Merged
merged 6 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build/
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM --platform=$BUILDPLATFORM golang:1.23-alpine AS build-env

# Set working directory for the build
WORKDIR /src

COPY . .

RUN go mod tidy -compat=1.19 && \
gupadhyaya marked this conversation as resolved.
Show resolved Hide resolved
go build /src/cmd/local-sequencer/main.go
gupadhyaya marked this conversation as resolved.
Show resolved Hide resolved

# Final image
FROM alpine:3.18.3

WORKDIR /root

# Copy over binaries from the build-env
COPY --from=build-env /src/main /usr/bin/local-sequencer

EXPOSE 7980

CMD ["local-sequencer", "-listen-all"]
gupadhyaya marked this conversation as resolved.
Show resolved Hide resolved
gupadhyaya marked this conversation as resolved.
Show resolved Hide resolved
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
LDFLAGS=-ldflags="-X '$(versioningPath).buildTime=$(shell date)' -X '$(versioningPath).lastCommit=$(shell git rev-parse HEAD)' -X '$(versioningPath).semanticVersion=$(shell git describe --tags --dirty=-dev 2>/dev/null || git rev-parse --abbrev-ref HEAD)'"
DOCKER := $(shell which docker)
DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf

Expand All @@ -7,6 +8,12 @@ pkgs := $(shell go list ./...)
run := .
count := 1

## build: Build local-da binary.
build:
@echo "--> Building local-sequencer"
@go build -o build/ ${LDFLAGS} ./...
.PHONY: build

## help: Show this help message
help: Makefile
@echo " Choose a command run in "$(PROJECTNAME)":"
Expand Down Expand Up @@ -40,6 +47,7 @@ lint: vet
@golangci-lint run
@echo "--> Running markdownlint"
@markdownlint --config .markdownlint.yaml '**/*.md'
@hadolint Dockerfile
@echo "--> Running yamllint"
@yamllint --no-warnings . -c .yamllint.yml

Expand Down
57 changes: 57 additions & 0 deletions cmd/local-sequencer/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package main

import (
"flag"
"fmt"
"log"
"net"
"os"
"os/signal"
"syscall"

"github.com/rollkit/go-sequencing/proxy/grpc"
"github.com/rollkit/go-sequencing/test"
)

const (
defaultHost = "localhost"
defaultPort = "50051"
defaultRollupId = "rollup-id"
)

func main() {
var (
host string
port string
rollupId string
listenAll bool
)
flag.StringVar(&port, "port", defaultPort, "listening port")
flag.StringVar(&host, "host", defaultHost, "listening address")
flag.StringVar(&rollupId, "rollup-id", defaultRollupId, "rollup id")
flag.BoolVar(&listenAll, "listen-all", false, "listen on all network interfaces (0.0.0.0) instead of just localhost")
flag.Parse()

if listenAll {
host = "0.0.0.0"
}

d := test.NewDummySequencer([]byte(rollupId))
srv := grpc.NewServer(d, d, d)
log.Printf("Listening on: %s:%s", host, port)

listenAddress := fmt.Sprintf("%s:%s", host, port)
lis, err := net.Listen("tcp", listenAddress)
if err != nil {
log.Fatal("error while serving:", err)
}
go func() {
_ = srv.Serve(lis)
}()

interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt, syscall.SIGINT)
<-interrupt
fmt.Println("\nCtrl+C pressed. Exiting...")
os.Exit(0)
}
gupadhyaya marked this conversation as resolved.
Show resolved Hide resolved
Loading