|
1 | | -# Docker Compose configuration for SitMe testing with Maven image |
2 | | -# This configuration runs tests using the official Maven Docker image |
3 | | -# without building a custom container image |
4 | | - |
5 | 1 | services: |
6 | | - # Test service using official Maven image |
7 | 2 | test: |
8 | | - # Use official Maven image with Eclipse Temurin JDK 21 |
9 | 3 | image: maven:3.9.11-eclipse-temurin-21 |
10 | 4 |
|
11 | | - # Set working directory inside container |
12 | 5 | working_dir: /src |
13 | 6 |
|
14 | | - # Mount source code as read-only volume for testing |
15 | 7 | volumes: |
16 | 8 | - type: bind |
17 | | - source: . # Current directory (project root) |
18 | | - target: /src # Mount point inside container |
19 | | - read_only: true # Prevent modifications to source code |
| 9 | + source: . |
| 10 | + target: /src |
| 11 | + read_only: true |
20 | 12 |
|
21 | | - # Run Maven test command with test profile |
22 | | - # Using -Ptest profile to avoid building JAR files (allows read-only source mounting) |
23 | | - entrypoint: ["mvn", "-Ptest", "clean", "verify", "--no-transfer-progress"] |
| 13 | + entrypoint: ["mvn", "-Ptest", "clean", "verify", "-Dspring.profiles.active=test", "--no-transfer-progress"] |
24 | 14 |
|
25 | | - # Custom container name for easier identification |
26 | 15 | container_name: test |
27 | 16 |
|
28 | | - # Environment variables passed to the SpringBoot application |
29 | 17 | environment: |
30 | | - - SPRING_PROFILES_ACTIVE=docker # Activates Docker-specific configuration profile |
31 | | - - SERVER_PORT=8080 # Sets the server port inside container |
32 | | - - DB_URL=jdbc:mysql://test-db:3306/sitme # Database connection URL using service name |
33 | | - - DB_USERNAME=sitme # Database username |
34 | | - - DB_PASSWORD=sitme123 # Database password |
| 18 | + - SPRING_PROFILES_ACTIVE=test |
| 19 | + - SERVER_PORT=8080 |
35 | 20 |
|
36 | | - # Restart policy - never restart (single-run test container) |
37 | 21 | restart: no |
38 | 22 |
|
39 | | - # Service dependencies - ensures database is healthy before starting app |
40 | 23 | depends_on: |
41 | | - test-db: |
42 | | - condition: service_healthy # Wait for DB health check to pass |
43 | | - |
44 | | - # Health check configuration for the SpringBoot application |
45 | | - healthcheck: |
46 | | - test: ["CMD", "curl", "-f", "http://localhost:8080/actuator/health"] # Health check command |
47 | | - interval: 30s # Check every 30 seconds |
48 | | - timeout: 10s # Timeout after 10 seconds |
49 | | - retries: 3 # Retry 3 times before marking as unhealthy |
50 | | - start_period: 60s # Wait 60 seconds before starting health checks |
| 24 | + mailhog: |
| 25 | + condition: service_started |
51 | 26 |
|
52 | | - # Connect to custom network |
53 | 27 | networks: |
54 | 28 | - test-network |
55 | 29 |
|
56 | | - # MySQL database service for testing |
57 | | - test-db: |
58 | | - # Use official MySQL 8.0 image from Docker Hub |
59 | | - image: mysql:8.0 |
| 30 | + mailhog: |
| 31 | + image: mailhog/mailhog:latest |
60 | 32 |
|
61 | | - # Custom container name for easier identification |
62 | | - container_name: test-db |
| 33 | + container_name: test-mailhog |
63 | 34 |
|
64 | | - # MySQL environment variables for database initialization |
65 | | - environment: |
66 | | - MYSQL_DATABASE: sitme # Creates database named 'sitme' |
67 | | - MYSQL_USER: sitme # Creates user 'sitme' |
68 | | - MYSQL_PASSWORD: sitme123 # Sets password for 'sitme' user |
69 | | - MYSQL_ROOT_PASSWORD: root123 # Sets root user password |
| 35 | + ports: |
| 36 | + - "1025:1025" |
| 37 | + - "8025:8025" |
70 | 38 |
|
71 | | - # Restart policy - never restart (single-run test container) |
72 | | - # No external port mapping - database only accessible from within the network |
73 | 39 | restart: no |
74 | 40 |
|
75 | | - # Health check configuration for MySQL database |
76 | | - healthcheck: |
77 | | - test: [ |
78 | | - "CMD", |
79 | | - "mysqladmin", # MySQL admin utility |
80 | | - "ping", # Ping command to check if MySQL is responding |
81 | | - "-h", |
82 | | - "localhost", # Connect to localhost |
83 | | - "-u", |
84 | | - "sitme", # Use sitme user for health check |
85 | | - "-psitme123", # Password for sitme user |
86 | | - ] |
87 | | - interval: 10s # Check every 10 seconds |
88 | | - timeout: 5s # Timeout after 5 seconds |
89 | | - retries: 5 # Retry 5 times before marking as unhealthy |
90 | | - start_period: 30s # Wait 30 seconds before starting health checks |
91 | | - |
92 | | - # Connect to custom network |
93 | 41 | networks: |
94 | 42 | - test-network |
95 | 43 |
|
96 | | -# Network configuration |
97 | 44 | networks: |
98 | 45 | test-network: |
99 | | - driver: bridge # Use bridge driver for container-to-container communication |
| 46 | + driver: bridge |
0 commit comments