2021-08-08 15:04:11 +08:00
|
|
|
# Try to get the commit hash from 1) git 2) the VERSION file 3) fallback.
|
2023-09-19 14:12:07 +08:00
|
|
|
LAST_COMMIT := $(or $(shell git rev-parse --short HEAD 2> /dev/null),$(shell head -n 1 VERSION | grep -oP -m 1 "^[a-z0-9]+$$"),"")
|
2021-08-08 15:04:11 +08:00
|
|
|
|
2021-12-18 15:44:14 +08:00
|
|
|
# Try to get the semver from 1) git 2) the VERSION file 3) fallback.
|
2024-01-06 14:32:44 +08:00
|
|
|
VERSION := $(or $(LISTMONK_VERSION),$(shell git describe --tags --abbrev=0 2> /dev/null),$(shell grep -oP 'tag: \Kv\d+\.\d+\.\d+(-[a-zA-Z0-9.-]+)?' VERSION),"v0.0.0")
|
2021-08-08 15:04:11 +08:00
|
|
|
|
2020-10-19 01:29:22 +08:00
|
|
|
BUILDSTR := ${VERSION} (\#${LAST_COMMIT} $(shell date -u +"%Y-%m-%dT%H:%M:%S%z"))
|
2019-07-08 20:51:44 +08:00
|
|
|
|
2021-06-27 01:20:40 +08:00
|
|
|
YARN ?= yarn
|
2021-06-27 02:25:02 +08:00
|
|
|
GOPATH ?= $(HOME)/go
|
|
|
|
STUFFBIN ?= $(GOPATH)/bin/stuffbin
|
|
|
|
FRONTEND_YARN_MODULES = frontend/node_modules
|
|
|
|
FRONTEND_DIST = frontend/dist
|
|
|
|
FRONTEND_DEPS = \
|
|
|
|
$(FRONTEND_YARN_MODULES) \
|
2024-01-01 00:50:37 +08:00
|
|
|
frontend/index.html \
|
2021-06-27 02:25:02 +08:00
|
|
|
frontend/package.json \
|
2023-12-24 22:49:19 +08:00
|
|
|
frontend/vite.config.js \
|
|
|
|
frontend/.eslintrc.js \
|
2021-06-27 02:25:02 +08:00
|
|
|
$(shell find frontend/fontello frontend/public frontend/src -type f)
|
2021-06-27 01:20:40 +08:00
|
|
|
|
2018-10-25 21:51:47 +08:00
|
|
|
BIN := listmonk
|
2020-06-07 02:03:55 +08:00
|
|
|
STATIC := config.toml.sample \
|
|
|
|
schema.sql queries.sql \
|
|
|
|
static/public:/public \
|
|
|
|
static/email-templates \
|
2021-09-22 22:44:31 +08:00
|
|
|
frontend/dist:/admin \
|
2020-12-19 18:55:52 +08:00
|
|
|
i18n:/i18n
|
2018-10-25 21:51:47 +08:00
|
|
|
|
2021-06-27 02:25:02 +08:00
|
|
|
.PHONY: build
|
|
|
|
build: $(BIN)
|
|
|
|
|
|
|
|
$(STUFFBIN):
|
2021-09-19 17:32:29 +08:00
|
|
|
go install github.com/knadh/stuffbin/...
|
2021-06-27 02:25:02 +08:00
|
|
|
|
|
|
|
$(FRONTEND_YARN_MODULES): frontend/package.json frontend/yarn.lock
|
2021-06-27 01:20:40 +08:00
|
|
|
cd frontend && $(YARN) install
|
2021-09-29 16:51:06 +08:00
|
|
|
touch -c $(FRONTEND_YARN_MODULES)
|
2019-01-09 19:13:13 +08:00
|
|
|
|
2021-04-11 15:26:56 +08:00
|
|
|
# Build the backend to ./listmonk.
|
2024-01-27 23:25:50 +08:00
|
|
|
$(BIN): $(shell find . -type f -name "*.go") go.mod go.sum
|
2021-04-11 15:26:56 +08:00
|
|
|
CGO_ENABLED=0 go build -o ${BIN} -ldflags="-s -w -X 'main.buildString=${BUILDSTR}' -X 'main.versionString=${VERSION}'" cmd/*.go
|
2020-10-19 01:14:21 +08:00
|
|
|
|
2021-09-22 22:44:31 +08:00
|
|
|
# Run the backend in dev mode. The frontend assets in dev mode are loaded from disk from frontend/dist.
|
2021-02-20 16:19:14 +08:00
|
|
|
.PHONY: run
|
2021-07-25 18:17:37 +08:00
|
|
|
run:
|
2021-09-22 22:44:31 +08:00
|
|
|
CGO_ENABLED=0 go run -ldflags="-s -w -X 'main.buildString=${BUILDSTR}' -X 'main.versionString=${VERSION}' -X 'main.frontendDir=frontend/dist'" cmd/*.go
|
2019-07-08 20:51:44 +08:00
|
|
|
|
2021-04-11 15:26:56 +08:00
|
|
|
# Build the JS frontend into frontend/dist.
|
2021-06-27 02:25:02 +08:00
|
|
|
$(FRONTEND_DIST): $(FRONTEND_DEPS)
|
2021-09-22 22:44:31 +08:00
|
|
|
export VUE_APP_VERSION="${VERSION}" && cd frontend && $(YARN) build
|
2021-09-29 16:51:06 +08:00
|
|
|
touch -c $(FRONTEND_DIST)
|
2021-06-27 02:25:02 +08:00
|
|
|
|
2021-07-11 13:03:00 +08:00
|
|
|
|
2021-06-27 02:25:02 +08:00
|
|
|
.PHONY: build-frontend
|
|
|
|
build-frontend: $(FRONTEND_DIST)
|
2019-07-08 20:51:44 +08:00
|
|
|
|
2021-04-11 15:26:56 +08:00
|
|
|
# Run the JS frontend server in dev mode.
|
|
|
|
.PHONY: run-frontend
|
|
|
|
run-frontend:
|
2023-12-24 22:49:19 +08:00
|
|
|
export VUE_APP_VERSION="${VERSION}" && cd frontend && $(YARN) dev
|
2021-04-11 15:26:56 +08:00
|
|
|
|
|
|
|
# Run Go tests.
|
|
|
|
.PHONY: test
|
|
|
|
test:
|
|
|
|
go test ./...
|
2020-10-19 01:14:21 +08:00
|
|
|
|
2021-02-20 16:19:14 +08:00
|
|
|
# Bundle all static assets including the JS frontend into the ./listmonk binary
|
|
|
|
# using stuffbin (installed with make deps).
|
|
|
|
.PHONY: dist
|
2021-09-23 21:56:38 +08:00
|
|
|
dist: $(STUFFBIN) build build-frontend pack-bin
|
2021-02-20 16:19:14 +08:00
|
|
|
|
2021-04-11 15:26:56 +08:00
|
|
|
# pack-releases runns stuffbin packing on the given binary. This is used
|
|
|
|
# in the .goreleaser post-build hook.
|
|
|
|
.PHONY: pack-bin
|
2021-09-29 17:02:21 +08:00
|
|
|
pack-bin: build-frontend $(BIN) $(STUFFBIN)
|
2021-06-27 02:25:02 +08:00
|
|
|
$(STUFFBIN) -a stuff -in ${BIN} -out ${BIN} ${STATIC}
|
2021-04-11 15:26:56 +08:00
|
|
|
|
2020-10-19 01:14:21 +08:00
|
|
|
# Use goreleaser to do a dry run producing local builds.
|
|
|
|
.PHONY: release-dry
|
|
|
|
release-dry:
|
|
|
|
goreleaser --parallelism 1 --rm-dist --snapshot --skip-validate --skip-publish
|
2018-10-25 21:51:47 +08:00
|
|
|
|
2020-10-19 01:14:21 +08:00
|
|
|
# Use goreleaser to build production releases and publish them.
|
|
|
|
.PHONY: release
|
|
|
|
release:
|
|
|
|
goreleaser --parallelism 1 --rm-dist --skip-validate
|
2021-12-02 01:47:14 +08:00
|
|
|
|
|
|
|
# Build local docker images for development.
|
|
|
|
.PHONY: build-dev-docker
|
|
|
|
build-dev-docker: build ## Build docker containers for the entire suite (Front/Core/PG).
|
|
|
|
cd dev; \
|
2023-08-28 22:43:03 +08:00
|
|
|
docker compose build ; \
|
2021-12-02 01:47:14 +08:00
|
|
|
|
|
|
|
# Spin a local docker suite for local development.
|
|
|
|
.PHONY: dev-docker
|
|
|
|
dev-docker: build-dev-docker ## Build and spawns docker containers for the entire suite (Front/Core/PG).
|
|
|
|
cd dev; \
|
2023-08-28 22:43:03 +08:00
|
|
|
docker compose up
|
2021-12-02 01:47:14 +08:00
|
|
|
|
|
|
|
# Run the backend in docker-dev mode. The frontend assets in dev mode are loaded from disk from frontend/dist.
|
|
|
|
.PHONY: run-backend-docker
|
|
|
|
run-backend-docker:
|
|
|
|
CGO_ENABLED=0 go run -ldflags="-s -w -X 'main.buildString=${BUILDSTR}' -X 'main.versionString=${VERSION}' -X 'main.frontendDir=frontend/dist'" cmd/*.go --config=dev/config.toml
|
|
|
|
|
|
|
|
# Tear down the complete local development docker suite.
|
|
|
|
.PHONY: rm-dev-docker
|
|
|
|
rm-dev-docker: build ## Delete the docker containers including DB volumes.
|
|
|
|
cd dev; \
|
2023-08-28 22:43:03 +08:00
|
|
|
docker compose down -v ; \
|
2021-12-02 01:47:14 +08:00
|
|
|
|
|
|
|
# Setup the db for local dev docker suite.
|
|
|
|
.PHONY: init-dev-docker
|
|
|
|
init-dev-docker: build-dev-docker ## Delete the docker containers including DB volumes.
|
|
|
|
cd dev; \
|
2023-08-28 22:43:03 +08:00
|
|
|
docker compose run --rm backend sh -c "make dist && ./listmonk --install --idempotent --yes --config dev/config.toml"
|