Skip to content

Dockerfile heredoc #23

@mordorim

Description

@mordorim

минорная проблема, однако, докерфайл у меня с heredoc не собирается.
версия buildx github.com/docker/buildx 0.23.0 28c90eadc4c12cc78155ad59ca5f486220241d2a

тестовые сборки с heredoc вполне работают, здесь же какой-то факап будто с экранированием кавычек.

docker build -t nodpi .
[+] Building 0.1s (1/1) FINISHED                                                                                                             docker:default
 => [internal] load build definition from Dockerfile                                                                                                   0.0s
 => => transferring dockerfile: 1.48kB                                                                                                                 0.0s
Dockerfile:15
--------------------
  13 |     #!/bin/sh
  14 |     # Get the absolute path of the script
  15 | >>> script_path="$(cd "$(dirname "$0")" && pwd)"
  16 |     # Default blacklists file
  17 |     blacklist_file="$script_path/blacklist.txt"
--------------------
ERROR: failed to solve: dockerfile parse error on line 15: unknown instruction: script_path="$(cd

Экранирование кавычек мне не помогло, в итоге переписал через echo

RUN echo '#!/bin/sh' > ./nodpi && \
    echo 'script_path="$(cd "$(dirname "$0")" && pwd)"' >> ./nodpi && \
    echo 'blacklist_file="$script_path/blacklist.txt"' >> ./nodpi && \
    echo 'blacklists_dir="/blacklists"' >> ./nodpi && \
    echo 'tmp_file="/tmp/blacklist.txt"' >> ./nodpi && \
    echo 'if [ -d "$blacklists_dir" ]; then' >> ./nodpi && \
    echo '  cat "$blacklists_dir"/* > "$tmp_file" 2>/dev/null' >> ./nodpi && \
    echo '  if [ -f "$tmp_file" ] && [ -s "$tmp_file" ]; then' >> ./nodpi && \
    echo '    blacklist_file="$tmp_file"' >> ./nodpi && \
    echo '  fi' >> ./nodpi && \
    echo 'fi' >> ./nodpi && \
    echo 'python3 "$script_path/src/main.py" --host 0.0.0.0 --blacklist "$blacklist_file" "$@"' >> ./nodpi
RUN chmod +x ./nodpi

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions