diff --git a/Makefile b/Makefile index da2308651..016715491 100644 --- a/Makefile +++ b/Makefile @@ -4,73 +4,89 @@ PLATFORM=$(shell go env GOOS) ARCH=$(shell go env GOARCH) -TAG=latest - # build target, can be one of "production", "testing", "development" ENV=development WEBPACK_CONFIG=webpack/webpack.$(ENV).js +TAG=latest +SWAG=go run github.com/swaggo/swag/cmd/swag@v1.8.11 +GOTESTSUM=go run gotest.tools/gotestsum@latest + +# Don't change anything below this line unless you know what you're doing .DEFAULT_GOAL := help -.PHONY: help build-storybook build-client devops download-binaries tidy clean client-deps ##@ Building - +.PHONY: init-dist build-storybook build build-client build-server build-image devops init-dist: - mkdir -p dist + @mkdir -p dist -build-storybook: - yarn storybook:build +build: build-server build-client ## Build the server and client -build-client: init-dist ## Build the client - @export NODE_ENV=$(ENV) && yarn build --config $(WEBPACK_CONFIG) +build-client: init-dist client-deps ## Build the client + export NODE_ENV=$(ENV) && yarn build --config $(WEBPACK_CONFIG) build-server: init-dist ## Build the server binary - @./build/build_binary.sh "$(PLATFORM)" "$(ARCH)" - -build: build-server build-client ## Build the server and client + ./build/build_binary.sh "$(PLATFORM)" "$(ARCH)" -build-image: build ## Build the Portainer image - docker build -t portainerci/portainer:$(TAG) -f build/linux/Dockerfile . +build-image: build ## Build the Portainer image locally + docker buildx build --load -t portainerci/portainer:$(TAG) -f build/linux/Dockerfile . -devops: clean init-dist download-binaries build-client ## Build the server binary for CI +devops: clean init-dist server-deps build-client ## Build the server binary for CI echo "Building the devops binary..." @./build/build_binary_azuredevops.sh "$(PLATFORM)" "$(ARCH)" -##@ Dependencies +build-storybook: + yarn storybook:build -download-binaries: ## Download dependant binaries +##@ Build dependencies +.PHONY: deps server-deps client-deps tidy +deps-all: server-deps client-deps ## Download all client and server build dependancies + +server-deps: ## Download dependant server binaries @./build/download_binaries.sh $(PLATFORM) $(ARCH) -tidy: ## Tidy up the go.mod file - cd api && go mod tidy - client-deps: ## Install client dependencies yarn -##@ Cleanup +tidy: ## Tidy up the go.mod file + cd api && go mod tidy + +##@ Cleanup +.PHONY: clean clean: ## Remove all build and download artifacts @echo "Clearing the dist directory..." @rm -rf dist/* + ##@ Testing +.PHONY: test test-client test-server +test: test-server test-client ## Run all tests test-client: ## Run client tests yarn test test-server: ## Run server tests - cd api && go test -v ./... - -test: test-client test-server ## Run all tests + cd api && $(GOTESTSUM) --format pkgname-and-test-fails --format-hide-empty-pkg --hide-summary skipped -- -cover ./... ##@ Dev +.PHONY: dev dev-client dev-server +dev: ## Run both the client and server in development mode + make dev-server + make dev-client + +dev-client: ## Run the client in development mode + yarn dev -dev-server: build-image ## Run the server in development mode +dev-server: ## Run the server in development mode @./dev/run_container.sh ##@ Format +.PHONY: format format-client format-server + +format: format-client format-server ## Format all code format-client: ## Format client code yarn format @@ -78,9 +94,9 @@ format-client: ## Format client code format-server: ## Format server code cd api && go fmt ./... -format: format-client format-server ## Format all code - ##@ Lint +.PHONY: lint lint-client lint-server +lint: lint-client lint-server ## Lint all code lint-client: ## Lint client code yarn lint @@ -88,20 +104,17 @@ lint-client: ## Lint client code lint-server: ## Lint server code cd api && go vet ./... -lint: lint-client lint-server ## Lint all code ##@ Extension - +.PHONY: dev-extension dev-extension: build-server build-client ## Run the extension in development mode make local -f build/docker-extension/Makefile -##@ Docs - -docs-deps: ## Install docs dependencies - go install github.com/swaggo/swag/cmd/swag@v1.8.11 -docs-build: docs-deps ## Build docs - cd api && swag init -g ./http/handler/handler.go --parseDependency --parseInternal --parseDepth 2 --markdownFiles ./ +##@ Docs +.PHONY: docs-build docs-validate docs-clean docs-validate-clean +docs-build: ## Build docs + cd api && $(SWAG) init -g ./http/handler/handler.go --parseDependency --parseInternal --parseDepth 2 --markdownFiles ./ docs-validate: docs-build ## Validate docs yarn swagger2openapi --warnOnly api/docs/swagger.yaml -o api/docs/openapi.yaml @@ -112,7 +125,8 @@ docs-clean: ## Clean docs docs-validate-clean: docs-validate docs-clean ## Validate and clean docs -##@ Helpers +##@ Helpers +.PHONY: help help: ## Display this help - @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) + @awk 'BEGIN {FS = ":.*##"; printf "Usage:\n make \033[36m\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) diff --git a/build/build_binary.ps1 b/build/build_binary.ps1 deleted file mode 100755 index 5dcb8175f..000000000 --- a/build/build_binary.ps1 +++ /dev/null @@ -1,17 +0,0 @@ - -$ErrorActionPreference = "Stop"; - -$binary = "portainer.exe" -$project_path = $((Get-Location).Path) - -New-Item -Name dist -Path "$project_path" -ItemType Directory | Out-Null -Set-Location -Path "$project_path\api\cmd\portainer" - -# copy templates -Copy-Item -Path "./mustache-templates" -Destination "./dist" -Recurse - - -C:\go\bin\go.exe get -t -d -v ./... -C:\go\bin\go.exe build -v - -Move-Item -Path "$($binary)" -Destination "..\..\..\dist" diff --git a/build/build_binary.sh b/build/build_binary.sh index c06343133..dc17396f9 100755 --- a/build/build_binary.sh +++ b/build/build_binary.sh @@ -1,11 +1,6 @@ #!/usr/bin/env bash set -euo pipefail -DEBUG=${DEBUG:-""} -if [ -n "$DEBUG" ]; then - set -x -fi - mkdir -p dist # populate tool versions @@ -24,16 +19,23 @@ cd api || exit 1 # the go get adds 8 seconds go get -t -d -v ./... + +ldflags="-s -X 'github.com/portainer/liblicense.LicenseServerBaseURL=https://api.portainer.io' \ +-X 'github.com/portainer/portainer-ee/api/build.BuildNumber=${BUILDNUMBER}' \ +-X 'github.com/portainer/portainer-ee/api/build.ImageTag=${CONTAINER_IMAGE_TAG}' \ +-X 'github.com/portainer/portainer-ee/api/build.NodejsVersion=${NODE_VERSION}' \ +-X 'github.com/portainer/portainer-ee/api/build.YarnVersion=${YARN_VERSION}' \ +-X 'github.com/portainer/portainer-ee/api/build.WebpackVersion=${WEBPACK_VERSION}' \ +-X 'github.com/portainer/portainer-ee/api/build.GoVersion=${GO_VERSION}'" + +BINARY_VERSION_FILE="../binary-version.json" + +echo "$ldflags" + # the build takes 2 seconds -GOOS=$1 GOARCH=$2 CGO_ENABLED=0 go build \ --trimpath \ ---installsuffix cgo \ ---ldflags "-s \ - --X 'github.com/portainer/portainer/api/build.BuildNumber=${BUILDNUMBER}' \ - --X 'github.com/portainer/portainer/api/build.ImageTag=${CONTAINER_IMAGE_TAG}' \ - --X 'github.com/portainer/portainer/api/build.NodejsVersion=${NODE_VERSION}' \ - --X 'github.com/portainer/portainer/api/build.YarnVersion=${YARN_VERSION}' \ - --X 'github.com/portainer/portainer/api/build.WebpackVersion=${WEBPACK_VERSION}' \ ---X 'github.com/portainer/portainer/api/build.GoVersion=${GO_VERSION}'" \ --o "../dist/portainer" \ -./cmd/portainer/ +GOOS=${1:-$(go env GOOS)} GOARCH=${2:-$(go env GOARCH)} CGO_ENABLED=0 go build \ + -trimpath \ + --installsuffix cgo \ + --ldflags "$ldflags" \ + -o "../dist/portainer" \ + ./cmd/portainer/