Docker 构建 Kitura Sqift 容器 - Shim.h mysql.h 找不到文件

Docker Build Kitura Sqift Container - Shim.h mysql.h file not found

我正在尝试将我当前的 Kitura Dev 设置移动到真实的 运行ning 环境中,方法是先将其移动到 Docker 容器中,然后再将其迁移到云提供商。

然而,在尝试为 Kitura 构建我的 Docker 设置时,我 运行 遇到了问题,我没有找到任何合适的解决方案来解决这些问题。

我正在根据此页面的说明构建我的 docker 容器 https://www.kitura.io/docs/deploying/docker.html

但我也在包中使用 MySQL 的 SwiftKuery。

我的 Docker 工具文件如下所示

FROM ibmcom/swift-ubuntu:5.0.2
##FROM swift:5.0.2

LABEL maintainer="IBM Swift Engineering at IBM Cloud"
LABEL Description="Template Dockerfile that extends the ibmcom/swift-ubuntu image."

# We can replace this port with what the user wants
EXPOSE 8080 1024 1025

# Default user if not provided
ARG bx_dev_user=root
ARG bx_dev_userid=1000

# Install system level packages
RUN apt-get update && apt-get dist-upgrade -y
##RUN apt-get update && apt-get install -y sudo libcurl4-openssl-dev openssl libssl-dev pkg-config libmysqlclient-dev

# Add utils files
ADD https://raw.githubusercontent.com/IBM-Swift/swift-ubuntu-docker/master/utils/tools-utils.sh /swift-utils/tools-utils.sh
ADD https://raw.githubusercontent.com/IBM-Swift/swift-ubuntu-docker/master/utils/common-utils.sh /swift-utils/common-utils.sh
RUN chmod -R 555 /swift-utils

# Create user if not root
RUN if [ "$bx_dev_user" != root ]; then useradd -ms /bin/bash -u $bx_dev_userid $bx_dev_user; fi

# Make password not required for sudo.
# This is necessary to run 'tools-utils.sh debug' script when executed from an interactive shell.
# This will not affect the deploy container.
RUN echo "$bx_dev_user ALL=NOPASSWD: ALL" > /etc/sudoers.d/user && \
    chmod 0440 /etc/sudoers.d/user

#Install some further SSL related flaws
##RUN  find / -name libssl.so.1.1 -type f -print

# Bundle application source & binaries
COPY . /swift-project

我收到以下错误

[5/24] Compiling Swift Module 'SwiftKueryMySQL' (3 sources)
[6/24] Compiling Swift Module 'KituraContracts' (9 sources)
<module-includes>:1:10: note: in file included from <module-includes>:1:
#include "shim.h"
         ^
/swift-project/.build-ubuntu/checkouts/SwiftKueryMySQL/Sources/CMySQL/shim.h:3:10: error: 'mysql.h' file not found
#include <mysql.h>
         ^
/swift-project/.build-ubuntu/checkouts/SwiftKueryMySQL/Sources/SwiftKueryMySQL/MySQLConnection.swift:21:8: error: could not build C module 'CMySQL'
import CMySQL
       ^

使用此命令后

docker build -t myapp-build -f Dockerfile-tools .

第一个仍然有效

docker run -v $PWD:/swift-project -w /swift-project myapp-build /swift-utils/tools-utils.sh build release

构建容器时出现错误

任何人都知道我可以做些什么来解决这个问题......?

更新:

我尝试了一个提供的建议来添加一个 .swift-build-linux 文件 有一个条目

swift build -Xcc -I/usr/include/mysql/

进入我项目的源文件。

使用 运行 命令:

docker run -v $PWD:/swift-project -w /swift-project myapp-build /swift-utils/tools-utils.sh build release

它似乎可以拾起它,如下所示...但我仍然 运行 遇到同样的问题 :(

Current folder: /swift-project
Command: build
Build configuration: release
Build folder: /swift-project/.build-ubuntu
Compiling the project...
Build configuration: release
Custom build command: swift build -Xcc -I/usr/include/mysql/££
warning: you may be able to install mysqlclient using your system-packager:
     apt-get install libmysqlclient-dev

[1/27] Compiling agentcore ibmras/common/Logger.cpp
[2/27] Compiling agentcore ibmras/common/MemoryManager.cpp
[3/27] Compiling agentcore ibmras/common/Properties.cpp
[4/27] Compiling agentcore ibmras/common/LogManager.cpp
[5/26] Compiling Swift Module 'SwiftKueryMySQL' (3 sources)
[6/26] Compiling Swift Module 'KituraContracts' (9 sources)
[7/26] Compiling Swift Module 'CloudFoundryEnv' (6 sources)
[8/26] Compiling CHTTPParser utils.c
[9/26] Linking ./.build-ubuntu/x86_64-unknown-linux/release/libagentcore.so
[10/26] Compiling CHTTPParser http_parser.c
<module-includes>:1:10: note: in file included from <module-includes>:1:
#include "shim.h"
         ^
/swift-project/.build-ubuntu/checkouts/SwiftKueryMySQL/Sources/CMySQL/shim.h:3:10: error: 'mysql.h' file not found
#include <mysql.h>
         ^
/swift-project/.build-ubuntu/checkouts/SwiftKueryMySQL/Sources/SwiftKueryMySQL/MySQLConnection.swift:21:8: error: could not build C module 'CMySQL'
import CMySQL
       ^
Kais-MacBook-Pro:beautylivery_server_mqsql kaibaier$ docker run -v $PWD:/swift-project -w /swift-project myapp-build /swift-utils/tools-utils.sh build release
Current folder: /swift-project
Command: build
Build configuration: release
Build folder: /swift-project/.build-ubuntu
Compiling the project...
Build configuration: release
Custom build command: swift build -Xcc -I/usr/include/mysql/
warning: you may be able to install mysqlclient using your system-packager:
     apt-get install libmysqlclient-dev

[1/33] Compiling CHTTPParser http_parser.c
[2/39] Compiling CHTTPParser utils.c
[3/65] Compiling Swift Module 'TypeDecoder' (2 sources)
[4/65] Compiling Swift Module 'Socket' (3 sources)
[5/65] Compiling Swift Module 'Signals' (1 sources)
[6/65] Compiling Swift Module 'Logging' (3 sources)
[7/65] Compiling Swift Module 'KituraTemplateEngine' (1 sources)
[8/65] Compiling Swift Module 'Cryptor' (11 sources)
[9/65] Compiling memplugin MemoryPlugin.cpp
[10/65] Compiling Swift Module 'LoggerAPI' (1 sources)
[11/65] Compiling hcapiplugin APIConnector.cpp
[12/65] Linking ./.build-ubuntu/x86_64-unknown-linux/release/libmemplugin.so
[13/65] Compiling envplugin envplugin.cpp
[14/65] Linking ./.build-ubuntu/x86_64-unknown-linux/release/libhcapiplugin.so
[15/65] Compiling cpuplugin cpuplugin.cpp
[16/65] Compiling Swift Module 'SwiftKuery' (49 sources)
[17/65] Compiling Swift Module 'KituraContracts' (9 sources)
[18/65] Compiling Swift Module 'HeliumLogger' (2 sources)
[19/65] Compiling Swift Module 'SSLService' (2 sources)
[20/65] Compiling Swift Module 'Health' (3 sources)
[21/65] Compiling Swift Module 'FileKit' (1 sources)
[22/65] Compiling Swift Module 'Configuration' (5 sources)
[23/65] Compiling agentcore ibmras/monitoring/connector/configuration/ConfigurationConnector.cpp
[24/65] Linking ./.build-ubuntu/x86_64-unknown-linux/release/libenvplugin.so
[25/65] Linking ./.build-ubuntu/x86_64-unknown-linux/release/libcpuplugin.so
[26/65] Compiling agentcore ibmras/monitoring/connector/ConnectorManager.cpp
[27/65] Compiling agentcore ibmras/monitoring/agent/threads/WorkerThread.cpp
[28/65] Compiling agentcore ibmras/monitoring/agent/threads/ThreadPool.cpp
[29/65] Compiling agentcore ibmras/monitoring/agent/SystemReceiver.cpp
[30/65] Compiling agentcore ibmras/monitoring/agent/BucketList.cpp
[31/65] Compiling agentcore ibmras/monitoring/agent/Bucket.cpp
[32/65] Compiling Swift Module 'CloudFoundryEnv' (6 sources)
[33/65] Compiling agentcore ibmras/monitoring/agent/Agent.cpp
[34/65] Compiling agentcore ibmras/monitoring/Plugin.cpp
[35/65] Compiling agentcore ibmras/common/util/sysUtils.cpp
[36/65] Compiling agentcore ibmras/common/util/strUtils.cpp
[37/65] Compiling agentcore ibmras/common/util/LibraryUtils.cpp
[38/65] Compiling agentcore ibmras/common/util/FileUtils.cpp
[39/65] Compiling agentcore ibmras/common/port/linux/Thread.cpp
[40/65] Compiling Swift Module 'SwiftKueryMySQL' (3 sources)
[41/65] Compiling agentcore ibmras/common/port/linux/Process.cpp
[42/65] Compiling agentcore ibmras/common/port/ThreadData.cpp
<module-includes>:1:10: note: in file included from <module-includes>:1:
#include "shim.h"
         ^
/swift-project/.build-ubuntu/checkouts/SwiftKueryMySQL/Sources/CMySQL/shim.h:3:10: error: 'mysql.h' file not found
#include <mysql.h>
         ^
/swift-project/.build-ubuntu/checkouts/SwiftKueryMySQL/Sources/SwiftKueryMySQL/MySQLConnection.swift:21:8: error: could not build C module 'CMySQL'
import CMySQL
       ^

更新:

在我的 Dockerfile-tools 中添加此行后,它似乎起作用了。 :

RUN apt-get update && apt-get install -y sudo libmysqlclient-dev 

...但现在我收到一个新错误,我首先必须调查...

[19/20] Compiling Swift Module 'Beautylivery_Server_New' (1 sources) [20/20] Linking ./.build-ubuntu/x86_64-unknown-linux/release/Beautylivery_Server_New clang-7: error: unable to execute command: Bus error clang-7: error: linker command failed due to signal (use -v to see invocation) <unknown>:0: error: link command failed with exit code 254 (use -v to see invocation)

更新 - 决议:

好的,我添加了条目

swift build -Xcc -I/usr/include/mysql/

到我项目根目录中新创建的 .swift-build-linux 文件。 (以前我在该行中有一个小的拼写错误)。

现在我能够通过 Docker 化过程的这一步 ... :)

更新 - 新问题:

大家好,我 运行 遇到了一个与教程相关的新问题,这是 运行 构建容器后的问题:因为我认为这是一个不同的主题,我有提出了一个新问题:

它是在 运行 容器上,我收到一条错误消息:

error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory

非常感谢您的帮助!

这里的问题是 ibmcom/swift-ubuntu:5.0.2 映像是在 Ubuntu 14.04 之上构建的。 14.04 提供的 libmysqlclient-dev 版本不包含允许 Swift 编译器在没有帮助的情况下找到 headers 的 pkg-config 信息。

这个问题有两种解决方法:

1:您可以向 swift build 命令添加 -Xcc -I/usr/include/mysql/ 个参数。或者:

  • 将您在构建容器中执行的命令替换为 swift build -Xcc -I/usr/include/mysql/
  • 如果您想继续使用 tools-utils.sh 脚本,您可以在项目中创建一个名为 .swift-build-linux 的文件,其中包含一行:swift build -Xcc -I/usr/include/mysql/ - 这将是tools-utils.sh 脚本在构建 运行 时被拾取。

2:您可以用 FROM swift:5.0.2(对于构建映像)和 FROM swift:5.0.2-slim(对于 运行 映像)替换您的基础映像 - 这些是官方的 Swift-maintained 基于 Ubuntu 18.04 的图像,从 Swift 5.0.2 版本开始,提供类似于 ibmcom 的 'runtime' 图像的 'slim' 图像。

  • 请注意,这些图像不捆绑 libssl-devlibcurl4-openssl-dev 依赖项,因此您需要将它们包含在 Dockerfile-tools.