Skip to content

kamal app exec does not quote it's arguments #1651

@arturaz

Description

@arturaz

kamal 2.7.0

$ kamal app exec -d staging /app/bin/appServer maintenance 'We are upgrading our infrastructure, we will be back soon.'
Get most recent version available as an image...
Launching command with version latest-staging from new container...
  INFO [6a00eb16] Running docker login europe-west2-docker.pkg.dev -u [REDACTED] -p [REDACTED] on REDACTED
  INFO [6a00eb16] Finished in 1.345 seconds with exit status 0 (successful).
  INFO [62747e3a] Running docker run --rm --network kamal --env REDACTED="true" --env REDACTED="postgres" --env REDACTED="REDACTED" --env REDACTED="127.0.0.1" --env REDACTED="3005" --env REDACTED="REDACTED-postgresql" --env REDACTED="redis://REDACTED-redis" --env REDACTED="https://dev.REDACTED.com" --env-file .kamal/apps/REDACTED-staging/env/roles/web.env --log-opt max-size="10m" europe-west2-docker.pkg.dev/REDACTED-448312/docker/REDACTED-staging:latest-staging /app/bin/appServer maintenance We are upgrading our infrastructure, we will be back soon. on REDACTED
  ERROR (SSHKit::Command::Failed): Exception while executing on host REDACTED: docker exit status: 1
docker stdout: 
...
Unknown command: maintenance We are upgrading our infrastructure, we will be back soon.
docker stderr: Nothing written

The appServer should receive "maintenance" "We are upgrading our infrastructure, we will be back soon." as arguments.

Workaround:

#!/bin/bash

set -e

if [ -z "$1" ];  then
  echo "Usage: $0 <destination> [args]"
  exit 1
fi

destination="$1"
shift

# This correctly handles all special characters, including single quotes.
quoted_args=$(printf '%q ' "$@")

# Construct the full command string that will be executed on the remote.
remote_command="/app/bin/appServer $quoted_args"

# Pipe the command string into an interactive bash session via kamal.
# The remote bash shell will read the command from its stdin and execute it.
echo "$remote_command" | kamal app exec -d "$destination" --interactive -- bash

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions