Skip to content
This repository was archived by the owner on May 2, 2025. It is now read-only.

Commit c5564f1

Browse files
authored
chore: add local sequencer and docker file (#20)
* add local sequencer and docker file * add docker build to ci * upgrade compat to go 1.23 * expose 50051
1 parent c655a9f commit c5564f1

File tree

5 files changed

+107
-0
lines changed

5 files changed

+107
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Docker Build & Publish
2+
3+
# Trigger on all push events, new semantic version tags, and all PRs
4+
on:
5+
push:
6+
branches:
7+
- "main"
8+
tags:
9+
- "v*"
10+
pull_request:
11+
12+
jobs:
13+
go-sequencing-docker:
14+
permissions:
15+
contents: write
16+
packages: write
17+
uses: rollkit/.github/.github/workflows/[email protected] # yamllint disable-line rule:line-length
18+
with:
19+
dockerfile: Dockerfile
20+
secrets: inherit

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build/

Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
FROM --platform=$BUILDPLATFORM golang:1.23-alpine AS build-env
2+
3+
# Set working directory for the build
4+
WORKDIR /src
5+
6+
COPY . .
7+
8+
RUN go mod tidy -compat=1.23 && \
9+
go build /src/cmd/local-sequencer/main.go
10+
11+
# Final image
12+
FROM alpine:3.18.3
13+
14+
WORKDIR /root
15+
16+
# Copy over binaries from the build-env
17+
COPY --from=build-env /src/main /usr/bin/local-sequencer
18+
19+
EXPOSE 50051
20+
21+
CMD ["local-sequencer", "-listen-all"]

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
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)'"
12
DOCKER := $(shell which docker)
23
DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf
34

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

11+
## build: Build local-da binary.
12+
build:
13+
@echo "--> Building local-sequencer"
14+
@go build -o build/ ${LDFLAGS} ./...
15+
.PHONY: build
16+
1017
## help: Show this help message
1118
help: Makefile
1219
@echo " Choose a command run in "$(PROJECTNAME)":"
@@ -40,6 +47,7 @@ lint: vet
4047
@golangci-lint run
4148
@echo "--> Running markdownlint"
4249
@markdownlint --config .markdownlint.yaml '**/*.md'
50+
@hadolint Dockerfile
4351
@echo "--> Running yamllint"
4452
@yamllint --no-warnings . -c .yamllint.yml
4553

cmd/local-sequencer/main.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package main
2+
3+
import (
4+
"flag"
5+
"fmt"
6+
"log"
7+
"net"
8+
"os"
9+
"os/signal"
10+
"syscall"
11+
12+
"github.com/rollkit/go-sequencing/proxy/grpc"
13+
"github.com/rollkit/go-sequencing/test"
14+
)
15+
16+
const (
17+
defaultHost = "localhost"
18+
defaultPort = "50051"
19+
defaultRollupId = "rollup-id"
20+
)
21+
22+
func main() {
23+
var (
24+
host string
25+
port string
26+
rollupId string
27+
listenAll bool
28+
)
29+
flag.StringVar(&port, "port", defaultPort, "listening port")
30+
flag.StringVar(&host, "host", defaultHost, "listening address")
31+
flag.StringVar(&rollupId, "rollup-id", defaultRollupId, "rollup id")
32+
flag.BoolVar(&listenAll, "listen-all", false, "listen on all network interfaces (0.0.0.0) instead of just localhost")
33+
flag.Parse()
34+
35+
if listenAll {
36+
host = "0.0.0.0"
37+
}
38+
39+
d := test.NewDummySequencer([]byte(rollupId))
40+
srv := grpc.NewServer(d, d, d)
41+
log.Printf("Listening on: %s:%s", host, port)
42+
43+
listenAddress := fmt.Sprintf("%s:%s", host, port)
44+
lis, err := net.Listen("tcp", listenAddress)
45+
if err != nil {
46+
log.Fatal("error while serving:", err)
47+
}
48+
go func() {
49+
_ = srv.Serve(lis)
50+
}()
51+
52+
interrupt := make(chan os.Signal, 1)
53+
signal.Notify(interrupt, os.Interrupt, syscall.SIGINT)
54+
<-interrupt
55+
fmt.Println("\nCtrl+C pressed. Exiting...")
56+
os.Exit(0)
57+
}

0 commit comments

Comments
 (0)