-
Notifications
You must be signed in to change notification settings - Fork 3
chore: upgrade meilisearch #270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
f882814
create meilisearch dump prior to upgrade
bytestream 173c69a
improve debug
bytestream 4c527c4
don't require meili dump if versions are equal
bytestream 925f2ef
fix shell check errors
bytestream 424988a
wait 60s for container to initialise before trying to get version
bytestream 805f21b
streamline meilisearch version retrieval and remove unnecessary pre-u…
bytestream 899f5e1
drop meilisearch instead of dump and reimport
bytestream 23189fc
write to debug log instead of output
bytestream 5757957
use sudo to stop meilisearch
bytestream 8c2726c
record meilisearch version
bytestream cd7a486
Revert "record meilisearch version"
bytestream 7dbf1be
use sudo to drop meilisearch db
bytestream 861619c
add note about upgrading dependencies
bytestream 1430510
Update templates/docker-monolithic/upgrade.sh
bytestream e519c70
Update templates/docker-monolithic/upgrade.sh
bytestream fed0043
Update templates/docker-monolithic/upgrade.sh
bytestream 522e880
Update templates/docker-monolithic/upgrade.sh
bytestream File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,6 +1,37 @@ | ||||||
| #!/bin/bash | ||||||
| set -eu -o pipefail | ||||||
|
|
||||||
| # Generate unique log filename | ||||||
| generate_log_filename() { | ||||||
| local base_name="upgrade" | ||||||
| local ext="log" | ||||||
| local filename="${base_name}.${ext}" | ||||||
| local counter=1 | ||||||
|
|
||||||
| while [ -f "$filename" ]; do | ||||||
| filename="${base_name}-${counter}.${ext}" | ||||||
| ((counter++)) | ||||||
| done | ||||||
|
|
||||||
| echo "$filename" | ||||||
| } | ||||||
|
|
||||||
| # Initialize log file | ||||||
| LOG_FILE="$(generate_log_filename)" | ||||||
| touch "$LOG_FILE" | ||||||
|
|
||||||
| # Log function - writes to log file | ||||||
| log_debug() { | ||||||
| echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*" >> "$LOG_FILE" | ||||||
| } | ||||||
|
|
||||||
| # Error exit function - notifies user about log file | ||||||
| error_exit() { | ||||||
| echo "ERROR: $1" >&2 | ||||||
| echo "A debug log is available in: $LOG_FILE" | ||||||
| exit 1 | ||||||
| } | ||||||
|
|
||||||
| usage="Options: | ||||||
| -h,--help Display this help and exit. | ||||||
| -r,--ref=5.x Git ref (commit sha, ref name, tag) to run the script on. | ||||||
|
|
@@ -37,6 +68,8 @@ while [[ "$#" -gt 0 ]]; do | |||||
| shift | ||||||
| done | ||||||
|
|
||||||
| COMPOSE_FILE_DOWNLOAD_URL="https://raw.githubusercontent.com/supportpal/helpdesk-install/${ref}/templates/docker-monolithic/docker-compose.yml" | ||||||
|
|
||||||
| # usage: version_ge <installed_version> <minimum_version> | ||||||
| version_ge() { | ||||||
| if ! [ "$(printf '%s\n' "$2" "$1" | sort -V | head -n1)" = "$2" ]; then | ||||||
|
|
@@ -81,7 +114,7 @@ backup() { | |||||
| } | ||||||
|
|
||||||
| update_compose_files() { | ||||||
| curl -fLsS https://raw.githubusercontent.com/supportpal/helpdesk-install/"${ref}"/templates/docker-monolithic/docker-compose.yml -o docker-compose.yml | ||||||
| curl -fLsS "${COMPOSE_FILE_DOWNLOAD_URL}" -o docker-compose.yml | ||||||
| } | ||||||
|
|
||||||
| update_volumes() { | ||||||
|
|
@@ -107,21 +140,216 @@ update_env() { | |||||
| fi | ||||||
| } | ||||||
|
|
||||||
| drop_meilisearch_data() { | ||||||
| echo "Preparing Meilisearch for upgrade..." | ||||||
|
|
||||||
| # Stop Meilisearch service | ||||||
| echo "Stopping Meilisearch service..." | ||||||
| if ! docker compose exec supportpal sudo sv stop 00meilisearch; then | ||||||
| error_exit "Failed to stop Meilisearch service" | ||||||
| fi | ||||||
| echo "✓ Meilisearch service stopped" | ||||||
|
|
||||||
| # Clear Meilisearch database directory (including hidden files) | ||||||
| echo "Clearing Meilisearch database directory..." | ||||||
| if ! docker compose exec supportpal bash -c 'sudo rm -rf "${MEILI_DB_PATH:?}"/* "${MEILI_DB_PATH:?}"/.[!.]*'; then | ||||||
bytestream marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| error_exit "Failed to clear Meilisearch database directory" | ||||||
| fi | ||||||
| echo "✓ Meilisearch database directory cleared" | ||||||
| } | ||||||
bytestream marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
|
||||||
| # Helper function to parse version from meilisearch --version output | ||||||
| parse_meilisearch_version() { | ||||||
| local version_output="$1" | ||||||
| local pkg_version | ||||||
|
|
||||||
| log_debug "Raw version output: $version_output" | ||||||
|
|
||||||
| # Extract version number from output like "meilisearch 1.10.3" | ||||||
| if ! pkg_version="$(echo "$version_output" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+')"; then | ||||||
| log_debug "Expected format: 'meilisearch x.y.z'" | ||||||
| log_debug "Actual output: $version_output" | ||||||
| error_exit "Failed to parse version from meilisearch --version output" | ||||||
| fi | ||||||
|
|
||||||
| log_debug "Extracted Meilisearch version: $pkg_version" | ||||||
| echo "$pkg_version" | ||||||
| } | ||||||
|
|
||||||
| # Usage: get_current_meilisearch_version <container_id> | ||||||
| get_current_meilisearch_version() { | ||||||
| local cid="$1" | ||||||
| local version | ||||||
|
|
||||||
| log_debug "Getting Meilisearch version from container: $cid" | ||||||
|
|
||||||
| # Get version directly using meilisearch --version command | ||||||
| if ! version="$(docker exec "$cid" meilisearch --version 2>&1)"; then | ||||||
| log_debug "Make sure the container is running and has meilisearch binary" | ||||||
| log_debug "Container logs:" | ||||||
| docker logs --tail 10 "$cid" >> "$LOG_FILE" 2>&1 || true | ||||||
| error_exit "Failed to get Meilisearch version from container $cid" | ||||||
| fi | ||||||
|
|
||||||
| parse_meilisearch_version "$version" | ||||||
| } | ||||||
|
|
||||||
| get_next_meilisearch_version() { | ||||||
| log_debug "Fetching next Meilisearch version from docker-compose file..." | ||||||
| log_debug "Download URL: $COMPOSE_FILE_DOWNLOAD_URL" | ||||||
|
|
||||||
| local image | ||||||
| if ! image=$(curl -fsSL "${COMPOSE_FILE_DOWNLOAD_URL}" 2>&1 | grep -m1 -E '^[[:space:]]*image:' | sed -E "s/^[[:space:]]*image:[[:space:]]*//; s/^['\"]//; s/['\"]$//"); then | ||||||
| log_debug "URL: $COMPOSE_FILE_DOWNLOAD_URL" | ||||||
| log_debug "Check if the URL is accessible and contains valid YAML" | ||||||
| error_exit "Failed to fetch or parse docker-compose file" | ||||||
| fi | ||||||
|
|
||||||
| if [ -z "$image" ]; then | ||||||
| log_debug "Expected to find a line like 'image: supportpal/helpdesk:latest'" | ||||||
| error_exit "Could not extract image name from docker-compose file" | ||||||
| fi | ||||||
|
|
||||||
| log_debug "Found image: $image" | ||||||
|
|
||||||
| # Get version directly using meilisearch --version without starting the full container | ||||||
| log_debug "Getting Meilisearch version from image..." | ||||||
|
|
||||||
| local version | ||||||
| if ! version="$(docker run --rm --entrypoint meilisearch "$image" --version 2>&1)"; then | ||||||
| log_debug "Check if the image exists and contains meilisearch binary" | ||||||
| log_debug "Docker run output: $version" | ||||||
| error_exit "Failed to get Meilisearch version from image: $image" | ||||||
| fi | ||||||
|
|
||||||
| parse_meilisearch_version "$version" | ||||||
| } | ||||||
|
|
||||||
| # Check if a version requires data dumping for upgrade | ||||||
| meili_requires_upgrade() { | ||||||
| local MEILISEARCH_DUMPLESS_VERSION="1.12.0" | ||||||
|
||||||
| local MEILISEARCH_DUMPLESS_VERSION="1.12.0" | |
| local -r MEILISEARCH_DUMPLESS_VERSION="1.12.0" |
bytestream marked this conversation as resolved.
Show resolved
Hide resolved
bytestream marked this conversation as resolved.
Show resolved
Hide resolved
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message states "A debug log is available in:" but the log file is not touched or created if an error occurs before line 21. If
error_exitis called beforeLOG_FILEis initialized (e.g., during argument parsing), this will reference an undefined variable or non-existent file. Consider initializing LOG_FILE earlier or checking if it exists before printing this message.