Issues while creating Swift 5.1 docker image for PPC64LE using docker build

swift5
swift
docker
#1

I am trying to build a docker image for Swift 5.1 on ppc64le using "docker build" command.

I am encountering the following issues while building Dockerfile using Docker version 18.06.1-ce.
However no errors are encountered for Docker version 1.12.1, and the entire toolchain gets built successfully with the same Dockerfile.

This is might be due to the Security Options in Docker version 18.06.1-ce.
These can be avoided for 'docker run' commands by passing following parameters, however the same is not available for 'docker build' command:-
docker run --cap-add=SYS_PTRACE --security-opt seccomp=unconfined --security-opt apparmor=unconfined -it --name swift_51 ubuntu:16.04 /bin/bash
Inside the container created in the above "docker run", I was able to successfully build entire Swift 5.1 toolchain including the entire test suite.

Following is the detailed error:-

    --- Creating installable package ---
    -- Package file: /swift-source/swift-LOCAL-2019-04-24-a-linux.tar.gz --
    /swift-source/swift-nightly-install /swift-source/swift
    + pushd /swift-source/swift-nightly-install/
    + tar -c -z -f /swift-source/swift-LOCAL-2019-04-24-a-linux.tar.gz --owner=0 --group=0 usr/
    + popd
    /swift-source/swift
    + rm -rf /swift-source/build/buildbot_linux/none-swift_package_sandbox_linux-powerpc64le
    -- Test Installable Package --
    + mkdir -p /swift-source/build/buildbot_linux/none-swift_package_sandbox_linux-powerpc64le
    /swift-source/build/buildbot_linux/none-swift_package_sandbox_linux-powerpc64le /swift-source/swift
    + pushd /swift-source/build/buildbot_linux/none-swift_package_sandbox_linux-powerpc64le
    + tar xzf /swift-source/swift-LOCAL-2019-04-24-a-linux.tar.gz
    /swift-source/swift
    + popd
    /swift-source/swift-integration-tests /swift-source/swift
    + pushd /swift-source/swift-integration-tests
    + python /swift-source/llvm/utils/lit/lit.py . -sv --param package-path=/swift-source/build/buildbot_linux/none-swift_package_sandbox_linux-powerpc64le --param test-exec-root=/swift-source/build/buildbot_linux/none-swift_package_sandbox_linux-powerpc64le/tests --param llvm-bin-dir=/swift-source/build/buildbot_linux/llvm-linux-powerpc64le/bin
    lit.py: /swift-source/swift-integration-tests/lit.cfg:131: note: testing package: '/swift-source/build/buildbot_linux/none-swift_package_sandbox_linux-powerpc64le'
    lit.py: /swift-source/swift-integration-tests/lit.cfg:143: note: testing using 'FileCheck': '/swift-source/build/buildbot_linux/llvm-linux-powerpc64le/bin/FileCheck'
    lit.py: /swift-source/swift-integration-tests/lit.cfg:144: note: testing using 'readelf': '/swift-source/build/buildbot_linux/llvm-linux-powerpc64le/bin/llvm-readelf'
    lit.py: /swift-source/swift-integration-tests/lit.cfg:165: note: testing using swift benchmarks at path: /swift-source/swift/benchmark
    lit.py: /swift-source/swift-integration-tests/lit.cfg:174: note: testing using 'swift': '/swift-source/build/buildbot_linux/none-swift_package_sandbox_linux-powerpc64le/usr/bin/swift'
    lit.py: /swift-source/swift-integration-tests/lit.cfg:179: note: testing using 'swiftc': '/swift-source/build/buildbot_linux/none-swift_package_sandbox_linux-powerpc64le/usr/bin/swiftc'
    lit.py: /swift-source/swift-integration-tests/lit.cfg:184: note: testing using 'lldb': /swift-source/build/buildbot_linux/none-swift_package_sandbox_linux-powerpc64le/usr/bin/lldb
    lit.py: /swift-source/swift-integration-tests/lit.cfg:189: note: testing using 'repl_swift': /swift-source/build/buildbot_linux/none-swift_package_sandbox_linux-powerpc64le/usr/bin/repl_swift
    lit.py: /swift-source/swift-integration-tests/lit.cfg:248: note: testing using 'sk-stress-test': /swift-source/build/buildbot_linux/none-swift_package_sandbox_linux-powerpc64le/usr/bin/sk-stress-test
    lit.py: /swift-source/swift-integration-tests/lit.cfg:249: note: testing using 'sk-swiftc-wrapper': /swift-source/build/buildbot_linux/none-swift_package_sandbox_linux-powerpc64le/usr/bin/sk-swiftc-wrapper
    -- Testing: 26 tests, 8 threads --
    Testing: 0 .. 10.. 20..
    FAIL: swift-package-tests :: repl/test-repl-glibc.py (8 of 26)
    ******************** TEST 'swift-package-tests :: repl/test-repl-glibc.py' FAILED ********************
    Script:
    --
    : 'RUN: at line 6';   rm -rf /swift-source/build/buildbot_linux/none-swift_package_sandbox_linux-powerpc64le/tests/repl/Output/test-repl-glibc.py.tmp.dir
    : 'RUN: at line 7';   mkdir /swift-source/build/buildbot_linux/none-swift_package_sandbox_linux-powerpc64le/tests/repl/Output/test-repl-glibc.py.tmp.dir
    : 'RUN: at line 8';   python /swift-source/swift-integration-tests/repl/test-repl-glibc.py /swift-source/build/buildbot_linux/none-swift_package_sandbox_linux-powerpc64le/usr/bin/swift > /swift-source/build/buildbot_linux/none-swift_package_sandbox_linux-powerpc64le/tests/repl/Output/test-repl-glibc.py.tmp.dir/output.txt
    : 'RUN: at line 9';   /swift-source/build/buildbot_linux/llvm-linux-powerpc64le/bin/FileCheck --input-file /swift-source/build/buildbot_linux/none-swift_package_sandbox_linux-powerpc64le/tests/repl/Output/test-repl-glibc.py.tmp.dir/output.txt /swift-source/swift-integration-tests/repl/test-repl-glibc.py
    --
    Exit Code: 1

    Command Output (stdout):
    --
    $ ":" "RUN: at line 6"
    $ "rm" "-rf" "/swift-source/build/buildbot_linux/none-swift_package_sandbox_linux-powerpc64le/tests/repl/Output/test-repl-glibc.py.tmp.dir"
    $ ":" "RUN: at line 7"
    $ "mkdir" "/swift-source/build/buildbot_linux/none-swift_package_sandbox_linux-powerpc64le/tests/repl/Output/test-repl-glibc.py.tmp.dir"
    $ ":" "RUN: at line 8"
    $ "python" "/swift-source/swift-integration-tests/repl/test-repl-glibc.py" "/swift-source/build/buildbot_linux/none-swift_package_sandbox_linux-powerpc64le/usr/bin/swift"
    # command stderr:
    Traceback (most recent call last):
      File "/swift-source/swift-integration-tests/repl/test-repl-glibc.py", line 22, in <module>
        repl.expect('(.*)Welcome to Swift version (.*)\r\n')
      File "/usr/lib/python2.7/dist-packages/pexpect/spawnbase.py", line 315, in expect
        timeout, searchwindowsize, async)
      File "/usr/lib/python2.7/dist-packages/pexpect/spawnbase.py", line 339, in expect_list
        return exp.expect_loop(timeout)
      File "/usr/lib/python2.7/dist-packages/pexpect/expect.py", line 102, in expect_loop
        return self.eof(e)
      File "/usr/lib/python2.7/dist-packages/pexpect/expect.py", line 49, in eof
        raise EOF(msg)
    pexpect.exceptions.EOF: End Of File (EOF). Exception style platform.
    <pexpect.pty_spawn.spawn object at 0x3fffaa680150>
    command: /swift-source/build/buildbot_linux/none-swift_package_sandbox_linux-powerpc64le/usr/bin/swift
    args: ['/swift-source/build/buildbot_linux/none-swift_package_sandbox_linux-powerpc64le/usr/bin/swift']
    searcher: None
    buffer (last 100 chars): ''
    before (last 100 chars): "error: failed to launch REPL process: process launch failed: 'A' packet returned an error: 8\r\n"
    after: <class 'pexpect.exceptions.EOF'>
    match: None
    match_index: None
    exitstatus: None
    flag_eof: True
    pid: 18431
    child_fd: 5
    closed: False
    timeout: 30
    delimiter: <class 'pexpect.exceptions.EOF'>
    logfile: None
    logfile_read: None
    logfile_send: None
    maxread: 2000
    ignorecase: False
    searchwindowsize: None
    delaybeforesend: 0.05
    delayafterclose: 0.1
    delayafterterminate: 0.1

    error: command failed with exit status: 1

    --

    ********************
    Testing: 0 .. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90..
    Testing Time: 102.82s
    ********************
    Failing Tests (1):
        swift-package-tests :: repl/test-repl-glibc.py

      Expected Passes    : 17
      Unsupported Tests  : 8
      Unexpected Failures: 1
    ./utils/build-script: fatal error: command terminated with a non-zero exit status 1, aborting
    Building the standard library for: swift-stdlib-linux-powerpc64le
    Running Swift tests for: check-swift-all-linux-powerpc64le check-swift-all-optimize-linux-powerpc64le
    ./utils/build-script: fatal error: command terminated with a non-zero exit status 1, aborting
    The command '/bin/sh -c apt-get update -y &&         apt-get install -y git cmake ninja-build clang python uuid-dev libicu-dev         icu-devtools libbsd-dev libedit-dev libxml2-dev libsqlite3-dev swig         libpython-dev libncurses5-dev pkg-config libblocksruntime-dev libcurl4-openssl-dev         systemtap-sdt-dev tzdata rsync openssh-server libc++-dev libc++abi-dev ocaml         autoconf libtool ca-certificates libstdc++-5-dev libobjc-5-dev sphinx-common         build-essential g++ re2c libc++1 libc++abi1 libc++-helpers libc++-test         libc++abi-test binutils libncurses-dev python-dev sqlite3 python-pexpect gdb &&         mkdir swift-source &&         cd swift-source &&         git clone https://github.com/apple/swift.git &&         ./swift/utils/update-checkout --clone  --scheme "swift-5.1-branch" &&         ./swift/utils/build-toolchain swift_toolchain_ppc64le' returned a non-zero code: 1
    root@pts00452-vm13:~/swift-docker#

I did have a look at docker artifacts at https://hub.docker.com/_/swift && https://github.com/apple/swift-docker. However these Dockerfiles download prebuilt release tar files and set them up, while I want my Dockerfile to download the swift-5.1-branch source and build the image from swift source.

I also tried the following on the host node and the docker containers while building using Dockerfile in order to enable ptrace:-
(As per https://linux-audit.com/protect-ptrace-processes-kernel-yama-ptrace_scope/)
echo 0 > /proc/sys/kernel/yama/ptrace_scope
sed -i 's/kernel.yama.ptrace_scope = 0/kernel.yama.ptrace_scope = 1/g' /etc/sysctl.d/10-ptrace.conf
sysctl -p

However these too does not work and still encountering the same failure.

Is there any other way I could build a docker image from Swift source using docker build command?
Any help/inputs would be greatly appreciated.

(Ian Partridge) #2

The error message error: failed to launch REPL process: process launch failed: 'A' packet returned an error: 8 does indicate that the container doesn't have the required privileges so if the REPL tests require those you will either have to find a way to build with those privileges (sorry, I don't know how to do this) or disable those tests.

I'm curious, why do you want to build a toolchain inside Docker? It's not the approach we've taken for the x86-64 images as you've seen.