From 90d82fb79b505640e5a7a8067a898cf670ef0cb1 Mon Sep 17 00:00:00 2001 From: Ruidy Date: Sat, 30 Aug 2025 22:16:48 -0400 Subject: [PATCH] build(make): replace justfile with Makefile; docs: update README; chore: remove justfile --- Makefile | 43 +++++++++++++++++++++++++++++++++++++++++++ README.md | 11 +++++++++++ justfile | 46 ---------------------------------------------- 3 files changed, 54 insertions(+), 46 deletions(-) create mode 100644 Makefile delete mode 100644 justfile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6abaa0e --- /dev/null +++ b/Makefile @@ -0,0 +1,43 @@ +# Defaults (override via `make VAR=value`) +NAME ?= rentease +PORT ?= 8000 +DB_USER ?= ruidy +DB_NAME ?= villafleurie + +DOCKER_RUN_ENV = -e DATABASE_URL="host=docker.for.mac.host.internal user=$(DB_USER) database=$(DB_NAME)" -e PORT=$(PORT) + +.PHONY: help build run dev test up-deps format lint stop + +help: ## List available commands + @grep -E '^[a-zA-Z_-]+:.*?## ' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " %-12s %s\n", $$1, $$2}' + +build: format lint ## Build the production Docker image + docker build -t $(NAME):latest . + +run: build ## Run the production container (port $(PORT)) + docker run -p $(PORT):$(PORT) $(DOCKER_RUN_ENV) $(NAME) + +dev: ## Build and run the dev container with live reload (Air) + docker build -t $(NAME):dev -f Dockerfile.dev . + docker run -p $(PORT):$(PORT) --rm \ + -v `pwd`:/app -v /app/tmp \ + --name $(NAME) \ + $(DOCKER_RUN_ENV) $(NAME):dev + +test: ## Run Go tests inside the running dev container + docker exec $(NAME) go test ./... + +up-deps: ## Update Go dependencies on host + go get -u ./... + +format: ## Generate templ files and format code (dev container must be running) + docker exec $(NAME) templ generate internal/view + docker exec $(NAME) templ fmt . + docker exec $(NAME) go fmt ./... + +lint: ## Lint the code using golangci-lint (dev container must be running) + docker exec $(NAME) golangci-lint run ./... + +stop: ## Stop the dev container + -@docker stop $(NAME) >/dev/null 2>&1 || true + diff --git a/README.md b/README.md index 260a439..1bf54d8 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,17 @@ use a cloud alternative such as Railway, fly.io, _etc._ make dev ``` +### Development Commands + +Use the included Makefile for common tasks: + +- `make dev`: Run the dev container with live reload (Air) on `http://localhost:8000`. +- `make run`: Build and run the production image locally. +- `make test`: Run `go test ./...` inside the dev container. +- `make format`: Generate templ files and format code. +- `make lint`: Lint with `golangci-lint`. +- `make stop`: Stop the dev container. + 6. **Access the application**: Open your browser and go to `http://localhost:8000` to start using Rentease. diff --git a/justfile b/justfile deleted file mode 100644 index d5ab7ef..0000000 --- a/justfile +++ /dev/null @@ -1,46 +0,0 @@ -# Set default values -name := "rentease" -port := "8000" -db_user := "ruidy" -db_name := "villafleurie" - -# List available recipes -default: - @just --list - -# Build the binary -build: format lint - @docker build -t {{name}}:latest . - -# Run the binary -run: build - @docker run -p {{port}}:{{port}} \ - -e DATABASE_URL="host=docker.for.mac.host.internal user={{db_user}} database={{db_name}}" \ - -e PORT={{port}} {{name}} - -# Run the binary in dev mode -dev: - @docker build -t {{name}}:dev -f Dockerfile.dev . - @docker run -p {{port}}:{{port}} --rm \ - -v `pwd`:/app -v /app/tmp \ - --name {{name}} \ - -e DATABASE_URL="host=docker.for.mac.host.internal user={{db_user}} database={{db_name}}" \ - -e PORT={{port}} {{name}}:dev - -# Run the tests -test: - @docker exec {{name}} go test ./... - -# Update dependencies -up-deps: - @go get -u ./... - -# Format the code -format: - @docker exec {{name}} templ generate internal/view - @docker exec {{name}} templ fmt . - @docker exec {{name}} go fmt ./... - -# Lint the code -lint: - @docker exec {{name}} golangci-lint run ./...