Skip to content

Commit

Permalink
Merge branch 'refs/heads/community_v2' into test_framework
Browse files Browse the repository at this point in the history
# Conflicts:
#	pom.xml
  • Loading branch information
Serwios committed Jul 14, 2024
2 parents 25d44b7 + f59497f commit f08de1a
Show file tree
Hide file tree
Showing 15 changed files with 317 additions and 62 deletions.
18 changes: 11 additions & 7 deletions .env-sample
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
DB_USER=
DB_PASS=
RABBIT_USER=
RABBIT_PASS=
TELEGRAM_BOT_TOKEN=
SPRING_DATASOURCE_URL=
SPRING_JPA_HIBERNATE_DDL_AUTO=
DB_NAME=community
DB_USER=backend
DB_PASS=superstrongpassword
RABBIT_HOST=rabbitmq
RABBIT_USER=community-rabbit
RABBIT_PASS=superstrongpassword
TELEGRAM_BOT_TOKEN=<your_token>
SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/community
SPRING_JPA_HIBERNATE_DDL_AUTO=update
SERVER_URL=http://localhost:8080
SPRING_APP_HEALTH_URL=http://localhost:8080/actuator/health
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ node_modules/
# Ignore Spring Boot specific files
*.pid

# Ignore Prometheus data
prometheus/

# Ignore local configuration files
local_config.yml

Expand Down
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,21 @@ This bot is designed to connect people based on their interests and preferences.

4. **Set Environment Variables**

Create a `.env` file in the root directory and add the following:
Create a `.env` file in the root directory by the .env-sample one

```env
TELEGRAM_BOT_USERNAME=your_bot_username
TELEGRAM_BOT_TOKEN=your_bot_token
TELEGRAM_BOT_WEBHOOK_PATH=webhook_path
5. **Get your IPv4 address for prometheus.yml** <br>
```java -jar ip-resolver.jar```

6. **Go to project root directory and run command** <br>
```
./run-project.sh
if no acccess -> chmod +x run-project.sh
try again -> ./run-project.sh
```
5. **Run the Application**
7. **It should run all containers including monitoring and logging**
<img width="1410" alt="image" src="https://github.com/ArchiVision/Community/assets/72043323/b510b515-aff7-4267-955e-a4534584a184">
```bash
mvn spring-boot:run
```
## Usage
Expand Down
57 changes: 20 additions & 37 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
version: '1'
services:
prometheus:
image: prom/prometheus
ports:
- "9090:9090"
volumes:
- ./prometheus:/etc/prometheus
command:
- --config.file=/etc/prometheus/prometheus.yml
depends_on:
- app

grafana:
image: grafana/grafana
app:
image: overpathz/communitybot
build: .
container_name: community-app
ports:
- "3000:3000"
- "8080:8080"
depends_on:
- prometheus
- redis
- rabbitmq
- db
environment:
SPRING_DATASOURCE_URL: jdbc:postgresql://db:5432/${DB_NAME}
SPRING_DATASOURCE_USERNAME: ${DB_USER}
SPRING_DATASOURCE_PASSWORD: ${DB_PASS}
SPRING_JPA_HIBERNATE_DDL_AUTO: update
SPRING_RABBITMQ_USERNAME: ${RABBIT_USER}
SPRING_RABBITMQ_PASSWORD: ${RABBIT_PASS}
SPRING_RABBITMQ_HOST: ${RABBIT_HOST}
TELEGRAM_BOT_TOKEN: ${TELEGRAM_BOT_TOKEN}
SPRING_PROFILES_ACTIVE: prometheus
volumes:
- ./logs:/app/logs

db:
image: 'postgres:13.1-alpine'
Expand Down Expand Up @@ -45,26 +51,3 @@ services:
environment:
- RABBITMQ_DEFAULT_USER=${RABBIT_USER}
- RABBITMQ_DEFAULT_PASS=${RABBIT_PASS}

app:
image: overpathz/communitybot
build: .
container_name: community-app
ports:
- "8080:8080"
depends_on:
- redis
- rabbitmq
- db
environment:
SPRING_DATASOURCE_URL: jdbc:postgresql://db:5432/${DB_NAME}
SPRING_DATASOURCE_USERNAME: ${DB_USER}
SPRING_DATASOURCE_PASSWORD: ${DB_PASS}
SPRING_JPA_HIBERNATE_DDL_AUTO: update
SPRING_RABBITMQ_USERNAME: ${RABBIT_USER}
SPRING_RABBITMQ_PASSWORD: ${RABBIT_PASS}
SPRING_RABBITMQ_HOST: ${RABBIT_HOST}
TELEGRAM_BOT_TOKEN: ${TELEGRAM_BOT_TOKEN}
SPRING_PROFILES_ACTIVE: prometheus
volumes:
- ./logs:/app/logs
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added ip-resolver.jar
Binary file not shown.
23 changes: 23 additions & 0 deletions monitoring-compose/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: '3.8'

services:
prometheus:
image: prom/prometheus
ports:
- "9090:9090"
volumes:
- ./prometheus:/etc/prometheus
command:
- --config.file=/etc/prometheus/prometheus.yml
healthcheck:
test: [ "CMD-SHELL", "curl -f $${SPRING_APP_HEALTH_URL} || exit 1" ]
interval: 30s
timeout: 10s
retries: 3

grafana:
image: grafana/grafana
ports:
- "3000:3000"
depends_on:
- prometheus
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ scrape_configs:
- job_name: 'app'
metrics_path: '/actuator/prometheus'
static_configs:
- targets: ['app:8080']
- targets: ['192.168.10.19:8080']
60 changes: 60 additions & 0 deletions run-project.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
@echo off
setlocal enabledelayedexpansion

set BASE_DIR=%cd%
set REBUILD_CONTAINERS=false

rem Check for rebuild flag
if "%1"=="--rebuild" (
set REBUILD_CONTAINERS=true
)

rem Function to wait for service
:wait_for_service
set service_name=%1
set url=%2
set retry_count=20
set retry_interval=10

echo Waiting for %service_name% to be ready at %url%...

for /L %%i in (1,1,%retry_count%) do (
powershell -Command "try { $response = Invoke-WebRequest -Uri %url% -UseBasicParsing; if ($response.StatusCode -eq 200) { exit 0 } } catch { exit 1 }"
if !errorlevel! == 0 (
echo %service_name% is up!
exit /b 0
)
echo Waiting for %service_name%... (Attempt %%i/%retry_count%)
timeout /t %retry_interval% >nul
)

echo Error: %service_name% is not responding at %url%
exit /b 1

rem Start ELK stack
echo Starting ELK stack...
docker-compose -f "%BASE_DIR%\elk-compose\docker-compose.yml" up -d

rem Wait for ELK stack to be up
call :wait_for_service "Elasticsearch" "http://localhost:9200"
if %errorlevel% neq 0 exit /b 1
call :wait_for_service "Kibana" "http://localhost:5601"
if %errorlevel% neq 0 exit /b 1

rem Start app stack
echo Starting app stack...
if "%REBUILD_CONTAINERS%"=="true" (
docker-compose -f "%BASE_DIR%\docker-compose.yml" up -d --build
) else (
docker-compose -f "%BASE_DIR%\docker-compose.yml" up -d
)

rem Wait for the app to be up (modify according to your app's health check)
call :wait_for_service "App" "http://localhost:8080/health"
if %errorlevel% neq 0 exit /b 1

rem Start Grafana stack
echo Starting Grafana stack...
docker-compose -f "%BASE_DIR%\monitoring-compose\docker-compose.yml" up -d

echo All services are up and running!
55 changes: 55 additions & 0 deletions run-project.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash

function wait_for_service() {
local service_name=$1
local url=$2
local retry_count=20
local retry_interval=10

echo "Waiting for $service_name to be ready at $url..."

for i in $(seq 1 $retry_count); do
if curl -s $url > /dev/null; then
echo "$service_name is up!"
return 0
fi
echo "Waiting for $service_name... (Attempt $i/$retry_count)"
sleep $retry_interval
done

echo "Error: $service_name is not responding at $url"
return 1
}

BASE_DIR=$(pwd)
REBUILD_CONTAINERS=false

# Check for rebuild flag
if [[ "$1" == "--rebuild" ]]; then
REBUILD_CONTAINERS=true
fi

# Start ELK stack
echo "Starting ELK stack..."
docker-compose -f "$BASE_DIR/elk-compose/docker-compose.yml" up -d

# Wait for ELK stack to be up
wait_for_service "Elasticsearch" "http://localhost:9200" || exit 1
wait_for_service "Kibana" "http://localhost:5601" || exit 1

# Start app stack
echo "Starting app stack..."
if [ "$REBUILD_CONTAINERS" = true ]; then
docker-compose -f "$BASE_DIR/docker-compose.yml" up -d --build
else
docker-compose -f "$BASE_DIR/docker-compose.yml" up -d
fi

# Wait for the app to be up (modify according to your app's health check)
wait_for_service "App" "http://localhost:8080/health" || exit 1

# Start Grafana stack
echo "Starting Grafana stack..."
docker-compose -f "$BASE_DIR/monitoring-compose/docker-compose.yml" up -d

echo "All services are up and running!"
69 changes: 69 additions & 0 deletions src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
telegram:
bot:
username: communitystagebot
token: 7483072284:AAEKReYVUKfbCu8i1kQHZW7IuV_W-ejMkCY

community:
likes-queue: like-events
payment-queue: payment-events

management:
endpoints:
web:
exposure:
include: info,health,metrics,prometheus
endpoint:
health:
show-details: always
metrics:
enabled: true
prometheus:
enabled: true

spring:
app:
rabbit:
like-event-queue-name: like-events
payment-event-queue-name: payment-events
jpa:
hibernate:
ddl-auto: create-drop
show-sql: true
flyway:
enabled: false
data:
mongodb:
host: localhost
port: 27017
database: mydatabase
username: admin
password: admin123
redis:
url: redis://redis:6379
datasource:
url: jdbc:postgresql://db:5432/${DB_NAME}
username: ${DB_USER}
password: ${DB_PASS}
rabbitmq:
username: ${RABBIT_USER}
password: ${RABBIT_USER}

amazon:
s3:
access-key: .
secret-key: .
bucket-name: .

logging:
level:
root: info
file:
name: logs/community.log
server:
port: 8080

paypal:
client:
id: .
secret: .
mode: sandbox
19 changes: 14 additions & 5 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,17 @@ spring:
payment-event-queue-name: payment-events
jpa:
hibernate:
ddl-auto: create-drop
show-sql: true
ddl-auto: none
properties:
hibernate:
show_sql: true
format_sql: true
flyway:
locations: classpath:db/migration
enabled: true
baseline-version: 1
baseline-description: Initial version
clean-disabled: true
data:
mongodb:
host: localhost
Expand All @@ -48,9 +57,9 @@ spring:

amazon:
s3:
access-key: .
secret-key: .
bucket-name: .
access-key: ${S3_ACCESS_KEY}
secret-key: ${S3_SECRET_KEY}
bucket-name: ${S3_BUCKET_NAME}

logging:
level:
Expand Down
Loading

0 comments on commit f08de1a

Please sign in to comment.