Files
rs_website/Makefile
Blake Ridgway 03fcf37beb first commit
2026-03-07 21:16:51 -06:00

77 lines
2.0 KiB
Makefile

BINARY = website
MODULE = ridgwaysystems.org/website
CMD = ./cmd/server
# Default target
.PHONY: build
build:
go build -o $(BINARY) $(CMD)
# Run locally in dev mode (template hot-reloading)
.PHONY: run
run:
DEV=1 PORT=8080 go run $(CMD)
# Run with a .env file
.PHONY: run-env
run-env:
@test -f .env || (echo "No .env file found. Copy .env.example and fill it in." && exit 1)
env $$(cat .env | grep -v '^\#' | xargs) go run $(CMD)
# Cross-compile for OpenBSD amd64
.PHONY: cross
cross:
GOOS=openbsd GOARCH=amd64 go build -ldflags="-s -w" -o $(BINARY)-openbsd-amd64 $(CMD)
# Generate an admin password hash
.PHONY: genhash
genhash:
@read -p "Password: " pw && go run ./tools/genhash "$$pw"
# Download / tidy dependencies
.PHONY: tidy
tidy:
go mod tidy
# Vet and lint
.PHONY: vet
vet:
go vet ./...
# Run tests (when there are any)
.PHONY: test
test:
go test ./...
# Clean build artifacts
.PHONY: clean
clean:
rm -f $(BINARY) $(BINARY)-openbsd-amd64
rm -f static/css/syntax.css
# Upload static files and binary to OpenBSD server
# Set DEPLOY_HOST to your server (e.g. srv01 or user@10.0.10.10)
DEPLOY_HOST ?= srv01
DEPLOY_DIR ?= /var/www/ridgwaysystems
.PHONY: deploy
deploy: cross
scp $(BINARY)-openbsd-amd64 $(DEPLOY_HOST):/usr/local/bin/$(BINARY)
rsync -av --delete templates/ $(DEPLOY_HOST):$(DEPLOY_DIR)/templates/
rsync -av --delete static/ $(DEPLOY_HOST):$(DEPLOY_DIR)/static/
rsync -av content/ $(DEPLOY_HOST):$(DEPLOY_DIR)/content/
ssh $(DEPLOY_HOST) rcctl restart $(BINARY)
.PHONY: help
help:
@echo "Targets:"
@echo " build Build binary for current OS"
@echo " run Run locally in dev mode"
@echo " run-env Run with .env file"
@echo " cross Cross-compile for OpenBSD amd64"
@echo " genhash Generate bcrypt hash for admin password"
@echo " tidy go mod tidy"
@echo " vet go vet"
@echo " deploy Cross-compile and deploy to OpenBSD server"
@echo " clean Remove build artifacts"