Skip to content

Commit

Permalink
Add docker support (#26)
Browse files Browse the repository at this point in the history
* 🐳 Add docker support

* ♻️ Add user and use ARG in Dockerfile

* ♻️ Use build in PR workflow

* ♻️ Handle config arg for make cmds
  • Loading branch information
ishantiw authored Feb 8, 2024
1 parent ae0567e commit c329aee
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@

# Go workspace file
go.work

# Folders
/bin/
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]
34 changes: 33 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
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
2 changes: 1 addition & 1 deletion config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit c329aee

Please sign in to comment.