-
Notifications
You must be signed in to change notification settings - Fork 0
General: Dockerize application with full stack setup
#12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2399455
dockerize application with full stack setup, including PostgreSQL, Sp…
Predixx a6fd2ea
update client port from 4173 to 5173 in README, docker-compose, and s…
Predixx e5db912
add startup scripts for automated Docker setup on macOS/Linux and Win…
Predixx 0530de9
remove Azure OpenAI configuration from server environment variables i…
Predixx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| .git | ||
| .github | ||
| .gradle | ||
| build/ | ||
| out/ | ||
| node_modules/ | ||
| src/main/webapp/node_modules/ | ||
| src/main/webapp/dist/ | ||
| *.iml | ||
| .idea/ | ||
| Dockerfile | ||
| docker-compose.yml | ||
| docker/postgres_data/ | ||
| .DS_Store |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # Build the React/Vite client | ||
| FROM node:22-bookworm-slim AS builder | ||
| WORKDIR /app | ||
|
|
||
| COPY src/main/webapp/package*.json ./ | ||
| RUN npm ci | ||
|
|
||
| COPY src/main/webapp . | ||
|
|
||
| ARG VITE_API_BASE_URL=http://localhost:8080 | ||
| ENV VITE_API_BASE_URL=${VITE_API_BASE_URL} | ||
| ENV NODE_ENV=production | ||
|
|
||
| RUN npm run build | ||
|
|
||
| # Serve the production build with nginx | ||
| FROM nginx:1.27-alpine AS runner | ||
|
|
||
| COPY docker/nginx.conf /etc/nginx/conf.d/default.conf | ||
| COPY --from=builder /app/dist /usr/share/nginx/html | ||
|
|
||
| EXPOSE 80 | ||
|
|
||
| CMD ["nginx", "-g", "daemon off;"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| server { | ||
| listen 80; | ||
| server_name _; | ||
|
|
||
| root /usr/share/nginx/html; | ||
| index index.html; | ||
|
|
||
| gzip on; | ||
| gzip_types text/plain application/xml text/css application/javascript application/json image/svg+xml; | ||
|
|
||
| location / { | ||
| try_files $uri /index.html; | ||
| } | ||
|
|
||
| location /api/ { | ||
| proxy_pass http://harmonia-server:8080/api/; | ||
| proxy_set_header Host $host; | ||
| proxy_set_header X-Real-IP $remote_addr; | ||
| proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
| proxy_set_header X-Forwarded-Proto $scheme; | ||
| } | ||
|
|
||
| location /actuator/ { | ||
| proxy_pass http://harmonia-server:8080/actuator/; | ||
| proxy_set_header Host $host; | ||
| proxy_set_header X-Real-IP $remote_addr; | ||
| proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
| proxy_set_header X-Forwarded-Proto $scheme; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # Build the Spring Boot application | ||
| FROM eclipse-temurin:25-jdk AS builder | ||
| WORKDIR /app | ||
|
|
||
| COPY . . | ||
|
|
||
| RUN chmod +x gradlew | ||
| RUN ./gradlew --no-daemon bootJar -x test \ | ||
| && JAR_FILE=$(find build/libs -maxdepth 1 -type f -name "*.jar" ! -name "*-plain.jar" | head -n 1) \ | ||
| && cp "${JAR_FILE}" /app/application.jar | ||
|
|
||
| # Run the packaged jar with a lightweight JRE | ||
| FROM eclipse-temurin:25-jre | ||
| WORKDIR /app | ||
|
|
||
| COPY --from=builder /app/application.jar app.jar | ||
|
|
||
| EXPOSE 8080 | ||
|
|
||
| ENTRYPOINT ["java", "-jar", "/app/app.jar"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Harmonia Startup Script | ||
| # This script starts all services using Docker containers | ||
|
|
||
| set -e # Exit on error | ||
|
|
||
| # Colors for output | ||
| GREEN='\033[0;32m' | ||
| BLUE='\033[0;34m' | ||
| YELLOW='\033[1;33m' | ||
| RED='\033[0;31m' | ||
| NC='\033[0m' # No Color | ||
|
|
||
| echo -e "${BLUE}========================================${NC}" | ||
| echo -e "${BLUE} Starting Harmonia Application${NC}" | ||
| echo -e "${BLUE} (Containerized Version)${NC}" | ||
| echo -e "${BLUE}========================================${NC}\n" | ||
|
|
||
| # Step 1: Check Docker is running | ||
| echo -e "${GREEN}[1/4] Checking Docker...${NC}" | ||
| if ! docker info >/dev/null 2>&1; then | ||
| echo -e "${RED}✗ Docker is not running. Please start Docker Desktop.${NC}" | ||
| exit 1 | ||
| fi | ||
| echo -e "${GREEN}✓ Docker is running${NC}\n" | ||
|
|
||
| # Step 2: Clean up any existing containers | ||
| echo -e "${GREEN}[2/4] Cleaning up existing containers...${NC}" | ||
| docker compose -f docker/docker-compose.yml down --remove-orphans 2>/dev/null || true | ||
| echo -e "${GREEN}✓ Cleanup completed${NC}\n" | ||
|
|
||
| # Step 3: Build and start all services | ||
| echo -e "${GREEN}[3/4] Building and starting all services...${NC}" | ||
| echo -e "${YELLOW}This may take several minutes for the first run...${NC}" | ||
| echo -e "${YELLOW}Building Docker images and starting containers...${NC}\n" | ||
|
|
||
| # Start services in background and capture output | ||
| docker compose -f docker/docker-compose.yml up --build -d | ||
|
|
||
| if [ $? -eq 0 ]; then | ||
| echo -e "${GREEN}✓ All services started successfully${NC}\n" | ||
| else | ||
| echo -e "${RED}✗ Failed to start services${NC}" | ||
| echo -e "${YELLOW}Check logs with: docker compose -f docker/docker-compose.yml logs${NC}" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Step 4: Wait for services to be ready | ||
| echo -e "${GREEN}[4/4] Waiting for services to be ready...${NC}" | ||
| echo -e "${YELLOW}Checking service health...${NC}" | ||
|
|
||
| # Wait for postgres to be healthy | ||
| echo -e "${YELLOW}• Waiting for PostgreSQL...${NC}" | ||
| timeout=60 | ||
| while [ $timeout -gt 0 ]; do | ||
| if docker compose -f docker/docker-compose.yml ps postgres | grep -q "healthy"; then | ||
| echo -e "${GREEN} ✓ PostgreSQL is ready${NC}" | ||
| break | ||
| fi | ||
| sleep 2 | ||
| ((timeout-=2)) | ||
| done | ||
|
|
||
| if [ $timeout -le 0 ]; then | ||
| echo -e "${RED} ✗ PostgreSQL failed to start within 60 seconds${NC}" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Wait for server to be responding | ||
| echo -e "${YELLOW}• Waiting for Spring Boot server...${NC}" | ||
| timeout=120 | ||
| while [ $timeout -gt 0 ]; do | ||
| if curl -f -s http://localhost:8080/actuator/health >/dev/null 2>&1; then | ||
| echo -e "${GREEN} ✓ Server is ready${NC}" | ||
| break | ||
| fi | ||
| sleep 3 | ||
| ((timeout-=3)) | ||
| done | ||
|
|
||
| if [ $timeout -le 0 ]; then | ||
| echo -e "${YELLOW} ⚠ Server may still be starting (timeout reached)${NC}" | ||
| fi | ||
|
|
||
| # Check if client is responding | ||
| echo -e "${YELLOW}• Waiting for React client...${NC}" | ||
| timeout=30 | ||
| while [ $timeout -gt 0 ]; do | ||
| if curl -f -s http://localhost:5173 >/dev/null 2>&1; then | ||
| echo -e "${GREEN} ✓ Client is ready${NC}" | ||
| break | ||
| fi | ||
| sleep 2 | ||
| ((timeout-=2)) | ||
| done | ||
|
|
||
| if [ $timeout -le 0 ]; then | ||
| echo -e "${YELLOW} ⚠ Client may still be starting (timeout reached)${NC}" | ||
| fi | ||
|
|
||
| # Summary | ||
| echo -e "\n${BLUE}========================================${NC}" | ||
| echo -e "${GREEN}✓ Harmonia is now running!${NC}" | ||
| echo -e "${BLUE}========================================${NC}" | ||
| echo -e "${YELLOW}Server:${NC} http://localhost:8080" | ||
| echo -e "${YELLOW}Client:${NC} http://localhost:5173" | ||
| echo -e "${YELLOW}Database:${NC} PostgreSQL on localhost:5432" | ||
| echo -e "\n${YELLOW}Useful commands:${NC}" | ||
| echo -e "${YELLOW}• View logs:${NC} docker compose -f docker/docker-compose.yml logs -f" | ||
| echo -e "${YELLOW}• Stop services:${NC} docker compose -f docker/docker-compose.yml down" | ||
| echo -e "${YELLOW}• Restart services:${NC} docker compose -f docker/docker-compose.yml restart" | ||
| echo -e "\n${YELLOW}Press Ctrl+C to stop all services${NC}\n" | ||
|
|
||
| # Keep script running and handle Ctrl+C | ||
| trap "echo -e '\n${RED}Shutting down all services...${NC}'; docker compose -f docker/docker-compose.yml down; exit" INT | ||
|
|
||
| # Follow logs to keep script running | ||
| docker compose -f docker/docker-compose.yml logs -f | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.