102 lines
2.3 KiB
Makefile
102 lines
2.3 KiB
Makefile
DOCKER=$(shell which docker)
|
|
PODMAN=$(shell which podman)
|
|
ifneq ($(strip $(DOCKER)),)
|
|
ENGINE=$(DOCKER)
|
|
endif
|
|
ifneq ($(strip $(PODMAN)),)
|
|
ENGINE=$(PODMAN)
|
|
endif
|
|
|
|
# Includes trailing slash
|
|
ROOT_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
|
|
|
|
# Run in dev mode and restart on changes.
|
|
.PHONY: dev
|
|
dev:
|
|
wgo -dir . \
|
|
-xdir .git \
|
|
-xdir storage \
|
|
-xdir pkg/models/sqlc \
|
|
-xfile static/css/styles.css \
|
|
-xfile data.sqlite \
|
|
make run
|
|
|
|
# Run the application in dev mode.
|
|
.PHONY: run
|
|
run: sqlc tailwind
|
|
go run \
|
|
-mod=vendor \
|
|
--tags "foreign_keys fts5" \
|
|
cmd/web/main.go --config $(ROOT_DIR)config.yaml
|
|
|
|
# Build the application binary and static files.
|
|
# This should be called from within the dev container.
|
|
.PHONY: build
|
|
build: install tailwind sqlc
|
|
rm -f orcashub
|
|
go build \
|
|
-mod=vendor \
|
|
--tags "foreign_keys fts5" \
|
|
-o orcashub \
|
|
cmd/web/main.go
|
|
|
|
# Install performs one-time steps before a build can succeed.
|
|
.PHONY: install
|
|
install:
|
|
npm install
|
|
|
|
.PHONY: sqlc
|
|
sqlc:
|
|
rm -f pkg/models/sqlc/*.sql.go
|
|
sqlc generate
|
|
|
|
# Build the application production container image.
|
|
# This should be called from outside any container.
|
|
.PHONY: build-image
|
|
build-image: check-env-VERSION
|
|
ifeq ($(strip $(ENGINE)),)
|
|
@echo "Unable to find docker or podman installed"
|
|
@exit 1
|
|
endif
|
|
$(ENGINE) build --target prod -t orcashub:${VERSION} .
|
|
|
|
# Run all tests
|
|
.PHONY: test
|
|
test:
|
|
TONYSLIST_CONFIG_FILE=$(ROOT_DIR)test-config.yaml go test \
|
|
-mod=vendor \
|
|
--tags "foreign_keys fts5 unit" \
|
|
-coverprofile=coverage.out \
|
|
./...
|
|
|
|
.PHONY: coverage
|
|
coverage:
|
|
gcov2lcov -infile=coverage.out -outfile=lcov.info
|
|
|
|
# Check for direct dependency updates
|
|
.PHONY: check-updates
|
|
check-updates:
|
|
go list --mod=mod -u -m -f '{{if not .Indirect}}{{.}}{{end}}' all | grep "\["
|
|
|
|
.PHONY: govulncheck
|
|
govulncheck:
|
|
govulncheck -scan module -C cmd/web/
|
|
|
|
.PHONY: tailwind
|
|
tailwind:
|
|
rm -f static/css/styles.css
|
|
npx postcss tailwind.css -o static/css/styles.css
|
|
|
|
# Watch for template changes and rebuild CSS file
|
|
.PHONY: tailwind-watch
|
|
tailwind-watch:
|
|
npx postcss tailwind.css -o static/css/styles.css --watch
|
|
|
|
# check-env can be set as a dependency for other build targets to assert the
|
|
# presence of an environment variable.
|
|
check-env-%:
|
|
@ if [ "${${*}}" = "" ]; then \
|
|
echo "Environment variable $* not set"; \
|
|
exit 1; \
|
|
fi
|