fix: Address code review feedback from Gemini

- Use BUILD_FROM and BUILD_ARCH for multi-architecture support
  * Replace hardcoded amd64 with BUILD_FROM in FROM statement
  * Use BUILD_ARCH variable in COPY --from directives
  * Enables building for both amd64 and aarch64 architectures

- Remove error suppression in run script for better debugging
  * Change 'cd /app || true' to 'cd /app' (fail fast on errors)
  * Remove '2> /dev/null' redirection from agent startup
  * Allow error messages to reach container logs for troubleshooting

These changes ensure the fix works correctly across all supported architectures
and provides visibility into any runtime issues.
This commit is contained in:
Claude Code
2025-12-29 15:53:37 +01:00
parent 6de904a01f
commit f0f1251285

View File

@@ -2,7 +2,9 @@
# Fix for: FATAL: PROTECTION MODE IS ENABLED! error when protection mode is OFF # Fix for: FATAL: PROTECTION MODE IS ENABLED! error when protection mode is OFF
# Approach: Level 1 (standard bashio) + Level 2 (socket fallback) # Approach: Level 1 (standard bashio) + Level 2 (socket fallback)
FROM ghcr.io/hassio-addons/base/amd64:11.1.0 ARG BUILD_FROM
ARG BUILD_ARCH
FROM $BUILD_FROM
# Step 1: Replace bashio v0.17.5 with main branch for improved API error handling # Step 1: Replace bashio v0.17.5 with main branch for improved API error handling
RUN rm -rf /usr/lib/bashio /usr/bin/bashio && \ RUN rm -rf /usr/lib/bashio /usr/bin/bashio && \
@@ -15,7 +17,7 @@ RUN rm -rf /usr/lib/bashio /usr/bin/bashio && \
rm -rf /tmp/bashio /tmp/bashio.tar.gz rm -rf /tmp/bashio /tmp/bashio.tar.gz
# Step 2: Get agent from official image # Step 2: Get agent from official image
COPY --from=ghcr.io/alexbelgium/portainer_agent-amd64:alpine-sts /app /app COPY --from=ghcr.io/alexbelgium/portainer_agent-${BUILD_ARCH}:alpine-sts /app /app
# Step 3: Add tzdata and timezone support # Step 3: Add tzdata and timezone support
RUN apk add --no-cache tzdata RUN apk add --no-cache tzdata
@@ -28,7 +30,7 @@ ENV S6_CMD_WAIT_FOR_SERVICES=1 \
S6_SERVICES_GRACETIME=0 S6_SERVICES_GRACETIME=0
# Step 5: Copy rootfs from official image # Step 5: Copy rootfs from official image
COPY --from=ghcr.io/alexbelgium/portainer_agent-amd64:alpine-sts / / COPY --from=ghcr.io/alexbelgium/portainer_agent-${BUILD_ARCH}:alpine-sts / /
# Step 6: Override the run script with simplified protection mode check # Step 6: Override the run script with simplified protection mode check
RUN mkdir -p /etc/services.d/portainer_agent RUN mkdir -p /etc/services.d/portainer_agent
@@ -94,9 +96,9 @@ bashio::require.unprotected.fixed
bashio::log.info "Starting Portainer Agent" bashio::log.info "Starting Portainer Agent"
# Launch app # Launch app
cd /app || true cd /app
if bashio::config.has_value 'PORTAINER_AGENT_ARGS'; then if bashio::config.has_value 'PORTAINER_AGENT_ARGS'; then
./agent "$PORTAINER_AGENT_ARGS" 2> /dev/null ./agent "$PORTAINER_AGENT_ARGS"
else else
./agent ./agent
fi fi