Skip to content

Commit e5a8a37

Browse files
committed
simplified deploy
1 parent 7abed17 commit e5a8a37

File tree

1 file changed

+16
-64
lines changed

1 file changed

+16
-64
lines changed

deploy.sh

Lines changed: 16 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -7,83 +7,35 @@ APP_DIR=${VPS_APP_DIR:-$(pwd)}
77

88
echo "🚀 Starting deployment of branch: $BRANCH"
99

10-
cd "$APP_DIR" || {
11-
echo "❌ Directory $APP_DIR not found!"
12-
exit 1
13-
}
10+
cd "$APP_DIR" || exit 1
1411

1512
echo "📥 Fetching latest code..."
1613
git fetch origin
1714
git reset --hard "origin/$BRANCH"
1815
git clean -fd
1916

20-
if [ ! -f .env ]; then
21-
echo "⚠️ Warning: .env file not found!"
22-
echo "Please create .env file before deployment."
23-
exit 1
24-
fi
17+
[ ! -f .env ] && { echo "❌ .env file not found!"; exit 1; }
2518

26-
echo "🛑 Stopping application container..."
27-
docker stop main-app 2>/dev/null || true
28-
docker rm main-app 2>/dev/null || true
29-
30-
echo "🔍 Checking volumes..."
31-
VOLUMES_EXIST=$(docker volume ls | grep -E "postgres_data|pgadmin_data" | wc -l)
32-
if [ "$VOLUMES_EXIST" -ge 2 ]; then
33-
echo "✅ Volumes exist and will be preserved"
34-
else
35-
echo "⚠️ Warning: Some volumes may not exist yet (will be created on first run)"
36-
fi
19+
echo "🛑 Stopping containers..."
20+
make all-down || true
3721

3822
echo "🔨 Building and starting containers..."
39-
docker compose -f docker_compose/storages.yaml --env-file .env up -d
40-
echo "🔨 Building and starting application..."
41-
docker compose -f docker_compose/storages.yaml -f docker_compose/app.yaml --env-file .env up --build -d main-app
42-
43-
DB_NAME=$(grep -E "^POSTGRES_DB=" .env 2>/dev/null | cut -d '=' -f2 | tr -d '"' | tr -d "'" || echo "organization_catalog")
44-
DB_USER=$(grep -E "^POSTGRES_USER=" .env 2>/dev/null | cut -d '=' -f2 | tr -d '"' | tr -d "'" || echo "postgres")
23+
make all
4524

46-
DB_NAME=$(echo "$DB_NAME" | xargs)
47-
DB_USER=$(echo "$DB_USER" | xargs)
25+
DB_USER=$(grep "^POSTGRES_USER=" .env | cut -d'=' -f2 | xargs || echo "postgres")
4826

49-
echo "⏳ Waiting for PostgreSQL to be ready..."
50-
MAX_ATTEMPTS=30
51-
ATTEMPT=0
52-
while [ $ATTEMPT -lt $MAX_ATTEMPTS ]; do
53-
if docker exec postgres pg_isready -U "$DB_USER" > /dev/null 2>&1; then
54-
echo "✅ PostgreSQL is ready!"
55-
break
56-
fi
57-
ATTEMPT=$((ATTEMPT + 1))
58-
echo " Attempt $ATTEMPT/$MAX_ATTEMPTS..."
27+
echo "⏳ Waiting for PostgreSQL..."
28+
for i in {1..30}; do
29+
docker exec postgres pg_isready -U "$DB_USER" >/dev/null 2>&1 && break
30+
[ $i -eq 30 ] && { echo "❌ PostgreSQL failed to start"; exit 1; }
5931
sleep 2
6032
done
33+
echo "✅ PostgreSQL is ready!"
6134

62-
if [ $ATTEMPT -eq $MAX_ATTEMPTS ]; then
63-
echo "❌ PostgreSQL failed to become ready after $MAX_ATTEMPTS attempts"
64-
exit 1
65-
fi
66-
67-
echo "🔍 Checking if database '$DB_NAME' exists..."
68-
if ! docker exec postgres psql -U "$DB_USER" -lqt 2>/dev/null | cut -d \| -f 1 | grep -qw "$DB_NAME"; then
69-
echo "📦 Creating database '$DB_NAME'..."
70-
docker exec postgres psql -U "$DB_USER" -c "CREATE DATABASE $DB_NAME;" 2>/dev/null || {
71-
echo "⚠️ Failed to create database, but continuing..."
72-
}
73-
else
74-
echo "✅ Database '$DB_NAME' already exists"
75-
fi
76-
77-
echo "📊 Running database migrations..."
78-
docker exec main-app alembic upgrade head || {
79-
echo "⚠️ Migration failed, but continuing..."
80-
}
81-
82-
echo "🧹 Cleaning up old Docker images..."
83-
docker image prune -f
84-
85-
echo "✅ Checking container status..."
86-
docker ps --filter "name=main-app" --format "table {{.Names}}\t{{.Status}}"
35+
echo "📊 Running migrations..."
36+
make migrate || true
8737

88-
echo "🎉 Deployment completed successfully!"
38+
echo "🧹 Cleaning up..."
39+
docker image prune -f >/dev/null 2>&1
8940

41+
echo "✅ Deployment completed!"

0 commit comments

Comments
 (0)