-
-
Notifications
You must be signed in to change notification settings - Fork 59
swag: modernize module with improved error handling and UX #896
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
base: main
Are you sure you want to change the base?
Changes from all commits
8e4b936
3d15632
ee18006
d40ee98
39e39f8
d2e019a
41a85b8
02444f9
9a5ed68
1c62617
0501433
11a9639
ed3abf8
584047d
518a88d
c592598
f7f1aed
d04add4
abbdd07
4284d16
a8971fb
50520d6
82b6d89
2118009
dcd1c52
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -142,6 +142,11 @@ docker_operation_progress() { | |||||||||||||||||||||||||||||||||||||||||
| # Ensure Docker is available | ||||||||||||||||||||||||||||||||||||||||||
| docker_ensure_docker | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| # Ensure unbuffer is available (for real-time pull progress) | ||||||||||||||||||||||||||||||||||||||||||
| if ! command -v unbuffer >/dev/null 2>&1; then | ||||||||||||||||||||||||||||||||||||||||||
| pkg_install expect | ||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| # Argument validation | ||||||||||||||||||||||||||||||||||||||||||
| if [[ -z "$operation" || -z "$target" ]]; then | ||||||||||||||||||||||||||||||||||||||||||
| dialog_msgbox "Usage Error" "Usage: docker_operation_progress <pull|rm|rmi> <target>\n\n pull <image> - Pull Docker image\n rm <container> - Remove container\n rmi <image> - Remove image" 12 60 | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -467,3 +472,56 @@ docker_operation_progress() { | |||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| return 0 | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| # | ||||||||||||||||||||||||||||||||||||||||||
| # Configure SWAG reverse proxy for a service | ||||||||||||||||||||||||||||||||||||||||||
| # Usage: docker_configure_swag_proxy <servicename> [port] [protocol] | ||||||||||||||||||||||||||||||||||||||||||
| # | ||||||||||||||||||||||||||||||||||||||||||
| # Parameters: | ||||||||||||||||||||||||||||||||||||||||||
| # servicename - Name of the service (e.g., "transmission", "sonarr") | ||||||||||||||||||||||||||||||||||||||||||
| # port - Optional: Override the default port in the proxy config | ||||||||||||||||||||||||||||||||||||||||||
| # protocol - Optional: Override the protocol (http/https) in the proxy config | ||||||||||||||||||||||||||||||||||||||||||
| # | ||||||||||||||||||||||||||||||||||||||||||
| # Returns: 0 on success, 1 if proxy config not found or enabling failed | ||||||||||||||||||||||||||||||||||||||||||
| # | ||||||||||||||||||||||||||||||||||||||||||
| docker_configure_swag_proxy() { | ||||||||||||||||||||||||||||||||||||||||||
| local servicename="$1" | ||||||||||||||||||||||||||||||||||||||||||
| local port="$2" | ||||||||||||||||||||||||||||||||||||||||||
| local protocol="$3" | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| # Check if SWAG container exists | ||||||||||||||||||||||||||||||||||||||||||
| if ! docker container ls -a --format "{{.Names}}" | grep -q "^swag$"; then | ||||||||||||||||||||||||||||||||||||||||||
| return 2 | ||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+492
to
+495
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Treat missing This helper is used for optional auto-configuration, but it returns Suggested fix # Check if SWAG container exists
if ! docker container ls -a --format "{{.Names}}" | grep -q "^swag$"; then
- return 2
+ return 0
fi📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| # Check if SWAG has proxy config for this service (sample or actual) | ||||||||||||||||||||||||||||||||||||||||||
| local proxy_sample="/config/nginx/proxy-confs/${servicename}.subfolder.conf.sample" | ||||||||||||||||||||||||||||||||||||||||||
| local proxy_actual="/config/nginx/proxy-confs/${servicename}.subfolder.conf" | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| if docker exec swag test -f "$proxy_sample" 2>/dev/null; then | ||||||||||||||||||||||||||||||||||||||||||
| # Copy sample to actual config if it doesn't exist | ||||||||||||||||||||||||||||||||||||||||||
| if ! docker exec swag test -f "$proxy_actual" 2>/dev/null; then | ||||||||||||||||||||||||||||||||||||||||||
| docker exec swag cp "$proxy_sample" "$proxy_actual" 2>/dev/null | ||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| # If port is specified, update it in the config | ||||||||||||||||||||||||||||||||||||||||||
| if [[ -n "$port" ]]; then | ||||||||||||||||||||||||||||||||||||||||||
| docker exec swag sed -i "s/set \\\$upstream_port [0-9]*/set \\\$upstream_port ${port}/g" "$proxy_actual" 2>/dev/null | ||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+501
to
+510
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fail fast when creating or rewriting the proxy config fails. Both Suggested fix- if docker exec swag test -f "$proxy_sample" 2>/dev/null; then
- # Copy sample to actual config if it doesn't exist
- if ! docker exec swag test -f "$proxy_actual" 2>/dev/null; then
- docker exec swag cp "$proxy_sample" "$proxy_actual" 2>/dev/null
- fi
-
- # If port is specified, update it in the config
- if [[ -n "$port" ]]; then
- docker exec swag sed -i "s/set \\\$upstream_port [0-9]*/set \\\$upstream_port ${port}/g" "$proxy_actual" 2>/dev/null
- fi
+ if docker exec swag test -f "$proxy_actual" 2>/dev/null || docker exec swag test -f "$proxy_sample" 2>/dev/null; then
+ if ! docker exec swag test -f "$proxy_actual" 2>/dev/null; then
+ docker exec swag cp "$proxy_sample" "$proxy_actual" 2>/dev/null || return 1
+ fi
+
+ if [[ -n "$port" ]]; then
+ docker exec swag sed -i "s/set \\\$upstream_port [0-9]*/set \\\$upstream_port ${port}/g" "$proxy_actual" 2>/dev/null || return 1
+ fi📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| # If protocol is specified, update it in the config | ||||||||||||||||||||||||||||||||||||||||||
| if [[ -n "$protocol" ]]; then | ||||||||||||||||||||||||||||||||||||||||||
| docker exec swag sed -i "s/set \\\$upstream_proto [a-z]*/set \\\$upstream_proto ${protocol}/g" "$proxy_actual" 2>/dev/null | ||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| # Enable the proxy configuration | ||||||||||||||||||||||||||||||||||||||||||
| if docker exec swag touch "/config/nginx/proxy-confs/${servicename}.subfolder.conf.enabled" 2>/dev/null; then | ||||||||||||||||||||||||||||||||||||||||||
| # Reload nginx to apply | ||||||||||||||||||||||||||||||||||||||||||
| docker exec swag nginx -s reload >/dev/null 2>&1 | ||||||||||||||||||||||||||||||||||||||||||
| return 0 | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+517
to
+521
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't return success until the nginx reload succeeds.
Proposed fix # Enable the proxy configuration
- if docker exec swag touch "/config/nginx/proxy-confs/${servicename}.subfolder.conf.enabled" 2>/dev/null; then
- # Reload nginx to apply
- docker exec swag nginx -s reload >/dev/null 2>&1
- return 0
- fi
+ if ! docker exec swag touch "/config/nginx/proxy-confs/${servicename}.subfolder.conf.enabled" 2>/dev/null; then
+ return 1
+ fi
+ if ! docker exec swag nginx -s reload >/dev/null 2>&1; then
+ return 1
+ fi
+ return 0📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||
| return 1 | ||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| return 1 | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ module_options+=( | |
| ["module_homepage,arch"]="" | ||
| ["module_homepage,dockerimage"]="ghcr.io/gethomepage/homepage:latest" | ||
| ["module_homepage,dockername"]="homepage" | ||
| ["module_homepage,servicename"]="homepage" | ||
| ) | ||
| # | ||
| # Module Homepage | ||
|
|
@@ -40,12 +41,17 @@ function module_homepage () { | |
| --name="$dockername" \ | ||
| -e PUID="${DOCKER_USERUID}" \ | ||
| -e PGID="${DOCKER_GROUPUID}" \ | ||
| -e TZ="$(cat /etc/timezone)" \ | ||
| -e HOMEPAGE_ALLOWED_HOSTS="${LOCALIPADD}:${port},homepage.local:${port},localhost:${port}" \ | ||
| -e HOMEPAGE_VAR_LOCALIPADD="${LOCALIPADD}" \ | ||
| -e HOMEPAGE_VAR_SWAG_URL="${SWAG_URL:-}" \ | ||
| -p "${port}:3000" \ | ||
| -v "${base_dir}/config:/app/config" \ | ||
| -v /var/run/docker.sock:/var/run/docker.sock:ro \ | ||
| --restart=always \ | ||
| "$dockerimage" | ||
| # Auto-configure SWAG reverse proxy if available | ||
| docker_configure_swag_proxy "homepage" "3000" | ||
|
Comment on lines
+53
to
+54
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Apply the same install-status guard here. This optional proxy step can override the result of Suggested fix- docker_configure_swag_proxy "homepage" "3000"
+ docker_configure_swag_proxy "homepage" "3000" || [[ $? -eq 2 ]]- "$dockerimage"
+ "$dockerimage" || return 1🤖 Prompt for AI Agents |
||
| ;; | ||
| "${commands[1]}") # remove | ||
| # Remove container and image (functions handle existence checks) | ||
|
|
||
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.
🧩 Analysis chain
🏁 Script executed:
Repository: armbian/configng
Length of output: 896
🏁 Script executed:
Repository: armbian/configng
Length of output: 258
🏁 Script executed:
Repository: armbian/configng
Length of output: 5930
🏁 Script executed:
Repository: armbian/configng
Length of output: 85
🏁 Script executed:
Repository: armbian/configng
Length of output: 790
Scope
expectinstallation topulland add a safe fallback.The
unbufferavailability check andexpectpackage installation run unconditionally for all operations (pull,rm,rmi,run), butunbufferis only used in thepulloperation (line 255). For non-pull operations, this causes unnecessary system mutation before operation validation, and any installation failure would incorrectly block rm/rmi/run operations. Gate this topullonly, and ifunbufferis unavailable, fall back to plaincurlinstead of hard-failing.Proposed fix
docker_operation_progress() { local operation="$1" local target="$2" + local use_unbuffer=0 @@ - # Ensure unbuffer is available (for real-time pull progress) - if ! command -v unbuffer >/dev/null 2>&1; then - pkg_install expect - fi + # Only pull needs unbuffer; fallback to plain curl if unavailable + if [[ "$operation" == "pull" ]]; then + if command -v unbuffer >/dev/null 2>&1; then + use_unbuffer=1 + elif pkg_install expect >/dev/null 2>&1 && command -v unbuffer >/dev/null 2>&1; then + use_unbuffer=1 + fi + fi @@ - unbuffer curl --silent --show-error \ + if [[ $use_unbuffer -eq 1 ]]; then + unbuffer curl --silent --show-error \ + --unix-socket "$socket_path" \ + -X POST "http://localhost/images/create?fromImage=${pull_image}&tag=${pull_tag}" \ + -w "%{http_code}" \ + -o "$raw_response_file" \ + 2> "$error_file" \ + > "$http_code_file" + else + curl --silent --show-error \ + --unix-socket "$socket_path" \ + -X POST "http://localhost/images/create?fromImage=${pull_image}&tag=${pull_tag}" \ + -w "%{http_code}" \ + -o "$raw_response_file" \ + 2> "$error_file" \ + > "$http_code_file" + fi - --unix-socket "$socket_path" \ - -X POST "http://localhost/images/create?fromImage=${pull_image}&tag=${pull_tag}" \ - -w "%{http_code}" \ - -o "$raw_response_file" \ - 2> "$error_file" \ - > "$http_code_file"🤖 Prompt for AI Agents