Clean up build tooling and Dockerfile

- Dockerfile cross-compiles Go for the target platform (amd64/arm64
  without emulation), uses templ pinned in go.mod, runs as uid 1000 on
  alpine and lets FRONTEND_IMAGE pin the frontend version
- justfile: tools via go tool, `test` (unit) and `test-integration`
  (uses the active docker context), no hardcoded paths, no tailwind or
  frontend recipes
- Removed app.yaml, init.sh, tailwind.config.js and the tracked .idea
  folder
This commit is contained in:
Sansan committed 2026-10-06 15:21:46 +02:00
1 parent 7b144ae419
commit 59dfff38bc
13 files changed
+58 -304

No files matched your search

+27 -150
View File
@@ -1,104 +1,50 @@
set dotenv-load
# Build the application
# Build and run the unit tests
all: build test
templ-install:
@if ! command -v templ > /dev/null; then \
read -p "Go's 'templ' 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/a-h/templ/cmd/templ@latest; \
if [ ! -x "$$(command -v templ)" ]; then \
echo "templ installation failed. Exiting..."; \
exit 1; \
fi; \
else \
echo "You chose not to install templ. Exiting..."; \
exit 1; \
fi; \
fi
templ-build: templ-install
# Generate templ components (version pinned in go.mod)
templ-build:
@echo "Building templ..."
@templ generate
tailwind-macos:
@if [ ! -f tailwindcss ]; then curl -sL https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-macos-arm64 -o tailwindcss; fi
@chmod +x tailwindcss
tailwind-linux:
@if [ ! -f tailwindcss ]; then curl -sL https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-linux-x64 -o tailwindcss; fi
@chmod +x tailwindcss
tailwind-build:
@echo "Building tailwind..."
@./tailwindcss -i cmd/web/assets/css/input.css -o cmd/web/assets/css/output.css
@go tool templ generate
sqlc-generate:
@echo "Generating sqlc schema..."
@echo "Generating sqlc code..."
@sqlc generate
migrate-create name:
@migrate create -ext sql -dir internal/db/migrations -seq {{name}}
swag-install:
@if ! command -v swag > /dev/null; then \
read -p "Swag 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/swaggo/swag/cmd/swag@latest; \
if [ ! -x "$$(command -v swag)" ]; then \
echo "swag installation failed. Exiting..."; \
exit 1; \
fi; \
else \
echo "You chose not to install swag. Exiting..."; \
exit 1; \
fi; \
fi
swag-generate: swag-install
# Generate OpenAPI docs (version pinned in go.mod)
swag-generate:
@echo "Generating OpenAPI docs..."
@swag init -g internal/server/routes.go -o cmd/docs
@go tool swag init -g internal/server/routes.go -o cmd/docs --parseInternal
frontend-install:
@if ! command -v npm > /dev/null; then \
echo "npm is not installed on your machine. Please install Node.js first."; \
exit 1; \
fi
@cd cmd/frontend && npm install
frontend-build: frontend-install
@echo "Building frontend..."
@cd cmd/frontend && npm run build
[no-cd]
build: sqlc-generate templ-build swag-generate
@echo "Building..."
@go build -o main cmd/main.go
@echo "Building..."
@go build -o main cmd/main.go
run:
@templ generate
run: templ-build
@go run cmd/main.go
build-run: build
@go run cmd/main.go
@./main
test: build
@echo "Starting test database container..."
@docker compose -f compose.test.yaml up -d
@sleep 10
@echo "Running integration tests..."
@just test-integration
@echo "Stopping test database container..."
@just test-integration-down
# Unit tests: no database or Docker needed
test:
@go test -race ./...
# Integration tests against PostgreSQL in Docker (testcontainers), using the active docker context.
# Pass a pattern to run a subset, e.g. `just test-integration TestSQLDumps`
test-integration pattern=".":
@DOCKER_HOST="${DOCKER_HOST:-$(docker context inspect --format '{{{{.Endpoints.docker.Host}}')}" \
go test -tags integration -race -timeout 15m -run '{{pattern}}' ./...
# Clean the binary
clean:
@echo "Cleaning..."
@rm -f main
docker-build:
@echo "Building Docker image with docker..."
@docker build -t music-server .
docker-run:
@@ -107,82 +53,13 @@ docker-run:
docker-down:
@docker compose down
# Run integration tests with docker
# Starts a test PostgreSQL container, runs tests, then cleans up
test-integration:
@echo "Cleaning old test database..."
@docker compose -f compose.test.yaml down -v
@echo "Starting fresh test database container..."
@docker compose -f compose.test.yaml up -d
@sleep 10
@echo "Running integration tests..."
@DOCKER_HOST=unix:///Users/sebastian/.docker/run/docker.sock TESTCONTAINERS_RYUK_CONTAINER_NETWORK=testcontainers-test-net DB_HOST=localhost DB_PORT=5433 DB_USERNAME=testuser DB_PASSWORD=testpass DB_NAME=music_server_test MUSIC_PATH=/Users/sebastian/projects/MusicServer/testMusic CHARACTERS_PATH=/Users/sebastian/projects/MusicServer/testCharacters PORT=8081 LOG_LEVEL=debug LOG_JSON=false go test -v -timeout 30m -p 1 -parallel 1 ./internal/...
# Alternative: Run integration tests using testcontainers with docker provider
test-integration-tc:
@echo "Creating test network (if it doesn't exist)..."
@docker network inspect testcontainers-test-net > /dev/null 2>&1 || docker network create testcontainers-test-net
@echo "Running integration tests with testcontainers (docker provider)..."
@DOCKER_HOST=unix:///Users/sebastian/.docker/run/docker.sock TESTCONTAINERS_PROVIDER=docker TESTCONTAINERS_RYUK_CONTAINER_NETWORK=testcontainers-test-net go test -v -timeout 30m .
# Run SQL dump migration tests
# Tests that the application can start with each SQL dump and migrations work correctly
test-sql-dump:
@echo "Creating test network (if it doesn't exist)..."
@docker network inspect testcontainers-test-net > /dev/null 2>&1 || docker network create testcontainers-test-net
@echo "Running SQL dump migration tests..."
@DOCKER_HOST=unix:///Users/sebastian/.docker/run/docker.sock TESTCONTAINERS_PROVIDER=docker TESTCONTAINERS_RYUK_CONTAINER_NETWORK=testcontainers-test-net go test -v -timeout 15m -run "TestMusic.*Dump" ./internal/server/
# Run individual SQL dump tests
test-sql-dump-ref:
@echo "Creating test network (if it doesn't exist)..."
@docker network inspect testcontainers-test-net > /dev/null 2>&1 || docker network create testcontainers-test-net
@echo "Running SQL dump migration test for ref dump..."
@DOCKER_HOST=unix:///Users/sebastian/.docker/run/docker.sock TESTCONTAINERS_PROVIDER=docker TESTCONTAINERS_RYUK_CONTAINER_NETWORK=testcontainers-test-net go test -v -timeout 5m -run "TestMusicRefDump" ./internal/server/
test-sql-dump-test:
@echo "Creating test network (if it doesn't exist)..."
@docker network inspect testcontainers-test-net > /dev/null 2>&1 || docker network create testcontainers-test-net
@echo "Running SQL dump migration test for test dump..."
@DOCKER_HOST=unix:///Users/sebastian/.docker/run/docker.sock TESTCONTAINERS_PROVIDER=docker TESTCONTAINERS_RYUK_CONTAINER_NETWORK=testcontainers-test-net go test -v -timeout 5m -run "TestMusicTestDump" ./internal/server/
test-sql-dump-prod:
@echo "Creating test network (if it doesn't exist)..."
@docker network inspect testcontainers-test-net > /dev/null 2>&1 || docker network create testcontainers-test-net
@echo "Running SQL dump migration test for prod dump..."
@DOCKER_HOST=unix:///Users/sebastian/.docker/run/docker.sock TESTCONTAINERS_PROVIDER=docker TESTCONTAINERS_RYUK_CONTAINER_NETWORK=testcontainers-test-net go test -v -timeout 5m -run "TestMusicProdDump" ./internal/server/
# Stop and remove test database container
test-integration-down:
@echo "Stopping test database container..."
@docker compose -f compose.test.yaml down -v
# Build and run with Docker Compose
build-run-docker:
@echo "Building and running with Docker Compose..."
@docker compose up --build
# Shutdown containers
stop-docker:
@echo "Stopping containers..."
@docker compose down
watch-templ:
templ generate --watch --proxy="http://localhost:8080" --cmd="go run ."
@go tool templ generate --watch --proxy="http://localhost:8080" --cmd="go run ./cmd"
# Live Reload
# 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; \
@if ! command -v air > /dev/null; then \
echo "air is not installed. Install it with: go install github.com/air-verse/air@latest"; \
exit 1; \
fi
@air