From 3c3e9ea23e2498ea197b9aca49faa9a676432ad3 Mon Sep 17 00:00:00 2001 From: gupadhyaya Date: Fri, 18 Oct 2024 22:43:22 +0400 Subject: [PATCH 1/4] add local sequencer and docker file --- .gitignore | 1 + Dockerfile | 21 ++++++++++++++ Makefile | 8 ++++++ cmd/local-sequencer/main.go | 57 +++++++++++++++++++++++++++++++++++++ 4 files changed, 87 insertions(+) create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 cmd/local-sequencer/main.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d163863 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e0dd22a --- /dev/null +++ b/Dockerfile @@ -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 && \ + go build /src/cmd/local-sequencer/main.go + +# 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"] \ No newline at end of file diff --git a/Makefile b/Makefile index b624ad1..04f5561 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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)":" @@ -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 diff --git a/cmd/local-sequencer/main.go b/cmd/local-sequencer/main.go new file mode 100644 index 0000000..686fcca --- /dev/null +++ b/cmd/local-sequencer/main.go @@ -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) +} From 37b7949382b948a4735be78c1ac77c499a728a6e Mon Sep 17 00:00:00 2001 From: gupadhyaya Date: Tue, 22 Oct 2024 09:26:10 +0400 Subject: [PATCH 2/4] add docker build to ci --- .github/workflows/docker-build-publish.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .github/workflows/docker-build-publish.yml diff --git a/.github/workflows/docker-build-publish.yml b/.github/workflows/docker-build-publish.yml new file mode 100644 index 0000000..1c606dd --- /dev/null +++ b/.github/workflows/docker-build-publish.yml @@ -0,0 +1,20 @@ +name: Docker Build & Publish + +# Trigger on all push events, new semantic version tags, and all PRs +on: + push: + branches: + - "main" + tags: + - "v*" + pull_request: + +jobs: + go-sequencing-docker: + permissions: + contents: write + packages: write + uses: rollkit/.github/.github/workflows/reusable_dockerfile_pipeline.yml@v0.4.1 # yamllint disable-line rule:line-length + with: + dockerfile: Dockerfile + secrets: inherit From 63f65f5c5c9c806c1f3c876292d8882f27f7ea92 Mon Sep 17 00:00:00 2001 From: gupadhyaya Date: Tue, 22 Oct 2024 19:07:58 +0400 Subject: [PATCH 3/4] upgrade compat to go 1.23 --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index e0dd22a..f0d25a4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,7 @@ WORKDIR /src COPY . . -RUN go mod tidy -compat=1.19 && \ +RUN go mod tidy -compat=1.23 && \ go build /src/cmd/local-sequencer/main.go # Final image From dff6ddcfd9866bf0747abe2619cd125ed7c11441 Mon Sep 17 00:00:00 2001 From: gupadhyaya Date: Tue, 22 Oct 2024 19:11:04 +0400 Subject: [PATCH 4/4] expose 50051 --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index f0d25a4..6ecec33 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,6 +16,6 @@ WORKDIR /root # Copy over binaries from the build-env COPY --from=build-env /src/main /usr/bin/local-sequencer -EXPOSE 7980 +EXPOSE 50051 CMD ["local-sequencer", "-listen-all"] \ No newline at end of file