90 lines
1.9 KiB
Makefile
90 lines
1.9 KiB
Makefile
# Simple Makefile for a Go project
|
|
|
|
# Build the application
|
|
all: build test
|
|
|
|
build:
|
|
@echo "Building..."
|
|
|
|
|
|
@go build -o main cmd/api/main.go
|
|
|
|
# Run the application
|
|
run:
|
|
@go run cmd/api/main.go
|
|
# Create DB container
|
|
docker-run:
|
|
@if docker compose up --build 2>/dev/null; then \
|
|
: ; \
|
|
else \
|
|
echo "Falling back to Docker Compose V1"; \
|
|
docker compose up --build; \
|
|
fi
|
|
|
|
# Shutdown DB container
|
|
docker-down:
|
|
@if docker compose down 2>/dev/null; then \
|
|
: ; \
|
|
else \
|
|
echo "Falling back to Docker Compose V1"; \
|
|
docker compose down; \
|
|
fi
|
|
|
|
# Test the application
|
|
test:
|
|
@echo "Testing..."
|
|
@go test ./... -v
|
|
# Integrations Tests for the application
|
|
itest:
|
|
@echo "Running integration tests..."
|
|
@go test ./internal/database -v
|
|
|
|
# Clean the binary
|
|
clean:
|
|
@echo "Cleaning..."
|
|
@rm -f main
|
|
|
|
# Live Reload
|
|
watch:
|
|
@if command -v air > /dev/null; then \
|
|
air; \
|
|
echo "Watching...";\
|
|
else \
|
|
read -p "Go's 'air' is not installed on your machine. Do you want to install it? [Y/n] " choice; \
|
|
if [ "$$choice" != "n" ] && [ "$$choice" != "N" ]; then \
|
|
go install github.com/air-verse/air@latest; \
|
|
air; \
|
|
echo "Watching...";\
|
|
else \
|
|
echo "You chose not to install air. Exiting..."; \
|
|
exit 1; \
|
|
fi; \
|
|
fi
|
|
|
|
# Start only the PostgreSQL container
|
|
db-up:
|
|
@if docker compose up -d psql_bp 2>/dev/null; then \
|
|
: ; \
|
|
else \
|
|
echo "Falling back to Docker Compose V1"; \
|
|
docker-compose up -d psql_bp; \
|
|
fi
|
|
|
|
# Stop only the PostgreSQL container
|
|
db-down:
|
|
@if docker compose stop psql_bp 2>/dev/null; then \
|
|
: ; \
|
|
else \
|
|
echo "Falling back to Docker Compose V1"; \
|
|
docker-compose stop psql_bp; \
|
|
fi
|
|
|
|
# Run DB in Docker and API locally with Air
|
|
dev-local:
|
|
@$(MAKE) db-up
|
|
@$(MAKE) watch
|
|
seed:
|
|
@go run cmd/seed/main.go
|
|
|
|
.PHONY: all build run test clean watch docker-run docker-down db-up db-down dev-local itest seed
|