Vapor builder docker image success run error not fount libswift_Concurrency.so

./Run: error while loading shared libraries: libswift_Concurrency.so: cannot open shared object file: No such file or directory

Can you share your Dockerfile and Package.swift to help locating the problem?

@stevapple
First of all thank you I first used Vapor new to create a template project, the compilation will report the following error

#18 819.4 [935/936] Compiling Vapor Application.swift
#18 819.7 remark: Incremental compilation has been disabled: it is not compatible with whole module optimization[937/938] Compiling Fluent FluentProvider+Concurrency.swift
#18 830.6 remark: Incremental compilation has been disabled: it is not compatible with whole module optimization[939/940] Compiling App TodoController.swift
#18 850.4 remark: Incremental compilation has been disabled: it is not compatible with whole module optimization[941/942] Compiling Run main.swift
#18 871.2 error: link command failed with exit code 254 (use -v to see invocation)
#18 871.2 clang-10: error: unable to execute command: Killed
#18 871.2 clang-10: error: linker command failed due to signal (use -v to see invocation)
#18 871.9 [942/943] Linking Run
------
failed to solve: rpc error: code = Unknown desc = executor failed running [/bin/sh -c swift build -c release --static-swift-stdlib]: exit code: 1

When I remove the parameter --static-swift-stdlib it compiles successfully but doesn't run

Below is the automatically generated Dockerfile

# ================================
# Build image
# ================================
FROM swift:5.5-focal as build

# Install OS updates and, if needed, sqlite3
RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \
    && apt-get -q update \
    && apt-get -q dist-upgrade -y \
    && rm -rf /var/lib/apt/lists/*

# Set up a build area
WORKDIR /build

# First just resolve dependencies.
# This creates a cached layer that can be reused
# as long as your Package.swift/Package.resolved
# files do not change.
COPY ./Package.* ./
RUN swift package resolve

# Copy entire repo into container
COPY . .

# Build everything, with optimizations
RUN swift build -c release --static-swift-stdlib

# Switch to the staging area
WORKDIR /staging

# Copy main executable to staging area
RUN cp "$(swift build --package-path /build -c release --show-bin-path)/Run" ./

# Copy any resources from the public directory and views directory if the directories exist
# Ensure that by default, neither the directory nor any of its contents are writable.
RUN [ -d /build/Public ] && { mv /build/Public ./Public && chmod -R a-w ./Public; } || true
RUN [ -d /build/Resources ] && { mv /build/Resources ./Resources && chmod -R a-w ./Resources; } || true

# ================================
# Run image
# ================================
FROM ubuntu:focal

# Make sure all system packages are up to date.
RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true && \
    apt-get -q update && apt-get -q dist-upgrade -y && apt-get -q install -y ca-certificates && \
    rm -r /var/lib/apt/lists/*

# Create a vapor user and group with /app as its home directory
RUN useradd --user-group --create-home --system --skel /dev/null --home-dir /app vapor

# Switch to the new home directory
WORKDIR /app

# Copy built executable and any staged resources from builder
COPY --from=build --chown=vapor:vapor /staging /app

# Ensure all further commands run as the vapor user
USER vapor:vapor

# Let Docker bind to port 8080
EXPOSE 8080

# Start the Vapor service when the image is run, default to listening on 8080 in production environment
ENTRYPOINT ["./Run"]
CMD ["serve", "--env", "production", "--hostname", "0.0.0.0", "--port", "8080"]

My Package.swift

// swift-tools-version:5.5
import PackageDescription

let package = Package(
    name: "hello1",
    platforms: [
       .macOS(.v12)
    ],
    dependencies: [
        // πŸ’§ A server-side Swift web framework.
        .package(url: "https://github.com/vapor/vapor.git", from: "4.0.0"),
        .package(url: "https://github.com/vapor/fluent.git", from: "4.0.0"),
        .package(url: "https://github.com/vapor/fluent-postgres-driver.git", from: "2.0.0"),
    ],
    targets: [
        .target(
            name: "App",
            dependencies: [
                .product(name: "Fluent", package: "fluent"),
                .product(name: "FluentPostgresDriver", package: "fluent-postgres-driver"),
                .product(name: "Vapor", package: "vapor")
            ],
            swiftSettings: [
                // Enable better optimizations when building in Release configuration. Despite the use of
                // the `.unsafeFlags` construct required by SwiftPM, this flag is recommended for Release
                // builds. See <https://github.com/swift-server/guides/blob/main/docs/building.md#building-for-production> for details.
                .unsafeFlags(["-cross-module-optimization"], .when(configuration: .release))
            ]
        ),
        .executableTarget(name: "Run", dependencies: [.target(name: "App")]),
        .testTarget(name: "AppTests", dependencies: [
            .target(name: "App"),
            .product(name: "XCTVapor", package: "vapor"),
        ])
    ]
)

--static-swift-stdlib is required to statically link Swift runtime libraries, but it will consume a lot more memory. It seems your builder ran out of memory, so it killed swift-build.

If you cannot statically link Swift libraries, you would need to copy the dynamic libraries along with Run:

RUN cp "$(swift build --package-path /build -c release --show-bin-path)/Run" ./
RUN ldd Run | grep swift | awk '{print $3}' | xargs cp -Lv -t .
1 Like

@stevapple

Thanks I will try the solution you provided My current build system is running on macOS 12.2 with Xcode version 13.2.1. The maximum memory is 16G, and 11G memory has been used.

Given that you’re building inside a Docker container, you may go and check the memory settings in Docker Desktop. 8GB would be fairly enough IMO.

I'll go to the settings and try again

@stevapple

I have upgraded Docker's default 2G memory to 8G and the compilation has been completed. Thank you for helping me during your busy schedule on Sunday. Thank you very much.

@stevapple

saved my day, turned out my virtual server only had 2gb ram and was stuck with this error after updating Vapor. After upgrading to a root server with 16gb my docker images are finally building again.

thx

As an FYI 5.9 (and hopefully 5.8.1) have a much improved linker that reduces memory usage by around 90%

5 Likes

Sorry for same question.
We have the same issue in our pipeline:
OSError: libswift_Concurrency.so: cannot open shared object file:
But we also need the Python 2.7 and actually we are creating the lib package with this docker:

Blockquote

FROM ubuntu:18.04

RUN
apt-get update
&& DEBIAN_FRONTEND=noninteractive apt-get install -y
wget
make
clang
libicu-dev
libcurl4-openssl-dev
libssl-dev
tzdata
git

ENV PYTHON_VERSION 2.7.13
RUN
wget -O /tmp/python.tgz https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-${PYTHON_VERSION}.tgz
&& tar -xzf /tmp/python.tgz -C /usr/src/
&& cd /usr/src/Python-${PYTHON_VERSION}
&& ./configure --with-ensurepip
&& make
&& make install
&& cd /

ENV SWIFT_VERSION 5.9.2
RUN
wget https://swift.org/builds/swift-${SWIFT_VERSION}-release/ubuntu1804/swift-${SWIFT_VERSION}-RELEASE/swift-${SWIFT_VERSION}-RELEASE-ubuntu18.04.tar.gz
&& tar xzf swift-${SWIFT_VERSION}-RELEASE-ubuntu18.04.tar.gz
&& rm swift-${SWIFT_VERSION}-RELEASE-ubuntu18.04.tar.gz

ENV SWIFT_ROOT=/swift-${SWIFT_VERSION}-RELEASE-ubuntu18.04/usr/

WORKDIR /src/PythonBindings

vim: ts=4:sw=4:et:ft=Dockerfile

maybe someone could help how to fix it

So there are a number of issues here. Your Dockerfile does not show how you are building and running the application, if there is a multistage pipeline etc. Those would be helpful to see.

Second - there is no world in which you should need Python 2.7 - security updates for it were stopped 4 years ago and it is not maintained or supported. You should not be using it.

Next - why are you manually installing Swift instead of just using a prebuilt Docker image?

Finally Ubuntu 18.04 is EOL as well and is no longer supported. The Swift 5.10 will not run on it

1 Like

we are using the SWIFT 5.9.2
also we are using this Docker image just for pack the packege to the Library. Then Python use it library for working
Also there is the goal to create the library which will be call from the Python. It does not need to run swift. The error is appearing in the Python code when the python is calling our library

You should use swift:5.9.2-focal or preferably swift:5.9.2-jammy as a base image instead of ubuntu:18.04. Then you don't need to install Swift manually in your image at all.

ok. and what to add or remove from Docker file?

Unless you need additional dependencies or prefer to build your Swift packages within a container, there is no need to create a Dockerfile at all.

docker run --rm -it swift:5.9.2-jammy /bin/bash

will run a container with both Swift and Python installed and ready to use.

That is cool advice, but the problem that we are creating the Library from the swift Package and then use it inside Python 2.7. We do not need to run swift, we need the working compiled library. This library we are putting in the storage and the python install it with requiremetns.

As mentioned upthread, Python 2.7 contains security vulnerabilities and is no longer supported by anyone including Python Software Foundation itself. swift:5.9.2-jammy has Python 3.10.12 preinstalled, and Python 3.10 will be supported at least until October of 2026, according to the downloads page on python.org.

1 Like

You also haven't shown how you're copying the Swift code over, because judging by the errors you're missing some Swift runtime libraries

thank you all. found the solution. just added the files to the docker container. And by the way swift ia a not a standalone language. In my case it using with the legacy Python 2.7 and for me was really very important to find the solution how to use with the old python. And the advices like " forget about legacy python" sounds like the people just building their own closed world and try to live inside it. Programing language it is just a tool - not the center of the galaxy.

With legacy python2.7 the newwest 5.9.2 swift libraries are working fine on the Ubuntu 18.04 image - all you need just include the shared swift libraries inside your Docker.

Thanks again to all