github.com/ddev/ddev@v1.23.2-0.20240519125000-d824ffe36ff3/Makefile (about)

     1  # Makefile for a standard golang repo with associated container
     2  
     3  # Circleci doesn't seem to provide a decent way to add to path, just adding here, for case where
     4  # linux build and linuxbrew is installed.
     5  export PATH := $(EXTRA_PATH):$(PATH)
     6  
     7  BUILD_BASE_DIR ?= $(PWD)
     8  
     9  GOTMP=.gotmp
    10  SHELL = /bin/bash
    11  PWD = $(shell pwd)
    12  GOFILES = $(shell find $(SRC_DIRS) -type f)
    13  GORACE = "halt_on_error=1"
    14  CGO_ENABLED = 0
    15  .PHONY: darwin_amd64 darwin_arm64 darwin_amd64_notarized darwin_arm64_notarized darwin_arm64_signed darwin_amd64_signed linux_amd64 linux_arm64 linux_arm windows_amd64 windows_arm64 setup
    16  
    17  # Expands SRC_DIRS into the common golang ./dir/... format for "all below"
    18  SRC_AND_UNDER = $(patsubst %,./%/...,$(SRC_DIRS))
    19  
    20  GOLANGCI_LINT_ARGS ?= --out-format=line-number --disable-all --enable=gofmt --enable=govet --enable=revive --enable=errcheck --enable=staticcheck --enable=ineffassign
    21  
    22  WINDOWS_GSUDO_VERSION=v0.7.3
    23  WINNFSD_VERSION=2.4.0
    24  NSSM_VERSION=2.24-101-g897c7ad
    25  
    26  TESTTMP=/tmp/testresults
    27  
    28  # This repo's root import path (under GOPATH).
    29  PKG := github.com/ddev/ddev
    30  
    31  # Top-level directories to build
    32  SRC_DIRS := cmd pkg
    33  
    34  # Version variables to replace in build
    35  VERSION_VARIABLES ?= DdevVersion AmplitudeAPIKey
    36  
    37  # These variables will be used as the default unless overridden by the make
    38  DdevVersion ?= $(VERSION)
    39  # WebTag ?= $(VERSION)  # WebTag is normally specified in version_constants.go, sometimes overridden (night-build.mak)
    40  # DBTag ?=  $(VERSION)  # DBTag is normally specified in version_constants.go, sometimes overridden (night-build.mak)
    41  # RouterTag ?= $(VERSION) #RouterTag is normally specified in version_constants.go, sometimes overridden (night-build.mak)
    42  # DBATag ?= $(VERSION) #DBATag is normally specified in version_constants.go, sometimes overridden (night-build.mak)
    43  
    44  # VERSION can be set by
    45    # Default: git tag
    46    # make command line: make VERSION=0.9.0
    47  # It can also be explicitly set in the Makefile as commented out below.
    48  
    49  # This version-strategy uses git tags to set the version string
    50  # VERSION can be overridden on make commandline: make VERSION=0.9.1 push
    51  VERSION := $(shell git describe --tags --always --dirty)
    52  # Some things insist on having the version without the leading 'v', so provide a
    53  # $(NO_V_VERSION) without it.
    54  # no_v_version removes the front v, for Chocolatey mostly
    55  NO_V_VERSION=$(shell echo $(VERSION) | awk -F"-" '{ OFS="-"; sub(/^./, "", $$1); printf $$0; }')
    56  GITHUB_ORG := ddev
    57  
    58  BUILD_OS = $(shell go env GOHOSTOS)
    59  BUILD_ARCH = $(shell go env GOHOSTARCH)
    60  VERSION_LDFLAGS=$(foreach v,$(VERSION_VARIABLES),-X '$(PKG)/pkg/versionconstants.$(v)=$($(v))')
    61  LDFLAGS=-extldflags -static $(VERSION_LDFLAGS)
    62  DEFAULT_BUILD=$(shell go env GOHOSTOS)_$(shell go env GOHOSTARCH)
    63  
    64  build: $(DEFAULT_BUILD)
    65  
    66  
    67  # Provide shorthand targets
    68  linux_amd64: $(GOTMP)/bin/linux_amd64/ddev
    69  linux_arm64: $(GOTMP)/bin/linux_arm64/ddev
    70  linux_arm: $(GOTMP)/bin/linux_arm/ddev
    71  darwin_amd64: $(GOTMP)/bin/darwin_amd64/ddev
    72  darwin_arm64: $(GOTMP)/bin/darwin_arm64/ddev
    73  windows_amd64: windows_install
    74  windows_arm64: $(GOTMP)/bin/windows_arm64/ddev.exe
    75  completions: $(GOTMP)/bin/completions.tar.gz
    76  
    77  TARGETS=$(GOTMP)/bin/linux_amd64/ddev $(GOTMP)/bin/linux_arm64/ddev $(GOTMP)/bin/linux_arm/ddev $(GOTMP)/bin/darwin_amd64/ddev $(GOTMP)/bin/darwin_arm64/ddev $(GOTMP)/bin/windows_amd64/ddev.exe
    78  $(TARGETS): mkcert $(GOFILES)
    79  	@echo "building $@ from $(SRC_AND_UNDER) GORACE=$(GORACE) CGO_ENABLED=$(CGO_ENABLED)";
    80  	@#echo "LDFLAGS=$(LDFLAGS)";
    81  	@rm -f $@
    82  	@export TARGET=$(word 3, $(subst /, ,$@)) && \
    83  	export CGO_ENABLED=$(CGO_ENABLED) GOOS="$${TARGET%_*}" GOARCH="$${TARGET#*_}" GOPATH="$(PWD)/$(GOTMP)" GOCACHE="$(PWD)/$(GOTMP)/.cache" && \
    84  	mkdir -p $(GOTMP)/{.cache,pkg,src,bin/$$TARGET} && \
    85  	chmod 777 $(GOTMP)/{.cache,pkg,src,bin/$$TARGET} && \
    86  	go build -o $(GOTMP)/bin/$$TARGET -installsuffix static $(BUILDARGS) -ldflags " $(LDFLAGS) " $(SRC_AND_UNDER)
    87  	$( shell if [ -d $(GOTMP) ]; then chmod -R u+w $(GOTMP); fi )
    88  	@echo $(VERSION) >VERSION.txt
    89  
    90  $(GOTMP)/bin/completions.tar.gz: build
    91  	$(GOTMP)/bin/$(BUILD_OS)_$(BUILD_ARCH)/ddev_gen_autocomplete
    92  	tar -C $(GOTMP)/bin/completions -czf $(GOTMP)/bin/completions.tar.gz .
    93  
    94  mkcert: $(GOTMP)/bin/darwin_arm64/mkcert $(GOTMP)/bin/darwin_amd64/mkcert $(GOTMP)/bin/linux_arm64/mkcert $(GOTMP)/bin/linux_amd64/mkcert
    95  
    96  # Download mkcert to it can be added to tarball installations
    97  $(GOTMP)/bin/darwin_arm64/mkcert $(GOTMP)/bin/darwin_amd64/mkcert $(GOTMP)/bin/linux_arm64/mkcert $(GOTMP)/bin/linux_amd64/mkcert:
    98  	@export TARGET=$(word 3, $(subst /, ,$@)) && \
    99  	export GOOS="$${TARGET%_*}" GOARCH="$${TARGET#*_}" && \
   100  	mkdir -p $(GOTMP)/bin/$${GOOS}_$${GOARCH} && \
   101  	curl --fail -JL -s -o $(GOTMP)/bin/$${GOOS}_$${GOARCH}/mkcert "https://dl.filippo.io/mkcert/latest?for=$${GOOS}/$${GOARCH}" && chmod +x $(GOTMP)/bin/$${GOOS}_$${GOARCH}/mkcert
   102  
   103  TEST_TIMEOUT=4h
   104  BUILD_ARCH = $(shell go env GOARCH)
   105  
   106  DDEVNAME=ddev
   107  SHASUM=shasum -a 256
   108  ifeq ($(BUILD_OS),windows)
   109  	DDEVNAME=ddev.exe
   110  	SHASUM=sha256sum
   111  	TEST_TIMEOUT=6h
   112  endif
   113  
   114  DDEV_PATH=$(PWD)/$(GOTMP)/bin/$(BUILD_OS)_$(BUILD_ARCH)
   115  DDEV_BINARY_FULLPATH=$(DDEV_PATH)/$(DDEVNAME)
   116  
   117  # Override test section with tests specific to ddev
   118  test: testpkg testcmd
   119  
   120  testcmd: $(DEFAULT_BUILD) setup
   121  	@echo LDFLAGS=$(LDFLAGS)
   122  	@echo DDEV_BINARY_FULLPATH=$(DDEV_BINARY_FULLPATH)
   123  	export PATH="$(DDEV_PATH):$$PATH" DDEV_NO_INSTRUMENTATION=true CGO_ENABLED=$(CGO_ENABLED) DDEV_BINARY_FULLPATH=$(DDEV_BINARY_FULLPATH); go test $(USEMODVENDOR) -p 1 -timeout $(TEST_TIMEOUT) -v -installsuffix static -ldflags " $(LDFLAGS) " ./cmd/... $(TESTARGS)
   124  
   125  testpkg: testnotddevapp testddevapp
   126  
   127  testddevapp: $(DEFAULT_BUILD) setup
   128  	export PATH="$(DDEV_PATH):$$PATH" DDEV_NO_INSTRUMENTATION=true CGO_ENABLED=$(CGO_ENABLED) DDEV_BINARY_FULLPATH=$(DDEV_BINARY_FULLPATH); go test $(USEMODVENDOR) -p 1 -timeout $(TEST_TIMEOUT) -v -installsuffix static -ldflags " $(LDFLAGS) " ./pkg/ddevapp $(TESTARGS)
   129  
   130  testnotddevapp: $(DEFAULT_BUILD) setup
   131  	export PATH="$(DDEV_PATH):$$PATH" DDEV_NO_INSTRUMENTATION=true CGO_ENABLED=$(CGO_ENABLED) DDEV_BINARY_FULLPATH=$(DDEV_BINARY_FULLPATH); go test $(USEMODVENDOR) -p 1 -timeout $(TEST_TIMEOUT) -v -installsuffix static -ldflags " $(LDFLAGS) " $(shell find ./pkg -maxdepth 1 -type d ! -name ddevapp ! -name pkg) $(TESTARGS)
   132  
   133  testfullsitesetup: $(DEFAULT_BUILD) setup
   134  	export PATH="$(DDEV_PATH):$$PATH" DDEV_NO_INSTRUMENTATION=true CGO_ENABLED=$(CGO_ENABLED) DDEV_BINARY_FULLPATH=$(DDEV_BINARY_FULLPATH); go test $(USEMODVENDOR) -p 1 -timeout $(TEST_TIMEOUT) -v -installsuffix static -ldflags " $(LDFLAGS) " ./pkg/ddevapp -run TestDdevFullSiteSetup $(TESTARGS)
   135  
   136  setup:
   137  	@mkdir -p $(GOTMP)/{bin/linux_arm64,bin/linux_amd64,bin/darwin_arm64,bin/darwin_amd64,bin/windows_amd64,src,pkg/mod/cache,.cache}
   138  	@mkdir -p $(TESTTMP)
   139  
   140  # Required static analysis targets used in circleci - these cause fail if they don't work
   141  staticrequired: setup golangci-lint markdownlint mkdocs pyspelling
   142  
   143  # Best to install markdownlint-cli locally with "npm install -g markdownlint-cli"
   144  markdownlint:
   145  	@echo "markdownlint: "
   146  	@CMD="markdownlint *.md docs/content 2>&1"; \
   147  	set -eu -o pipefail; \
   148  	if command -v markdownlint >/dev/null 2>&1 ; then \
   149  		$$CMD; \
   150  	else \
   151  		echo "Skipping markdownlint as not installed"; \
   152  	fi
   153  
   154  # Best to install mkdocs locally with "sudo pip3 install -r docs/mkdocs-pip-requirements"
   155  mkdocs:
   156  	@echo "mkdocs: "
   157  	@CMD="mkdocs -q build -d /tmp/mkdocsbuild"; \
   158  	if command -v mkdocs >/dev/null 2>&1; then \
   159  		$$CMD ; \
   160  	else \
   161  		echo "Not running mkdocs because it's not installed"; \
   162  	fi
   163  
   164  # To see what the docs build will be, you can use `make mkdocs-serve`
   165  # It works best with mkdocs installed, `pip3 install mkdocs`,
   166  # see https://www.mkdocs.org/user-guide/installation/
   167  # But it will also work using docker.
   168  MKDOCS_TAG := 1.5.2
   169  ifeq ($(BUILD_ARCH),arm64)
   170      MKDOCS_TAG := arm64v8-$(MKDOCS_TAG)
   171  endif
   172  mkdocs-serve:
   173  	set -x; \
   174  	if command -v mkdocs >/dev/null ; then \
   175    		mkdocs serve; \
   176  	else \
   177  		docker run -it -p 8000:8000 -v "${PWD}:/docs" -e "ADD_MODULES=mkdocs-material mkdocs-redirects mkdocs-minify-plugin mdx_truly_sane_lists mkdocs-git-revision-date-localized-plugin" -e "LIVE_RELOAD_SUPPORT=true" -e "FAST_MODE=true" -e "DOCS_DIRECTORY=./docs" "polinux/mkdocs:$(MKDOCS_TAG)"; \
   178  	fi; \
   179  	set +x
   180  
   181  # Install markdown-link-check locally with "npm install -g markdown-link-check"
   182  markdown-link-check:
   183  	@echo "markdown-link-check: "
   184  	if command -v markdown-link-check >/dev/null 2>&1; then \
   185    		find docs *.md -name "*.md" -exec markdown-link-check -q -c markdown-link-check.json {} \; 2>&1  ;\
   186  	else \
   187  		echo "Not running markdown-link-check because it's not installed"; \
   188  	fi
   189  
   190  # Best to install pyspelling locally with "sudo -H pip3 install pyspelling pymdown-extensions". Also requries aspell, `sudo apt-get install aspell"
   191  pyspelling:
   192  	@echo "pyspelling: "
   193  	@CMD="pyspelling --config .spellcheck.yml"; \
   194  	set -eu -o pipefail; \
   195  	if command -v pyspelling >/dev/null 2>&1 ; then \
   196  		$$CMD; \
   197  	else \
   198  		echo "Not running pyspelling because it's not installed"; \
   199  	fi
   200  
   201  # Install textlint locally with `npm install -g textlint textlint-filter-rule-comments textlint-rule-no-todo textlint-rule-stop-words textlint-rule-terminology`
   202  textlint:
   203  	@echo "textlint: "
   204  	@CMD="textlint {README.md,version-history.md,docs/**}"; \
   205  	set -eu -o pipefail; \
   206  	if command -v textlint >/dev/null 2>&1 ; then \
   207  		$$CMD; \
   208  	else \
   209  		echo "textlint is not installed"; \
   210  	fi
   211  
   212  darwin_amd64_signed: $(GOTMP)/bin/darwin_amd64/ddev
   213  	@if [ -z "$(DDEV_MACOS_SIGNING_PASSWORD)" ] ; then echo "Skipping signing ddev for macOS, no DDEV_MACOS_SIGNING_PASSWORD provided"; else echo "Signing $< ..."; \
   214  		set -o errexit -o pipefail; \
   215  		curl -s https://raw.githubusercontent.com/ddev/signing_tools/master/macos_sign.sh | bash -s -  --signing-password="$(DDEV_MACOS_SIGNING_PASSWORD)" --cert-file=certfiles/ddev_developer_id_cert.p12 --cert-name="Developer ID Application: Localdev Foundation (9HQ298V2BW)" --target-binary="$<" ; \
   216  	fi
   217  darwin_arm64_signed: $(GOTMP)/bin/darwin_arm64/ddev
   218  	@if [ -z "$(DDEV_MACOS_SIGNING_PASSWORD)" ] ; then echo "Skipping signing ddev for macOS, no DDEV_MACOS_SIGNING_PASSWORD provided"; else echo "Signing $< ..."; \
   219  		set -o errexit -o pipefail; \
   220  		codesign --remove-signature "$(GOTMP)/bin/darwin_arm64/ddev" || true; \
   221  		curl -s https://raw.githubusercontent.com/ddev/signing_tools/master/macos_sign.sh | bash -s -  --signing-password="$(DDEV_MACOS_SIGNING_PASSWORD)" --cert-file=certfiles/ddev_developer_id_cert.p12 --cert-name="Developer ID Application: Localdev Foundation (9HQ298V2BW)" --target-binary="$<" ; \
   222  	fi
   223  
   224  darwin_amd64_notarized: darwin_amd64_signed
   225  	@if [ -z "$(DDEV_MACOS_APP_PASSWORD)" ]; then echo "Skipping notarizing ddev for macOS, no DDEV_MACOS_APP_PASSWORD provided"; else \
   226  		set -o errexit -o pipefail; \
   227  		echo "Notarizing $(GOTMP)/bin/darwin_amd64/ddev ..." ; \
   228  		curl -sSL -f https://raw.githubusercontent.com/ddev/signing_tools/master/macos_notarize.sh | bash -s -  --app-specific-password=$(DDEV_MACOS_APP_PASSWORD) --apple-id=notarizer@localdev.foundation --primary-bundle-id=com.ddev.ddev --target-binary="$(GOTMP)/bin/darwin_amd64/ddev" ; \
   229  	fi
   230  darwin_arm64_notarized: darwin_arm64_signed
   231  	@if [ -z "$(DDEV_MACOS_APP_PASSWORD)" ]; then echo "Skipping notarizing ddev for macOS, no DDEV_MACOS_APP_PASSWORD provided"; else \
   232  		set -o errexit -o pipefail; \
   233  		echo "Notarizing $(GOTMP)/bin/darwin_arm64/ddev ..." ; \
   234  		curl -sSL -f https://raw.githubusercontent.com/ddev/signing_tools/master/macos_notarize.sh | bash -s - --app-specific-password=$(DDEV_MACOS_APP_PASSWORD) --apple-id=notarizer@localdev.foundation --primary-bundle-id=com.ddev.ddev --target-binary="$(GOTMP)/bin/darwin_arm64/ddev" ; \
   235  	fi
   236  
   237  windows_install: $(GOTMP)/bin/windows_amd64/ddev_windows_installer.exe
   238  
   239  $(GOTMP)/bin/windows_amd64/ddev_windows_installer.exe: $(GOTMP)/bin/windows_amd64/ddev.exe $(GOTMP)/bin/windows_amd64/sudo_license.txt $(GOTMP)/bin/windows_amd64/mkcert.exe $(GOTMP)/bin/windows_amd64/mkcert_license.txt winpkg/ddev.nsi
   240  	ls -l .gotmp/bin/windows_amd64
   241  	@if [ "$(DDEV_WINDOWS_SIGN)" != "true" ] ; then echo "Skipping signing ddev.exe, DDEV_WINDOWS_SIGN not set"; else echo "Signing windows binaries..." && signtool sign -fd SHA256 ".gotmp/bin/windows_amd64/ddev.exe" ".gotmp/bin/windows_amd64/mkcert.exe" ".gotmp/bin/windows_amd64/ddev_gen_autocomplete.exe"; fi
   242  	@makensis -DVERSION=$(VERSION) winpkg/ddev.nsi  # brew install makensis, apt-get install nsis, or install on Windows
   243  	@if [ "$(DDEV_WINDOWS_SIGN)" != "true" ] ; then echo "Skipping signing ddev_windows_installer, DDEV_WINDOWS_SIGN not set"; else echo "Signing windows installer binary..." && signtool sign -fd SHA256 "$@"; fi
   244  	$(SHASUM) $@ >$@.sha256.txt
   245  
   246  no_v_version:
   247  	@echo $(NO_V_VERSION)
   248  
   249  chocolatey: $(GOTMP)/bin/windows_amd64/ddev_windows_installer.exe
   250  	rm -rf $(GOTMP)/bin/windows_amd64/chocolatey && cp -r winpkg/chocolatey $(GOTMP)/bin/windows_amd64/chocolatey
   251  	perl -pi -e 's/REPLACE_DDEV_VERSION/$(NO_V_VERSION)/g' $(GOTMP)/bin/windows_amd64/chocolatey/*.nuspec
   252  	perl -pi -e 's/REPLACE_DDEV_VERSION/$(VERSION)/g' $(GOTMP)/bin/windows_amd64/chocolatey/tools/*.ps1
   253  	perl -pi -e 's/REPLACE_GITHUB_ORG/$(GITHUB_REPOSITORY_OWNER)/g' $(GOTMP)/bin/windows_amd64/chocolatey/*.nuspec $(GOTMP)/bin/windows_amd64/chocolatey/tools/*.ps1 #GITHUB_ORG is for testing, for example when the binaries are on rfay acct
   254  	perl -pi -e "s/REPLACE_INSTALLER_CHECKSUM/$$(cat $(GOTMP)/bin/windows_amd64/ddev_windows_installer.exe.sha256.txt | awk '{ print $$1; }')/g" $(GOTMP)/bin/windows_amd64/chocolatey/tools/*
   255  	if [[ "$(NO_V_VERSION)" =~ -g[0-9a-f]+ ]]; then \
   256  		echo "Skipping chocolatey build on interim version"; \
   257  	else \
   258  		docker run --rm -v "/$(PWD)/$(GOTMP)/bin/windows_amd64/chocolatey:/tmp/chocolatey" -w "//tmp/chocolatey" linuturk/mono-choco pack ddev.nuspec; \
   259  		echo "chocolatey package is in $(GOTMP)/bin/windows_amd64/chocolatey"; \
   260  	fi
   261  
   262  $(GOTMP)/bin/windows_amd64/mkcert.exe $(GOTMP)/bin/windows_amd64/mkcert_license.txt:
   263  	curl --fail -JL -s -o $(GOTMP)/bin/windows_amd64/mkcert.exe "https://dl.filippo.io/mkcert/latest?for=windows/amd64"
   264  	curl --fail -sSL -o $(GOTMP)/bin/windows_amd64/mkcert_license.txt -O https://raw.githubusercontent.com/FiloSottile/mkcert/master/LICENSE
   265  
   266  $(GOTMP)/bin/windows_amd64/sudo_license.txt:
   267  	set -x
   268  	curl --fail -sSL -o "$(GOTMP)/bin/windows_amd64/sudo_license.txt" "https://raw.githubusercontent.com/gerardog/gsudo/master/LICENSE.txt"
   269  
   270  # Best to install golangci-lint locally with "curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b /usr/local/bin v1.31.0"
   271  golangci-lint:
   272  	@echo "golangci-lint: "
   273  	@CMD="golangci-lint run $(GOLANGCI_LINT_ARGS) $(SRC_AND_UNDER)"; \
   274  	set -eu -o pipefail; \
   275  	if command -v golangci-lint >/dev/null 2>&1; then \
   276  		$$CMD; \
   277  	else \
   278  		echo "Skipping golanci-lint as not installed"; \
   279  	fi
   280  
   281  version:
   282  	@echo VERSION:$(VERSION)
   283  
   284  clean: bin-clean
   285  
   286  bin-clean:
   287  	@rm -rf bin
   288  	$(shell if [ -d $(GOTMP) ]; then chmod -R u+w $(GOTMP) && rm -rf $(GOTMP); fi )
   289  
   290  # print-ANYVAR prints the expanded variable
   291  print-%: ; @echo $* = $($*)