diff --git a/.github/workflows/prod-build.yml b/.github/workflows/prod-build.yml index a7bae6d..56324e5 100644 --- a/.github/workflows/prod-build.yml +++ b/.github/workflows/prod-build.yml @@ -27,6 +27,10 @@ jobs: name: Deploy to prod if: github.ref == 'refs/heads/prod-helm-deploy' runs-on: ubuntu-latest + environment: + name: Production + url: https://nmrium.nmrxiv.org + steps: - name: Checkout uses: actions/checkout@v4.1.7 diff --git a/update-nmrium.sh b/update-nmrium.sh new file mode 100755 index 0000000..daac79c --- /dev/null +++ b/update-nmrium.sh @@ -0,0 +1,66 @@ +#!/bin/bash + +set -e +set -o pipefail +set -u + +LOG_FILE="$HOME/nmrium-update.log" + +# Create log file if it doesn't exist +if [ ! -f "$LOG_FILE" ]; then + touch "$LOG_FILE" + chmod 644 "$LOG_FILE" +fi + +# Logging function +log_message() { + echo "$(date '+%Y-%m-%d %H:%M:%S') $1" >> "$LOG_FILE" +} + +log_message "๐Ÿ”„ Starting Docker Compose update process..." + +# Move to project directory +PROJECT_DIR="/mnt/data/nmrium-react-wrapper" +log_message "๐Ÿ“‚ Changing directory to $PROJECT_DIR" +cd "$PROJECT_DIR" + +# Pull latest deployment files +log_message "๐Ÿ”„ Performing git pull to sync deployment files..." +git pull origin prod-helm-deploy +log_message "โœ… Git pull completed." + +# Define services and their images +declare -A SERVICE_IMAGES +SERVICE_IMAGES["nmrium-dev"]="nfdi4chem/nmrium-react-wrapper:dev-latest" +SERVICE_IMAGES["nmrium-prod"]="nfdi4chem/nmrium-react-wrapper:latest" + +# Track services with updated images +UPDATED_SERVICES=() + +for service in "${!SERVICE_IMAGES[@]}"; do + image="${SERVICE_IMAGES[$service]}" + log_message "๐Ÿ“ฅ Checking for updates on $image" + + if [ "$(docker pull "$image" | grep -c "Status: Image is up to date")" -eq 0 ]; then + log_message "โœ… New image detected for $service" + UPDATED_SERVICES+=("$service") + else + log_message "๐Ÿ”Ž Image for $service is up to date" + fi +done + +# Recreate only changed services +if [ "${#UPDATED_SERVICES[@]}" -gt 0 ]; then + for service in "${UPDATED_SERVICES[@]}"; do + log_message "๐Ÿš€ Recreating container for $service with updated image..." + docker compose up -d --force-recreate --no-deps "$service" + done +else + log_message "โœ… No new images detected. Skipping container recreation." +fi + +# Cleanup +log_message "๐Ÿงน Cleaning up dangling images..." +docker image prune -f + +log_message "โœ… Update process completed."