diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index df3f064..bd8fab7 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -16,7 +16,7 @@ jobs: with: go-version: '1.21' - name: build - run: go build -v ./... + run: make build - name: golangci-lint run: make lint - name: format diff --git a/.gitignore b/.gitignore index bc8733f..f1b5acc 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,6 @@ # Go workspace file go.work + +# Folders +/bin/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8ff79f2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +ARG GOLANG_VERSION=1 +# Pull golang alpine to build binary +FROM golang:${GOLANG_VERSION}-alpine as builder + +RUN apk add --no-cache make + +WORKDIR /app + +# Build binary +COPY . . +RUN make build + +# Use alpine to run app +FROM alpine +RUN adduser -D onchain && \ + mkdir /home/onchain/faultdetector && \ + chown -R onchain:onchain /home/onchain/ +USER onchain +WORKDIR /home/onchain/faultdetector +COPY --from=builder /app/bin/faultdetector ./bin/ +COPY --from=builder /app/config.yaml . + +EXPOSE 8080 + +# Run app +CMD [ "./bin/faultdetector" ] diff --git a/Makefile b/Makefile index 83d8818..ae3d980 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,23 @@ PKGS=$(shell go list ./... | grep -v "/vendor/") .PHONY: test +APP_NAME = faultdetector +GREEN = \033[0;32m +BLUE = \033[0;34m +COLOR_END = \033[0;39m + +build: + @echo "$(BLUE)ยป Building fault detector application binary... $(COLOR_END)" + @CGO_ENABLED=0 go build -a -v -o bin/$(APP_NAME) ./cmd/ + @echo "$(GREEN) Binary successfully built$(COLOR_END)" + +run-app: +ifdef config + @./bin/${APP_NAME} --config $(config) +else + @./bin/${APP_NAME} +endif + test: @echo "Test packages" @go test -race -shuffle=on -coverprofile=coverage.out -cover $(PKGS) @@ -24,4 +41,19 @@ format: godocs: @go install golang.org/x/tools/cmd/godoc@latest @echo "open http://localhost:6060/pkg/github.com/LiskHQ/op-fault-detector" - godoc -http=:6060 \ No newline at end of file + godoc -http=:6060 + +.PHONY: docker-build +docker-build: + @echo "$(BLUE) Building docker image...$(COLOR_END)" + @docker build -t $(APP_NAME) . + +.PHONY: docker-run +docker-run: +ifdef config + @echo "$(BLUE) Running docker image...$(COLOR_END)" + @docker run -p 8080:8080 -v $(config):/home/onchain/faultdetector/config.yaml -t $(APP_NAME) +else + @echo "$(BLUE) Running docker image...$(COLOR_END)" + @docker run -p 8080:8080 $(APP_NAME) +endif diff --git a/config.yaml b/config.yaml index adadf51..79a2541 100644 --- a/config.yaml +++ b/config.yaml @@ -15,5 +15,5 @@ api: fault_detector: l1_rpc_endpoint: "https://rpc.notadegen.com/eth" l2_rpc_endpoint: "https://mainnet.optimism.io/" - start_batch_index: 0 + start_batch_index: -1 l2_output_oracle_contract_address: "0x0000000000000000000000000000000000000000" diff --git a/go.mod b/go.mod index a2a95b5..690e405 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/LiskHQ/op-fault-detector -go 1.21.5 +go 1.21 require ( github.com/ethereum-optimism/optimism v1.4.2