AdGuardHome/Makefile

341 lines
12 KiB
Makefile
Raw Normal View History

#
# Available targets
#
# * build -- builds AdGuardHome for the current platform
# * client -- builds client-side code of AdGuard Home
# * client-watch -- builds client-side code of AdGuard Home and watches for changes there
# * docker -- builds a docker image for the current platform
# * clean -- clean everything created by previous builds
# * lint -- run all linters
# * test -- run all unit-tests
# * dependencies -- installs dependencies (go and npm modules)
# * ci -- installs dependencies, runs linters and tests, intended to be used by CI/CD
#
# Building releases:
#
2020-07-10 23:24:43 +03:00
# * release -- builds AdGuard Home distros. CHANNEL must be specified (edge, release or beta).
# * release_and_sign -- builds AdGuard Home distros and signs the binary files.
# CHANNEL must be specified (edge, release or beta).
# * sign -- Repacks all release archive files and signs the binary files inside them.
# For signing to work, the public+private key pair for $(GPG_KEY) must be imported:
# gpg --import public.txt
# gpg --import private.txt
# GPG_KEY_PASSPHRASE must contain the GPG key passphrase
# * docker-multi-arch -- builds a multi-arch image. If you want it to be pushed to docker hub,
# you must specify:
# * DOCKER_IMAGE_NAME - adguard/adguard-home
# * DOCKER_OUTPUT - type=image,name=adguard/adguard-home,push=true
GOPATH := $(shell go env GOPATH)
PWD := $(shell pwd)
TARGET=AdGuardHome
BASE_URL="https://static.adguard.com/adguardhome/$(CHANNEL)"
GPG_KEY := devteam@adguard.com
GPG_KEY_PASSPHRASE :=
GPG_CMD := gpg --detach-sig --default-key $(GPG_KEY) --pinentry-mode loopback --passphrase $(GPG_KEY_PASSPHRASE)
2020-07-10 23:24:43 +03:00
# See release target
DIST_DIR=dist
# Update channel. Can be release, beta or edge. Uses edge by default.
CHANNEL ?= edge
# Validate channel
2020-07-14 11:55:26 +03:00
ifneq ($(CHANNEL),release)
ifneq ($(CHANNEL),beta)
ifneq ($(CHANNEL),edge)
$(error CHANNEL value is not valid. Valid values are release,beta or edge)
endif
endif
endif
# Version history URL (see
VERSION_HISTORY_URL="https://github.com/AdguardTeam/AdGuardHome/releases"
ifeq ($(CHANNEL),edge)
VERSION_HISTORY_URL="https://github.com/AdguardTeam/AdGuardHome/commits/master"
endif
2020-07-10 23:24:43 +03:00
# goreleaser command depends on the $CHANNEL
GORELEASER_COMMAND=goreleaser release --rm-dist --skip-publish --snapshot
ifneq ($(CHANNEL),edge)
# If this is not an "edge" build, use normal release command
GORELEASER_COMMAND=goreleaser release --rm-dist --skip-publish
endif
# Version properties
COMMIT=$(shell git rev-parse --short HEAD)
TAG_NAME=$(shell git describe --abbrev=0)
2020-07-10 14:57:53 +03:00
RELEASE_VERSION=$(TAG_NAME)
SNAPSHOT_VERSION=$(RELEASE_VERSION)-SNAPSHOT-$(COMMIT)
# Set proper version
VERSION=
ifeq ($(TAG_NAME),$(shell git describe --abbrev=4))
2020-07-22 21:29:22 +03:00
ifeq ($(CHANNEL),edge)
VERSION=$(SNAPSHOT_VERSION)
else
VERSION=$(RELEASE_VERSION)
endif
else
VERSION=$(SNAPSHOT_VERSION)
endif
# Docker target parameters
DOCKER_IMAGE_NAME ?= adguardhome-dev
DOCKER_IMAGE_FULL_NAME = $(DOCKER_IMAGE_NAME):$(VERSION)
DOCKER_PLATFORMS=linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/386,linux/ppc64le
DOCKER_OUTPUT ?= type=image,name=$(DOCKER_IMAGE_NAME),push=false
BUILD_DATE=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
# Docker tags (can be redefined)
DOCKER_TAGS ?=
ifndef DOCKER_TAGS
ifeq ($(CHANNEL),release)
DOCKER_TAGS := --tag $(DOCKER_IMAGE_NAME):latest
endif
ifeq ($(CHANNEL),beta)
DOCKER_TAGS := --tag $(DOCKER_IMAGE_NAME):beta
endif
ifeq ($(CHANNEL),edge)
# Don't set the version tag when pushing to "edge"
DOCKER_IMAGE_FULL_NAME := $(DOCKER_IMAGE_NAME):edge
# DOCKER_TAGS := --tag $(DOCKER_IMAGE_NAME):edge
endif
endif
# Validate docker build arguments
ifndef DOCKER_IMAGE_NAME
$(error DOCKER_IMAGE_NAME value is not set)
endif
.PHONY: all build client client-watch docker lint lint-js lint-go test dependencies clean release docker-multi-arch
all: build
init:
git config core.hooksPath .githooks
build: client_with_deps
go mod download
+client: "Drill down" to activity reports Close #1625 Squashed commit of the following: commit a01f12c4e5831c43dbe3ae8a80f4db12077dbb2a Author: ArtemBaskal <a.baskal@adguard.com> Date: Mon Jul 13 15:50:15 2020 +0300 minor commit b8ceb17a3b12e47de81af85fa30c2961a4a42fab Merge: 702c55ed fecf5494 Author: Andrey Meshkov <am@adguard.com> Date: Mon Jul 13 15:32:44 2020 +0300 Merge branch 'feature/1625' of ssh://bit.adguard.com:7999/dns/adguard-home into feature/1625 commit 702c55edc1ba2ab330eda8189498dfff33c92f5f Author: Andrey Meshkov <am@adguard.com> Date: Mon Jul 13 15:32:41 2020 +0300 fix makefile when there's no gopath commit fecf5494b8c1719cb70044f336fe99c341802d25 Merge: d4c811f9 8a417604 Author: ArtemBaskal <a.baskal@adguard.com> Date: Mon Jul 13 15:30:21 2020 +0300 Merge branch 'master' into feature/1625 commit d4c811f9630dee448012434e2f50f34ab8b8b899 Merge: b0a037da a33164bf Author: ArtemBaskal <a.baskal@adguard.com> Date: Mon Jul 13 12:35:16 2020 +0300 Merge branch 'master' into feature/1625 commit b0a037daf48913fd8a4cda16d520835630072520 Author: ArtemBaskal <a.baskal@adguard.com> Date: Mon Jul 13 12:34:42 2020 +0300 Simplify sync logs action creators commit eeeb620ae100a554f59783fc2a14fad525ce1a82 Author: ArtemBaskal <a.baskal@adguard.com> Date: Mon Jul 13 11:17:08 2020 +0300 Review changes commit 4cbc59eec5c794df18d6cb9b33f39091ce7cfde9 Author: ArtemBaskal <a.baskal@adguard.com> Date: Fri Jul 10 15:23:37 2020 +0300 Update tracker tooltip class commit 0a705301d4726af1c8f7f7a5776b11d338ab1d54 Author: ArtemBaskal <a.baskal@adguard.com> Date: Fri Jul 10 13:46:10 2020 +0300 Replace depricated addListener commit 2ac0843239853da1725d2e038b5e4cbaef253732 Author: ArtemBaskal <a.baskal@adguard.com> Date: Fri Jul 10 13:39:45 2020 +0300 Validate response_status url param commit 2178039ebbd0cbe2c0048cb5ab7ad7c7e7571bd1 Author: ArtemBaskal <a.baskal@adguard.com> Date: Fri Jul 10 12:58:18 2020 +0300 Fix setting empty search value, use strict search on drill down, extract refreshFilteredLogs action commit 4b11c6a34049bd133077bad035d267f87cdec141 Author: ArtemBaskal <a.baskal@adguard.com> Date: Thu Jul 9 19:41:48 2020 +0300 Normalize input search commit 3fded3575b21bdd017723f5e487c268074599e4f Author: ArtemBaskal <a.baskal@adguard.com> Date: Thu Jul 9 18:20:05 2020 +0300 Optimize search commit 9073e032e4aadcdef9d826f16a10c300ee46b30e Author: ArtemBaskal <a.baskal@adguard.com> Date: Thu Jul 9 14:28:41 2020 +0300 Update url string params commit a18cffc8bfac83103fb78ffae2f786f89aea8ba1 Author: ArtemBaskal <a.baskal@adguard.com> Date: Thu Jul 9 12:55:50 2020 +0300 Fix reset search commit 33f769aed56369aacedd29ffd52b527b527d4a59 Author: ArtemBaskal <a.baskal@adguard.com> Date: Wed Jul 8 19:13:21 2020 +0300 WIP: Add permlinks commit 4422641cf5cff06c8485ea23d58e5d42f7cca5cd Author: ArtemBaskal <a.baskal@adguard.com> Date: Wed Jul 8 14:42:28 2020 +0300 Refactor Counters, add response_status links to query log commit e8bb0b70ca55f31ef3fcdda13dcaad6f5d8479b5 Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue Jul 7 19:33:04 2020 +0300 Delete unnecessary file commit b20816e9dad79866e3ec04d3093c972967b3b226 Merge: 6281084e d2c3af5c Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue Jul 7 19:30:44 2020 +0300 Resolve conflict commit d2c3af5cf227d76f876d6d94ca016d4b242b2515 Author: ArtemBaskal <a.baskal@adguard.com> Date: Tue Jul 7 17:14:51 2020 +0300 + client: Add git hooks ... and 5 more commits
2020-07-13 16:06:56 +03:00
PATH=$(GOPATH)/bin:$(PATH) go generate ./...
CGO_ENABLED=0 go build -ldflags="-s -w -X main.version=$(VERSION) -X main.channel=$(CHANNEL) -X main.goarm=$(GOARM)"
PATH=$(GOPATH)/bin:$(PATH) packr clean
client:
npm --prefix client run build-prod
client_with_deps:
npm --prefix client ci
npm --prefix client run build-prod
client-watch:
npm --prefix client run watch
docker:
DOCKER_CLI_EXPERIMENTAL=enabled \
docker buildx build \
--build-arg VERSION=$(VERSION) \
--build-arg CHANNEL=$(CHANNEL) \
--build-arg VCS_REF=$(COMMIT) \
--build-arg BUILD_DATE=$(BUILD_DATE) \
$(DOCKER_TAGS) \
--load \
-t "$(DOCKER_IMAGE_NAME)" -f ./Dockerfile .
@echo Now you can run the docker image:
@echo docker run --name "adguard-home" -p 53:53/tcp -p 53:53/udp -p 80:80/tcp -p 443:443/tcp -p 853:853/tcp -p 3000:3000/tcp $(DOCKER_IMAGE_NAME)
lint: lint-js lint-go
lint-js: dependencies
@echo Running js linter
npm --prefix client run lint
lint-go:
@echo Running go linter
golangci-lint run
test:
@echo Running JS unit-tests
npm run test --prefix client
@echo Running Go unit-tests
go test -race -v -bench=. -coverprofile=coverage.txt -covermode=atomic ./...
ci: client_with_deps
go mod download
$(MAKE) test
dependencies:
npm --prefix client ci
go mod download
clean:
# make build output
rm -f AdGuardHome
rm -f AdGuardHome.exe
2020-07-10 16:58:52 +03:00
# tests output
rm -rf data
2020-07-10 17:10:11 +03:00
rm -f coverage.txt
# static build output
rm -rf build
# dist folder
rm -rf $(DIST_DIR)
# client deps
rm -rf client/node_modules
# packr-generated files
2020-07-10 17:18:04 +03:00
PATH=$(GOPATH)/bin:$(PATH) packr clean || true
docker-multi-arch:
DOCKER_CLI_EXPERIMENTAL=enabled \
docker buildx build \
--platform $(DOCKER_PLATFORMS) \
--build-arg VERSION=$(VERSION) \
--build-arg CHANNEL=$(CHANNEL) \
--build-arg VCS_REF=$(COMMIT) \
--build-arg BUILD_DATE=$(BUILD_DATE) \
$(DOCKER_TAGS) \
--output "$(DOCKER_OUTPUT)" \
-t "$(DOCKER_IMAGE_FULL_NAME)" -f ./Dockerfile .
@echo If the image was pushed to the registry, you can now run it:
@echo docker run --name "adguard-home" -p 53:53/tcp -p 53:53/udp -p 80:80/tcp -p 443:443/tcp -p 853:853/tcp -p 3000:3000/tcp $(DOCKER_IMAGE_NAME)
release: client_with_deps
go mod download
@echo Starting release build: version $(VERSION), channel $(CHANNEL)
2020-07-10 23:24:43 +03:00
CHANNEL=$(CHANNEL) $(GORELEASER_COMMAND)
$(call write_version_file,$(VERSION))
PATH=$(GOPATH)/bin:$(PATH) packr clean
release_and_sign: client_with_deps
$(MAKE) release
$(call repack_dist)
sign:
$(call repack_dist)
define write_version_file
$(eval version := $(1))
@echo Writing version file: $(version)
# Variables for CI
rm -f $(DIST_DIR)/version.txt
2020-07-10 14:57:53 +03:00
echo "version=$(version)" > $(DIST_DIR)/version.txt
# Prepare the version.json file
rm -f $(DIST_DIR)/version.json
echo "{" >> $(DIST_DIR)/version.json
2020-07-10 14:57:53 +03:00
echo " \"version\": \"$(version)\"," >> $(DIST_DIR)/version.json
echo " \"announcement\": \"AdGuard Home $(version) is now available!\"," >> $(DIST_DIR)/version.json
echo " \"announcement_url\": \"$(VERSION_HISTORY_URL)\"," >> $(DIST_DIR)/version.json
echo " \"selfupdate_min_version\": \"0.0\"," >> $(DIST_DIR)/version.json
# Windows builds
echo " \"download_windows_amd64\": \"$(BASE_URL)/AdGuardHome_windows_amd64.zip\"," >> $(DIST_DIR)/version.json
echo " \"download_windows_386\": \"$(BASE_URL)/AdGuardHome_windows_386.zip\"," >> $(DIST_DIR)/version.json
# MacOS builds
echo " \"download_darwin_amd64\": \"$(BASE_URL)/AdGuardHome_darwin_amd64.zip\"," >> $(DIST_DIR)/version.json
2020-07-10 23:24:43 +03:00
echo " \"download_darwin_386\": \"$(BASE_URL)/AdGuardHome_darwin_386.zip\"," >> $(DIST_DIR)/version.json
# Linux
echo " \"download_linux_amd64\": \"$(BASE_URL)/AdGuardHome_linux_amd64.tar.gz\"," >> $(DIST_DIR)/version.json
echo " \"download_linux_386\": \"$(BASE_URL)/AdGuardHome_linux_386.tar.gz\"," >> $(DIST_DIR)/version.json
# Linux, all kinds of ARM
echo " \"download_linux_arm\": \"$(BASE_URL)/AdGuardHome_linux_armv6.tar.gz\"," >> $(DIST_DIR)/version.json
echo " \"download_linux_armv5\": \"$(BASE_URL)/AdGuardHome_linux_armv5.tar.gz\"," >> $(DIST_DIR)/version.json
echo " \"download_linux_armv6\": \"$(BASE_URL)/AdGuardHome_linux_armv6.tar.gz\"," >> $(DIST_DIR)/version.json
echo " \"download_linux_armv7\": \"$(BASE_URL)/AdGuardHome_linux_armv7.tar.gz\"," >> $(DIST_DIR)/version.json
echo " \"download_linux_arm64\": \"$(BASE_URL)/AdGuardHome_linux_arm64.tar.gz\"," >> $(DIST_DIR)/version.json
# Linux, MIPS
echo " \"download_linux_mips\": \"$(BASE_URL)/AdGuardHome_linux_mips_softfloat.tar.gz\"," >> $(DIST_DIR)/version.json
echo " \"download_linux_mipsle\": \"$(BASE_URL)/AdGuardHome_linux_mipsle_softfloat.tar.gz\"," >> $(DIST_DIR)/version.json
echo " \"download_linux_mips64\": \"$(BASE_URL)/AdGuardHome_linux_mips64_softfloat.tar.gz\"," >> $(DIST_DIR)/version.json
echo " \"download_linux_mips64le\": \"$(BASE_URL)/AdGuardHome_linux_mips64le_softfloat.tar.gz\"," >> $(DIST_DIR)/version.json
# FreeBSD
echo " \"download_freebsd_386\": \"$(BASE_URL)/AdGuardHome_freebsd_386.tar.gz\"," >> $(DIST_DIR)/version.json
echo " \"download_freebsd_amd64\": \"$(BASE_URL)/AdGuardHome_freebsd_amd64.tar.gz\"," >> $(DIST_DIR)/version.json
# FreeBSD, all kinds of ARM
echo " \"download_freebsd_arm\": \"$(BASE_URL)/AdGuardHome_freebsd_armv6.tar.gz\"," >> $(DIST_DIR)/version.json
echo " \"download_freebsd_armv5\": \"$(BASE_URL)/AdGuardHome_freebsd_armv5.tar.gz\"," >> $(DIST_DIR)/version.json
echo " \"download_freebsd_armv6\": \"$(BASE_URL)/AdGuardHome_freebsd_armv6.tar.gz\"," >> $(DIST_DIR)/version.json
echo " \"download_freebsd_armv7\": \"$(BASE_URL)/AdGuardHome_freebsd_armv7.tar.gz\"," >> $(DIST_DIR)/version.json
echo " \"download_freebsd_arm64\": \"$(BASE_URL)/AdGuardHome_freebsd_arm64.tar.gz\"" >> $(DIST_DIR)/version.json
# Finish
echo "}" >> $(DIST_DIR)/version.json
endef
define repack_dist
# Repack archive files
# A temporary solution for our auto-update code to be able to unpack these archive files
# The problem is that goreleaser doesn't add directory AdGuardHome/ to the archive file
# and we can't create it
rm -rf $(DIST_DIR)/AdGuardHome
# Windows builds
$(call zip_repack_windows,AdGuardHome_windows_amd64.zip)
$(call zip_repack_windows,AdGuardHome_windows_386.zip)
# MacOS builds
$(call zip_repack,AdGuardHome_darwin_amd64.zip)
$(call zip_repack,AdGuardHome_darwin_386.zip)
# Linux
$(call tar_repack,AdGuardHome_linux_amd64.tar.gz)
$(call tar_repack,AdGuardHome_linux_386.tar.gz)
# Linux, all kinds of ARM
$(call tar_repack,AdGuardHome_linux_armv5.tar.gz)
$(call tar_repack,AdGuardHome_linux_armv6.tar.gz)
$(call tar_repack,AdGuardHome_linux_armv7.tar.gz)
$(call tar_repack,AdGuardHome_linux_arm64.tar.gz)
# Linux, MIPS
$(call tar_repack,AdGuardHome_linux_mips_softfloat.tar.gz)
$(call tar_repack,AdGuardHome_linux_mipsle_softfloat.tar.gz)
$(call tar_repack,AdGuardHome_linux_mips64_softfloat.tar.gz)
$(call tar_repack,AdGuardHome_linux_mips64le_softfloat.tar.gz)
# FreeBSD
$(call tar_repack,AdGuardHome_freebsd_386.tar.gz)
$(call tar_repack,AdGuardHome_freebsd_amd64.tar.gz)
# FreeBSD, all kinds of ARM
$(call tar_repack,AdGuardHome_freebsd_armv5.tar.gz)
$(call tar_repack,AdGuardHome_freebsd_armv6.tar.gz)
$(call tar_repack,AdGuardHome_freebsd_armv7.tar.gz)
$(call tar_repack,AdGuardHome_freebsd_arm64.tar.gz)
endef
define zip_repack_windows
$(eval ARC := $(1))
cd $(DIST_DIR) && \
unzip $(ARC) && \
$(GPG_CMD) AdGuardHome/AdGuardHome.exe && \
zip -r $(ARC) AdGuardHome/ && \
rm -rf AdGuardHome
endef
define zip_repack
$(eval ARC := $(1))
cd $(DIST_DIR) && \
unzip $(ARC) && \
$(GPG_CMD) AdGuardHome/AdGuardHome && \
zip -r $(ARC) AdGuardHome/ && \
rm -rf AdGuardHome
endef
define tar_repack
$(eval ARC := $(1))
cd $(DIST_DIR) && \
tar xzf $(ARC) && \
$(GPG_CMD) AdGuardHome/AdGuardHome && \
tar czf $(ARC) AdGuardHome/ && \
rm -rf AdGuardHome
endef