Skip to content
This repository was archived by the owner on Oct 10, 2025. It is now read-only.

Commit 6b46ddd

Browse files
committed
fix: [#14] resolve yamllint validation warnings in config scripts
- Fix validate-config.sh to skip yamllint for files in application/storage/ - Use basic Python YAML validation for ignored directories instead - Fix grep pattern for template variable validation (avoid curly brace errors) - Add docker-compose.env.tpl template for Docker Compose environment - Update environment files with all required variables for production - Ensure validation works correctly for both local and production environments All linting checks now pass without warnings while respecting project ignore rules.
1 parent 94d278b commit 6b46ddd

File tree

7 files changed

+158
-16
lines changed

7 files changed

+158
-16
lines changed

Makefile

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Makefile for Torrust Tracker Local Testing Infrastructure
2-
.PHONY: help init plan apply destroy test clean status refresh-state ssh install-deps console vm-console lint lint-yaml lint-shell lint-markdown
2+
.PHONY: help init plan apply destroy test clean status refresh-state ssh install-deps console vm-console lint lint-yaml lint-shell lint-markdown configure-local configure-production validate-config validate-config-production deploy-local deploy-production start-services stop-services
33

44
# Default variables
55
VM_NAME ?= torrust-tracker-demo
@@ -342,3 +342,61 @@ vm-console: ## Access VM graphical console (GUI)
342342
echo "virt-viewer not found. Please install it:"; \
343343
echo " sudo apt install virt-viewer"; \
344344
fi
345+
346+
# Configuration Management Targets
347+
configure-local: ## Generate local environment configuration
348+
@echo "Generating local environment configuration..."
349+
@infrastructure/scripts/configure-env.sh local
350+
351+
configure-production: ## Generate production environment configuration (requires secrets)
352+
@echo "Generating production environment configuration..."
353+
@infrastructure/scripts/configure-env.sh production
354+
355+
validate-config: ## Validate generated configuration files
356+
@echo "Validating configuration files..."
357+
@infrastructure/scripts/validate-config.sh local
358+
359+
validate-config-production: ## Validate production configuration files
360+
@echo "Validating production configuration files..."
361+
@infrastructure/scripts/validate-config.sh production
362+
363+
# Deployment workflow targets
364+
deploy-local: configure-local ## Deploy VM and configure for local environment
365+
@echo "Deploying local environment..."
366+
@$(MAKE) apply
367+
@echo "Waiting for VM to be ready..."
368+
@sleep 30
369+
@echo "Starting application services..."
370+
@$(MAKE) start-services
371+
372+
deploy-production: configure-production ## Deploy and configure for production environment (requires secrets)
373+
@echo "Deploying production environment..."
374+
@$(MAKE) apply
375+
@echo "Waiting for VM to be ready..."
376+
@sleep 30
377+
@echo "Starting application services..."
378+
@$(MAKE) start-services
379+
380+
start-services: ## Start Docker Compose services in the VM
381+
@echo "Starting Docker Compose services..."
382+
@VM_IP=$$(cd $(TERRAFORM_DIR) && tofu output -raw vm_ip 2>/dev/null) || \
383+
VM_IP=$$(virsh domifaddr $(VM_NAME) | grep ipv4 | awk '{print $$4}' | cut -d'/' -f1); \
384+
if [ -n "$$VM_IP" ]; then \
385+
echo "Starting services on $$VM_IP..."; \
386+
ssh -o StrictHostKeyChecking=no torrust@$$VM_IP 'cd /home/torrust/github/torrust/torrust-tracker-demo/application && docker compose up -d'; \
387+
else \
388+
echo "Could not get VM IP. Is the VM deployed?"; \
389+
exit 1; \
390+
fi
391+
392+
stop-services: ## Stop Docker Compose services in the VM
393+
@echo "Stopping Docker Compose services..."
394+
@VM_IP=$$(cd $(TERRAFORM_DIR) && tofu output -raw vm_ip 2>/dev/null) || \
395+
VM_IP=$$(virsh domifaddr $(VM_NAME) | grep ipv4 | awk '{print $$4}' | cut -d'/' -f1); \
396+
if [ -n "$$VM_IP" ]; then \
397+
echo "Stopping services on $$VM_IP..."; \
398+
ssh -o StrictHostKeyChecking=no torrust@$$VM_IP 'cd /home/torrust/github/torrust/torrust-tracker-demo/application && docker compose down'; \
399+
else \
400+
echo "Could not get VM IP. Is the VM deployed?"; \
401+
exit 1; \
402+
fi

application/compose.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@ services:
108108
tty: true
109109
restart: unless-stopped
110110
environment:
111-
- USER_ID=${USER_ID}
111+
- USER_ID=${USER_ID:-1000}
112112
- TORRUST_TRACKER_DATABASE=${TORRUST_TRACKER_DATABASE:-mysql}
113-
- TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__DRIVER=${TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__DRIVER:-mysql}
114-
- TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__PATH=${TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__PATH:-mysql://torrust:password@mysql:3306/torrust_tracker}
115-
- TORRUST_TRACKER_CONFIG_OVERRIDE_HTTP_API__ACCESS_TOKENS__ADMIN=${TORRUST_TRACKER_CONFIG_OVERRIDE_HTTP_API__ACCESS_TOKENS__ADMIN:-MyAccessToken}
113+
- TORRUST_TRACKER_DATABASE_URL=${TORRUST_TRACKER_DATABASE_URL:-mysql://torrust:password@mysql:3306/torrust_tracker}
114+
# Configuration file will be loaded from /etc/torrust/tracker/tracker.toml
115+
# Generated by infrastructure/scripts/configure-env.sh
116116
networks:
117117
- backend_network
118118
ports:

infrastructure/config/environments/local.env

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,18 @@ TORRUST_TRACKER_HEALTH_CHECK_PORT=1313
4040
# API Authentication
4141
TORRUST_TRACKER_API_TOKEN=local-dev-token
4242

43+
# Database Configuration for Docker Compose
44+
MYSQL_ROOT_PASSWORD=root_password
45+
MYSQL_DATABASE=torrust_tracker
46+
MYSQL_USER=torrust
47+
MYSQL_PASSWORD=password
48+
TORRUST_TRACKER_DATABASE=mysql
49+
TORRUST_TRACKER_DATABASE_URL=mysql://torrust:password@mysql:3306/torrust_tracker
50+
4351
# Service Configuration
4452
GRAFANA_ADMIN_PASSWORD=admin
53+
GF_SECURITY_ADMIN_USER=admin
54+
GF_SECURITY_ADMIN_PASSWORD=admin
4555
PROMETHEUS_RETENTION_TIME=7d
4656

4757
# Docker Configuration

infrastructure/config/environments/production.env

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,18 @@ TORRUST_TRACKER_HEALTH_CHECK_PORT=1313
3939
# API Authentication (from secrets)
4040
TORRUST_TRACKER_API_TOKEN=${TORRUST_PROD_API_TOKEN}
4141

42+
# Database Configuration for Docker Compose
43+
MYSQL_ROOT_PASSWORD=${MYSQL_PROD_ROOT_PASSWORD}
44+
MYSQL_DATABASE=torrust_tracker
45+
MYSQL_USER=torrust
46+
MYSQL_PASSWORD=${MYSQL_PROD_PASSWORD}
47+
TORRUST_TRACKER_DATABASE=mysql
48+
TORRUST_TRACKER_DATABASE_URL=${TORRUST_PROD_DATABASE_URL}
49+
4250
# Service Configuration
4351
GRAFANA_ADMIN_PASSWORD=${GRAFANA_PROD_PASSWORD}
52+
GF_SECURITY_ADMIN_USER=admin
53+
GF_SECURITY_ADMIN_PASSWORD=${GRAFANA_PROD_PASSWORD}
4454
PROMETHEUS_RETENTION_TIME=30d
4555

4656
# Security Configuration
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Generated Docker Compose environment file for ${ENVIRONMENT}
2+
# Generated on: ${GENERATION_DATE}
3+
4+
# Database Configuration
5+
MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
6+
MYSQL_DATABASE=${MYSQL_DATABASE}
7+
MYSQL_USER=${MYSQL_USER}
8+
MYSQL_PASSWORD=${MYSQL_PASSWORD}
9+
10+
# Tracker Configuration
11+
USER_ID=${USER_ID}
12+
TORRUST_TRACKER_DATABASE=${TORRUST_TRACKER_DATABASE}
13+
TORRUST_TRACKER_DATABASE_URL=${TORRUST_TRACKER_DATABASE_URL}
14+
15+
# Grafana Configuration
16+
GF_SECURITY_ADMIN_USER=${GF_SECURITY_ADMIN_USER}
17+
GF_SECURITY_ADMIN_PASSWORD=${GF_SECURITY_ADMIN_PASSWORD}

infrastructure/scripts/configure-env.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,38 @@ process_templates() {
104104
log_success "Configuration templates processed"
105105
}
106106

107+
# Generate .env file for Docker Compose
108+
generate_docker_env() {
109+
local templates_dir="${CONFIG_DIR}/templates"
110+
local env_output="${PROJECT_ROOT}/application/.env"
111+
112+
log_info "Generating Docker Compose environment file"
113+
114+
# Set generation date for template
115+
GENERATION_DATE="$(date)"
116+
export GENERATION_DATE
117+
118+
# Ensure ENVIRONMENT is exported for template substitution
119+
export ENVIRONMENT
120+
121+
# Process Docker Compose environment template
122+
if [[ -f "${templates_dir}/docker-compose.env.tpl" ]]; then
123+
envsubst <"${templates_dir}/docker-compose.env.tpl" >"${env_output}"
124+
log_info "Generated: ${env_output}"
125+
else
126+
log_error "Docker Compose environment template not found: ${templates_dir}/docker-compose.env.tpl"
127+
exit 1
128+
fi
129+
}
130+
107131
# Main execution
108132
main() {
109133
log_info "Starting configuration processing for environment: ${ENVIRONMENT}"
110134

111135
load_environment
112136
validate_environment
113137
process_templates
138+
generate_docker_env
114139

115140
log_success "Configuration processing completed successfully"
116141
}

infrastructure/scripts/validate-config.sh

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -124,21 +124,43 @@ validate_yaml_files() {
124124

125125
log_info "Validating YAML configuration files..."
126126

127-
# YAML syntax validation
128-
if command -v yamllint >/dev/null 2>&1; then
129-
if yamllint "${prometheus_config}"; then
130-
log_success "YAML syntax validation passed (using yamllint)"
127+
# Check if file is in ignored directory
128+
if [[ "${prometheus_config}" == *"application/storage/"* ]]; then
129+
log_info "Skipping yamllint for file in ignored directory: application/storage/"
130+
# Basic YAML validation using Python instead
131+
if python3 -c "import yaml; yaml.safe_load(open('${prometheus_config}'))" 2>/dev/null; then
132+
log_success "Basic YAML syntax validation passed (file in ignored directory)"
131133
else
132-
log_error "YAML syntax validation failed"
134+
log_error "Basic YAML syntax validation failed"
133135
return 1
134136
fi
135137
else
136-
# Basic YAML validation using Python
137-
if python3 -c "import yaml; yaml.safe_load(open('${prometheus_config}'))" 2>/dev/null; then
138-
log_success "Basic YAML syntax validation passed"
138+
# YAML syntax validation for files not in ignored directories
139+
if command -v yamllint >/dev/null 2>&1; then
140+
# Use project yamllint config if it exists
141+
if [[ -f "${PROJECT_ROOT}/.yamllint-ci.yml" ]]; then
142+
if yamllint -c "${PROJECT_ROOT}/.yamllint-ci.yml" "${prometheus_config}"; then
143+
log_success "YAML syntax validation passed (using yamllint with project config)"
144+
else
145+
log_error "YAML syntax validation failed"
146+
return 1
147+
fi
148+
else
149+
if yamllint "${prometheus_config}"; then
150+
log_success "YAML syntax validation passed (using yamllint)"
151+
else
152+
log_error "YAML syntax validation failed"
153+
return 1
154+
fi
155+
fi
139156
else
140-
log_error "Basic YAML syntax validation failed"
141-
return 1
157+
# Basic YAML validation using Python
158+
if python3 -c "import yaml; yaml.safe_load(open('${prometheus_config}'))" 2>/dev/null; then
159+
log_success "Basic YAML syntax validation passed"
160+
else
161+
log_error "Basic YAML syntax validation failed"
162+
return 1
163+
fi
142164
fi
143165
fi
144166

@@ -243,7 +265,7 @@ validate_template_substitution() {
243265
for file in "${files_to_check[@]}"; do
244266
if [[ -f "${file}" ]]; then
245267
# Check for unsubstituted variables (${VAR} patterns)
246-
if grep -n '\$\{[^}]*\}' "${file}"; then
268+
if grep -n '\$[{][^}]*[}]' "${file}"; then
247269
log_error "Unsubstituted template variables found in: ${file}"
248270
found_issues=true
249271
fi

0 commit comments

Comments
 (0)