From ec58713e0f539feceb77bf19fa965b40f5d19926 Mon Sep 17 00:00:00 2001 From: nagdahimanshu Date: Tue, 18 Jun 2024 13:41:21 +0200 Subject: [PATCH] :seedling: Add Makefile --- Makefile | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 22 +++++++++++----------- 2 files changed, 66 insertions(+), 11 deletions(-) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..890d623 --- /dev/null +++ b/Makefile @@ -0,0 +1,55 @@ + +APP_NAME = lsk-faucet +PKGS=$(shell go list ./... | grep -v "/vendor/") +BLUE = \033[1;34m +GREEN = \033[1;32m +COLOR_END = \033[0;39m + +build: build-backend build-frontend + +build-backend: # Builds the application and create a binary at ./bin/ + @echo "$(BLUE)» Building $(APP_NAME) application binary... $(COLOR_END)" + @go build -a -o bin/$(APP_NAME) . + @echo "$(GREEN) Binary successfully built$(COLOR_END)" + +build-frontend: # Builds the frontned application + @echo "$(BLUE)» Building frontend... $(COLOR_END)" + @go generate + @echo "$(GREEN) Frontend successfully built$(COLOR_END)" + +run: # Runs the application, use `make run FLAGS="--help"` + @./bin/${APP_NAME} ${FLAGS} + +.PHONY: test +test: # Runs tests + @echo "Test packages" + @go test -race -shuffle=on -coverprofile=coverage.out -cover $(PKGS) + +lint: # Runs golangci-lint on the repo + @go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest + golangci-lint run + +format: # Runs gofmt on the repo + gofmt -s -w . + +.PHONY: docker-build +build-image: # Builds docker image + @echo "$(BLUE) Building docker image...$(COLOR_END)" + @docker build -t $(APP_NAME) . + +.PHONY: docker-run +docker-start: # Runs docker image + @echo "$(BLUE) Starting docker container $(APP_NAME)...$(COLOR_END)" +ifdef PRIVATE_KEY + @docker run --name $(APP_NAME) -p 8080:8080 -d -e WEB3_PROVIDER=$(WEB3_PROVIDER) -e PRIVATE_KEY=$(PRIVATE_KEY) $(APP_NAME) +else ifdef KEYSTORE + @docker run --name $(APP_NAME) -p 8080:8080 -d -e WEB3_PROVIDER=$(WEB3_PROVIDER) -e KEYSTORE=$(KEYSTORE) -v $(KEYSTORE)/keystore:/app/keystore -v $(KEYSTORE)/password.txt:/app/password.txt $(APP_NAME) +endif + +docker-stop: + @echo "$(BLUE) Stopping and removing docker container $(APP_NAME)...$(COLOR_END)" + @docker rm -f $(APP_NAME) + +.PHONY: help +help: # Show help for each of the Makefile recipes + @grep -E '^[a-zA-Z0-9 -]+:.*#' Makefile | sort | while read -r l; do printf "$(GREEN)$$(echo $$l | cut -f 1 -d':')$(COLOR_END):$$(echo $$l | cut -f 2- -d'#')\n"; done \ No newline at end of file diff --git a/README.md b/README.md index ccf9670..0bd6b24 100644 --- a/README.md +++ b/README.md @@ -32,15 +32,16 @@ cd lsk-faucet ``` 2. Bundle Frontend web with Vite -Please make sure to replace token icon at `web/public/token.png` with the specific ERC20 token icon. + +**NOTE**: Please make sure to replace token icon at `web/public/token.png` with the specific ERC20 token icon. ```bash -go generate +make build-frontend ``` -1. Build Go project +3. Build Go project ```bash -go build -o lsk-faucet +make build-backend ``` ## Usage @@ -48,13 +49,13 @@ go build -o lsk-faucet **Use private key to fund users** ```bash -./lsk-faucet -httpport 8080 -wallet.provider http://localhost:8545 -wallet.privkey privkey +make run FLAGS="-httpport 8080 -wallet.provider http://localhost:8545 -wallet.privkey privkey" ``` **Use keystore to fund users** ```bash -./lsk-faucet -httpport 8080 -wallet.provider http://localhost:8545 -wallet.keyjson keystore -wallet.keypass password.txt +make run FLAGS="-httpport 8080 -wallet.provider http://localhost:8545 -wallet.keyjson keystore -wallet.keypass password.txt" ``` ### Configuration @@ -81,7 +82,7 @@ echo "your keystore password" > `pwd`/password.txt Then run the faucet application without the wallet command-line flags: ```bash -./lsk-faucet -httpport 8080 +make run FLAGS="-httpport 8080" ``` **Optional Flags** @@ -104,15 +105,14 @@ The following are the available command-line flags(excluding above wallet flags) #### Build docker image Run the following command to build docker image: ```bash -docker build -t liskhq/lsk-faucet . +make build ``` - #### Run faucet Run the following command to start the application: ```bash -docker run -d -p 8080:8080 -e WEB3_PROVIDER= -e PRIVATE_KEY= liskhq/lsk-faucet +make docker-start WEB3_PROVIDER= PRIVATE_KEY= ``` **NOTE**: Please replace `` and `` with appropriate values. @@ -120,7 +120,7 @@ docker run -d -p 8080:8080 -e WEB3_PROVIDER= -e PRIVATE_KEY= -e KEYSTORE= -v `pwd`/keystore:/app/keystore -v `pwd`/password.txt:/app/password.txt liskhq/lsk-faucet +make docker-start WEB3_PROVIDER= KEYSTORE= ``` **NOTE**: Please replace `` and `` with appropriate values.