Skip to content

Commit 46bce21

Browse files
committed
Merge branch 'main' of https://github.com/NFDI4Chem/nmrium-react-wrapper into prod-helm-deploy
2 parents c492920 + 06e02ec commit 46bce21

File tree

2 files changed

+52
-42
lines changed

2 files changed

+52
-42
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: 48 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#!/bin/bash
22

3-
# Set up logging
3+
set -e
4+
set -o pipefail
5+
set -u
6+
47
LOG_FILE="$HOME/nmrium-update.log"
58

69
# Create log file if it doesn't exist
@@ -9,52 +12,55 @@ if [ ! -f "$LOG_FILE" ]; then
912
chmod 644 "$LOG_FILE"
1013
fi
1114

12-
# Function to log messages
15+
# Logging function
1316
log_message() {
14-
echo "$(date): $1" >> "$LOG_FILE"
17+
echo "$(date '+%Y-%m-%d %H:%M:%S') $1" >> "$LOG_FILE"
1518
}
1619

17-
# Function to check and update a specific image and service
18-
check_and_update() {
19-
local image=$1
20-
local service=$2
21-
22-
log_message "Checking for updates for $image"
23-
24-
# Pull the latest image
25-
if ! docker pull $image; then
26-
log_message "ERROR: Failed to pull image $image"
27-
return 1
28-
fi
29-
30-
# Get the current image ID
31-
current_id=$(docker images $image --format "{{.ID}}")
32-
33-
# Get the new image ID after pull
34-
new_id=$(docker images $image --format "{{.ID}}")
35-
36-
# If the IDs are different, restart the service
37-
if [ "$current_id" != "$new_id" ]; then
38-
log_message "New image detected for $image, restarting $service"
39-
if ! docker-compose restart $service; then
40-
log_message "ERROR: Failed to restart service $service"
41-
return 1
42-
fi
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")
4347
else
44-
log_message "No updates available for $image"
48+
log_message "🔎 Image for $service is up to date"
4549
fi
46-
}
50+
done
4751

48-
# Change to the directory containing docker-compose.yml
49-
cd "$(dirname "$0")" || {
50-
log_message "ERROR: Failed to change to script directory"
51-
exit 1
52-
}
53-
54-
log_message "Starting update check"
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
5561

56-
# Check both development and production images
57-
check_and_update "nfdi4chem/nmrium-react-wrapper:dev-latest" "nmrium-dev"
58-
check_and_update "nfdi4chem/nmrium-react-wrapper:latest" "nmrium-prod"
62+
# Cleanup
63+
log_message "🧹 Cleaning up dangling images..."
64+
docker image prune -f
5965

60-
log_message "Update check completed"
66+
log_message "Update process completed."

0 commit comments

Comments
 (0)