github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/Makefile (about)

     1  DOCKER_COMPOSE_FILE=./docker-compose.yaml
     2  WS_BACKEND_IMAGE = $(USER)/w3bstream:main
     3  WS_WORKING_DIR=$(shell pwd)/working_dir
     4  
     5  .DEFAULT_GOAL := all
     6  
     7  ## cmd build entries
     8  
     9  ## update and download go module dependency
    10  .PHONY: update
    11  update:
    12  	@go mod tidy
    13  	@go mod download
    14  
    15  ## build all targets to ./build/
    16  .PHONY: targets
    17  targets: update
    18  	@cd cmd && for target in * ; \
    19  	do \
    20  		echo "\033[32mbuilding $$target ... \033[0m" ; \
    21  		if [ -d $$target ] && [ -e $$target/Makefile ]; then \
    22  			cd $$target; \
    23  			make target --no-print-directory; \
    24  			cd ..; \
    25  		else \
    26  			echo "\033[31mno entry\033[0m" ; \
    27  		fi; \
    28  		echo "\033[32mdone!\033[0m\n"; \
    29  	done
    30  
    31  ## build all docker images
    32  .PHONY: images
    33  images:
    34  	@cd cmd && for target in * ; \
    35  	do \
    36  		echo "\033[32mbuilding $$target docker image ... \033[0m" ; \
    37  		if [ -d $$target ] && [ -e $$target/Dockerfile ]; then \
    38  			cd $$target; \
    39  			make image --no-print-directory || true; \
    40  			cd ..; \
    41  		else \
    42  			echo "\033[31mno entry\033[0m" ; \
    43  		fi; \
    44  		echo "\033[32mdone!\033[0m\n"; \
    45  	done
    46  
    47  .PHONY: all
    48  all: update targets test images
    49  
    50  .PHONY: clean
    51  clean:
    52  	@cd cmd && for target in * ; \
    53  	do \
    54  		echo "\033[32mcleaning $$target ... \033[0m" ; \
    55  		if [ -d $$target ] && [ -e $$target/Makefile ]; then \
    56  			cd $$target; \
    57  			make clean --no-print-directory || true; \
    58  			cd ..; \
    59  		else \
    60  			echo "\033[31mno entry\033[0m" ; \
    61  		fi; \
    62  		echo "\033[32mdone!\033[0m\n" ; \
    63  	done
    64  
    65  
    66  # run server in docker containers
    67  .PHONY: run_docker
    68  run_docker:
    69  	@WS_WORKING_DIR=${WS_WORKING_DIR} WS_BACKEND_IMAGE=${WS_BACKEND_IMAGE} WS_STUDIO_IMAGE=${WS_STUDIO_IMAGE} docker-compose -p w3bstream -f ${DOCKER_COMPOSE_FILE} up -d
    70  
    71  # stop server running in docker containers
    72  .PHONY: stop_docker
    73  stop_docker:
    74  	@docker-compose -f ${DOCKER_COMPOSE_FILE} stop
    75  
    76  # stop docker and delete docker resources
    77  .PHONY: drop_docker
    78  drop_docker:
    79  	@docker-compose -f ${DOCKER_COMPOSE_FILE} down
    80  
    81  # restart server in docker containers
    82  .PHONY: restart_docker
    83  restart_docker: drop_docker run_docker
    84  
    85  ## developing stage entries
    86  
    87  ## toolkit for code generation
    88  .PHONY: toolkit
    89  toolkit:
    90  	@go install github.com/machinefi/w3bstream/pkg/depends/gen/cmd/...@toolkit-patch-0.0.3
    91  	@echo installed `which toolkit`
    92  
    93  ## gomock for generating mock code
    94  .PHONY: gomock
    95  gomock:
    96  	@go install github.com/golang/mock/mockgen@v1.6.0
    97  
    98  .PHONY: generate
    99  generate: toolkit gomock
   100  	@cd pkg/models              && go generate ./...
   101  	@cd pkg/enums               && go generate ./...
   102  	@cd pkg/errors              && go generate ./...
   103  	@cd pkg/depends/util/strfmt && go generate ./...
   104  	@cd pkg/test                && go generate ./...
   105  	@cd cmd/srv-applet-mgr      && go generate ./...
   106  
   107  .PHONY: precommit
   108  precommit: toolkit generate targets test
   109  	@toolkit fmt
   110  	@git add -u
   111  
   112  ## to migrate database models, if model defines changed, make this entry
   113  .PHONY: migrate
   114  migrate: toolkit
   115  	go run cmd/srv-applet-mgr/main.go migrate
   116  
   117  .PHONY: test
   118  test: test_depends
   119  	@go test -gcflags "all=-N -l" -cover -coverprofile=coverage.out ./...
   120  	@docker stop mqtt_test postgres_test redis_test || true && docker container rm mqtt_test postgres_test redis_test || true
   121  
   122  bench: test_depends
   123  	@cd ./cmd/srv-applet-mgr/tests/integrations/ && go test event_benchmark_test.go -bench=.
   124  	@docker stop mqtt_test postgres_test redis_test || true && docker container rm mqtt_test postgres_test redis_test || true
   125  
   126  .PHONY: test_depends
   127  test_depends: cleanup_test_depends postgres_test mqtt_test redis_test
   128  
   129  .PHONY: cleanup_test_depends
   130  cleanup_test_depends:
   131  	@docker stop mqtt_test postgres_test redis_test || true && docker container rm mqtt_test postgres_test redis_test || true
   132  
   133  .PHONY: postgres_test
   134  postgres_test:
   135  	docker run --name postgres_test -e POSTGRES_PASSWORD=test_passwd -e POSTGRES_USER=root -p 15432:5432 -d postgres:14-alpine
   136  
   137  .PHONY: mqtt_test
   138  mqtt_test:
   139  	docker run --name mqtt_test -p 11883:1883 -d eclipse-mosquitto:1.6.15
   140  
   141  .PHONY: redis_test
   142  redis_test:
   143  	docker run --name redis_test -p 16379:6379 -d redis:6.2