Skip to content

Commit 78cab14

Browse files
committed
fix: update deploy script
1 parent f82819a commit 78cab14

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

.github/workflows/prod-build.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ jobs:
2727
name: Deploy to prod
2828
if: github.ref == 'refs/heads/prod-helm-deploy'
2929
runs-on: ubuntu-latest
30+
environment:
31+
name: Production
32+
url: https://nmrium.nmrxiv.org
33+
3034
steps:
3135
- name: Checkout
3236
uses: actions/[email protected]

update-nmrium.sh

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/bin/bash
2+
3+
set -e
4+
set -o pipefail
5+
set -u
6+
7+
LOG_FILE="$HOME/nmrium-update.log"
8+
9+
# Create log file if it doesn't exist
10+
if [ ! -f "$LOG_FILE" ]; then
11+
touch "$LOG_FILE"
12+
chmod 644 "$LOG_FILE"
13+
fi
14+
15+
# Logging function
16+
log_message() {
17+
echo "$(date '+%Y-%m-%d %H:%M:%S') $1" >> "$LOG_FILE"
18+
}
19+
20+
log_message "🔄 Starting Docker Compose update process..."
21+
22+
# Move to project directory
23+
PROJECT_DIR="/mnt/data/nmrium-react-wrapper"
24+
log_message "📂 Changing directory to $PROJECT_DIR"
25+
cd "$PROJECT_DIR"
26+
27+
# Pull latest deployment files
28+
log_message "🔄 Performing git pull to sync deployment files..."
29+
git pull origin prod-helm-deploy
30+
log_message "✅ Git pull completed."
31+
32+
# Define services and their images
33+
declare -A SERVICE_IMAGES
34+
SERVICE_IMAGES["nmrium-dev"]="nfdi4chem/nmrium-react-wrapper:dev-latest"
35+
SERVICE_IMAGES["nmrium-prod"]="nfdi4chem/nmrium-react-wrapper:latest"
36+
37+
# Track services with updated images
38+
UPDATED_SERVICES=()
39+
40+
for service in "${!SERVICE_IMAGES[@]}"; do
41+
image="${SERVICE_IMAGES[$service]}"
42+
log_message "📥 Checking for updates on $image"
43+
44+
if [ "$(docker pull "$image" | grep -c "Status: Image is up to date")" -eq 0 ]; then
45+
log_message "✅ New image detected for $service"
46+
UPDATED_SERVICES+=("$service")
47+
else
48+
log_message "🔎 Image for $service is up to date"
49+
fi
50+
done
51+
52+
# Recreate only changed services
53+
if [ "${#UPDATED_SERVICES[@]}" -gt 0 ]; then
54+
for service in "${UPDATED_SERVICES[@]}"; do
55+
log_message "🚀 Recreating container for $service with updated image..."
56+
docker compose up -d --force-recreate --no-deps "$service"
57+
done
58+
else
59+
log_message "✅ No new images detected. Skipping container recreation."
60+
fi
61+
62+
# Cleanup
63+
log_message "🧹 Cleaning up dangling images..."
64+
docker image prune -f
65+
66+
log_message "✅ Update process completed."

0 commit comments

Comments
 (0)