Files
mam-contract/Makefile
Jeffrey Duroyon 33db360b03 init
2023-10-18 19:52:34 +02:00

87 lines
2.7 KiB
Makefile

# Set an output prefix, which is the local directory if not specified
PREFIX?=$(shell pwd)
.DEFAULT_GOAL := build
DOCKER_IMAGE_NAME := MamContract
# Setup name variables for the package/tool
NAME := MamContract
BIN_NAME := MamContract
PKG := github.com/kratisto/mam-contract
# GO env vars
ifeq ($(GOPATH),)
GOPATH:=~/go
endif
GO=$(firstword $(subst :, ,$(GOPATH)))
.PHONY: ensure-vendor
ensure-vendor: ## Get all vendor dependencies
@echo "+ $@"
dep ensure
.PHONY: update-vendor
update-vendor: ## Get all vendor dependencies
@echo "+ $@"
dep ensure -update
.PHONY: clean
clean: local-clean ## Clean your generated files
@echo "+ $@"
docker image rm workScheduler:snapshot || true
.PHONY: local-build
local-build: local-clean local-format ## Build locally the binary
@echo "+ $@"
go build -o $(GO)/bin/$(BIN_NAME) .
.PHONY: local-clean
local-clean: ## Cleanup locally any build binaries or packages
@echo "+ $@"
@$(RM) $(BIN_NAME)
.PHONY: local-format
local-format: ## format locally all files
@echo "+ $@"
gofmt -s -l -w .
.PHONY: build
build: sources-image ## Build the docker image with application binary
@echo "+ $@"
docker build --no-cache \
-f containers/Dockerfile \
--build-arg SOURCES_IMAGE=workScheduler-sources:snapshot \
-t workScheduler:snapshot .
GIT_CREDENTIALS?=$(shell cat ~/.git-credentials 2> /dev/null)
.PHONY: sources-image
sources-image: ## Generate a Docker image with only the sources
@echo "+ $@"
docker build -t workScheduler-sources:snapshot -f containers/Dockerfile.sources .
.PHONY: local-run-dependencies
local-run-dependencies: ## Run the dependencies of the server (launch the containers/docker-compose.local.yml)
@echo "+ $@"
@docker-compose -p $(DOCKER_IMAGE_NAME)-uuid -f containers/docker-compose.local.yml down || true;
@docker-compose -p $(DOCKER_IMAGE_NAME)-uuid -f containers/docker-compose.local.yml pull;
@docker-compose -p $(DOCKER_IMAGE_NAME)-uuid -f containers/docker-compose.local.yml up -d --build
.PHONY: local-run-golang
local-run-golang: ## Build the server and run it
@echo "+ $@"
BUILD_GOLANG_CMD=local-build \
LAUNCH_GOLANG_CMD="$(GO)/bin/$(BIN_NAME)" \
$(MAKE) local-launch-golang
.PHONY: local-launch-golang
local-launch-golang: ## Build the server and run it
@echo "+ $@"
PID=`ps -ax | egrep "\b$(BIN_NAME)"| cut -d " " -f 1`; \
kill $$PID || true
$(MAKE) $(BUILD_GOLANG_CMD)
DB_PORT=`docker-compose -p $(DOCKER_IMAGE_NAME)-uuid -f containers/docker-compose.local.yml port database 5432 | cut -f2 -d':'`; \
$(LAUNCH_GOLANG_CMD) serve --loglevel debug --logformat text --postgreshost localhost:$$DB_PORT
.PHONY: local-run
local-run: local-run-dependencies local-run-golang ## Run the server with its dependencies