github.com/pluralsh/plural-cli@v0.9.5/Makefile (about)

     1  ROOT_DIRECTORY := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
     2  
     3  include $(ROOT_DIRECTORY)/hack/include/help.mk
     4  include $(ROOT_DIRECTORY)/hack/include/tools.mk
     5  include $(ROOT_DIRECTORY)/hack/include/build.mk
     6  
     7  GCP_PROJECT ?= pluralsh
     8  APP_NAME ?= plural-cli
     9  APP_VSN ?= $(shell git describe --tags --always --dirty)
    10  APP_DATE ?= $(shell date -u +"%Y-%m-%dT%H:%M:%S%z")
    11  BUILD ?= $(shell git rev-parse --short HEAD)
    12  DKR_HOST ?= dkr.plural.sh
    13  GOOS ?= darwin
    14  GOARCH ?= arm64
    15  GOLANG_CROSS_VERSION  ?= v1.22.0
    16  PACKAGE ?= github.com/pluralsh/plural
    17  BASE_LDFLAGS ?= -s -w
    18  LDFLAGS ?= $(BASE_LDFLAGS) $\
    19  	-X "$(PACKAGE)/cmd/plural.Version=$(APP_VSN)" $\
    20  	-X "$(PACKAGE)/cmd/plural.Commit=$(BUILD)" $\
    21  	-X "$(PACKAGE)/cmd/plural.Date=$(APP_DATE)" $\
    22  	-X "$(PACKAGE)/pkg/scm.GitlabClientSecret=${GITLAB_CLIENT_SECRET}" $\
    23  	-X "$(PACKAGE)/pkg/scm.BitbucketClientSecret=${BITBUCKET_CLIENT_SECRET}"
    24  WAILS_TAGS ?= desktop,production,ui,debug
    25  WAILS_BINDINGS_TAGS ?= bindings,generate
    26  WAILS_BINDINGS_BINARY_NAME ?= wailsbindings
    27  TAGS ?= $(WAILS_TAGS)
    28  OUTFILE ?= plural.o
    29  GOBIN ?= go env GOBIN
    30  
    31  # Targets to run before other targets
    32  # install-tools - Install binaries required to run targets
    33  PRE := install-tools
    34  
    35  .PHONY: git-push
    36  git-push:
    37  	git pull --rebase
    38  	git push
    39  
    40  .PHONY: install
    41  install:
    42  	go build -ldflags '$(LDFLAGS)' -o $(GOBIN)/plural .
    43  
    44  .PHONY: build-cli
    45  build-cli: ## Build a CLI binary for the host architecture without embedded UI
    46  	go build -ldflags='$(LDFLAGS)' -o $(OUTFILE) .
    47  
    48  .PHONY: build-cli-ui
    49  build-cli-ui: $(PRE) generate-bindings ## Build a CLI binary for the host architecture with embedded UI
    50  	CGO_LDFLAGS=$(CGO_LDFLAGS) go build -tags $(WAILS_TAGS) -ldflags='$(LDFLAGS)' -o $(OUTFILE) .
    51  
    52  .PHONY: build-web
    53  build-web: ## Build just the embedded UI
    54  	cd pkg/ui/web && yarn --immutable && yarn build
    55  
    56  .PHONY: run-web
    57  run-web: $(PRE) ## Run the UI for development
    58  	@CGO_LDFLAGS=$(CGO_LDFLAGS) wails dev -tags ui -browser -skipbindings
    59  
    60  # This is somewhat an equivalent of wails `GenerateBindings` method.
    61  # Ref: https://github.com/wailsapp/wails/blob/master/v2/pkg/commands/bindings/bindings.go#L28
    62  .PHONY: generate-bindings
    63  generate-bindings: build-web ## Generate backend bindings for the embedded UI
    64  	@echo Building bindings binary
    65  	@CGO_LDFLAGS=$(CGO_LDFLAGS) go build -tags $(WAILS_BINDINGS_TAGS) -ldflags='$(LDFLAGS)' -o $(WAILS_BINDINGS_BINARY_NAME) .
    66  	@echo Generating bindings
    67  	@./$(WAILS_BINDINGS_BINARY_NAME) > /dev/null 2>&1
    68  	@echo Cleaning up
    69  	@rm $(WAILS_BINDINGS_BINARY_NAME)
    70  
    71  .PHONY: release
    72  release:
    73  	GOOS=$(GOOS) GOARCH=$(GOARCH) go build -ldflags='$(LDFLAGS)' -o $(OUTFILE) .
    74  
    75  .PHONY: setup
    76  setup: ## sets up your local env (for mac only)
    77  	brew install golangci-lint
    78  
    79  .PHONY: plural
    80  plural: ## uploads to plural
    81  	plural apply -f plural/Pluralfile
    82  
    83  .PHONY: build
    84  build: ## Build the Docker image
    85  	docker build --build-arg APP_NAME=$(APP_NAME) \
    86  		--build-arg APP_VSN=$(APP_VSN) \
    87  		--build-arg APP_DATE=$(APP_DATE) \
    88  		--build-arg APP_COMMIT=$(BUILD) \
    89  		-t $(APP_NAME):$(APP_VSN) \
    90  		-t $(APP_NAME):latest \
    91  		-t gcr.io/$(GCP_PROJECT)/$(APP_NAME):$(APP_VSN) \
    92  		-t $(DKR_HOST)/plural/$(APP_NAME):$(APP_VSN) .
    93  
    94  .PHONY: build-cloud
    95  build-cloud: ## build the cloud docker image
    96  	docker build --build-arg APP_NAME=$(APP_NAME) \
    97  		--build-arg APP_VSN=$(APP_VSN) \
    98  		--build-arg APP_DATE=$(APP_DATE) \
    99  		--build-arg APP_COMMIT=$(BUILD) \
   100  		-t $(APP_NAME)-cloud:$(APP_VSN) \
   101  		-t $(APP_NAME)-cloud:latest \
   102  		-t gcr.io/$(GCP_PROJECT)/$(APP_NAME)-cloud:$(APP_VSN) \
   103  		-t $(DKR_HOST)/plural/$(APP_NAME)-cloud:$(APP_VSN) -f dockerfiles/Dockerfile.cloud  .
   104  
   105  .PHONY: build-dind
   106  build-dind: ## build the dind docker image
   107  	docker build --build-arg APP_NAME=$(APP_NAME) \
   108  		--build-arg APP_VSN=$(APP_VSN) \
   109  		--build-arg APP_DATE=$(APP_DATE) \
   110  		--build-arg APP_COMMIT=$(BUILD) \
   111  		-t $(APP_NAME)-cloud:$(APP_VSN) \
   112  		-t $(APP_NAME)-cloud:latest \
   113  		-t gcr.io/$(GCP_PROJECT)/$(APP_NAME)-cloud:$(APP_VSN) \
   114  		-t $(DKR_HOST)/plural/$(APP_NAME)-dind:$(APP_VSN) -f dockerfiles/Dockerfile.dind  .
   115  
   116  .PHONY: push
   117  push: ## push to gcr
   118  	docker push gcr.io/$(GCP_PROJECT)/$(APP_NAME):$(APP_VSN)
   119  	docker push $(DKR_HOST)/plural/${APP_NAME}:$(APP_VSN)
   120  
   121  .PHONY: push-cloud
   122  push-cloud: ## push to gcr
   123  	docker push gcr.io/$(GCP_PROJECT)/$(APP_NAME):$(APP_VSN)-cloud
   124  	docker push $(DKR_HOST)/plural/${APP_NAME}:$(APP_VSN)-cloud
   125  
   126  .PHONY: generate
   127  generate:
   128  	go generate ./...
   129  
   130  .PHONY: bake-ami
   131  bake-ami:
   132  	cd packer && packer build -var "cli_version=$(APP_VSN)" .
   133  	@echo "baked ami for all regions"
   134  
   135  .PHONY: up
   136  up: # spin up local server
   137  	docker-compose up
   138  
   139  .PHONY: pull
   140  pull: # pulls new server image
   141  	docker-compose pull
   142  
   143  .PHONY: serve
   144  serve: build-cloud # build cloud version of plural-cli and start plural serve in docker
   145  	docker kill plural-cli || true
   146  	docker run --rm --name plural-cli -p 8080:8080 -d plural-cli:latest-cloud
   147  
   148  .PHONY: release-vsn
   149  release-vsn: # tags and pushes a new release
   150  	@read -p "Version: " tag; \
   151  	git checkout main; \
   152  	git pull --rebase; \
   153  	git tag -a $$tag -m "new release"; \
   154  	git push origin $$tag
   155  
   156  .PHONY: setup-tests
   157  setup-tests:
   158  	go install gotest.tools/gotestsum@latest
   159  
   160  .PHONY: test
   161  test: setup-tests
   162  	gotestsum --format testname -- -v -race ./pkg/... ./cmd/...
   163  
   164  .PHONY: format
   165  format: # formats all go code to prep for linting
   166  	golangci-lint run --fix
   167  
   168  .PHONY: genmock
   169  genmock: # generates mocks before running tests
   170  	hack/gen-client-mocks.sh
   171  
   172  .PHONY: lint
   173  lint:
   174  	docker run --rm -v $(PWD):/app -w /app golangci/golangci-lint:v1.56.2 golangci-lint run
   175  
   176  .PHONY: delete-tag
   177  delete-tag:
   178  	@read -p "Version: " tag; \
   179  	git tag -d $$tag; \
   180  	git push origin :$$tag