1

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

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

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

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

我的 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 文件。(以前我在该行中有一个小的拼写错误)。

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

更新 - 新问题:

大家好,我遇到了一个与教程相关的新问题,这是在构建容器后运行容器:我认为这是一个不同的主题,我提出了一个新问题: 运行 Kitura Docker Image 导致 libmysqlclient.so。 18 错误

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

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

非常感谢您的帮助 !

4

1 回答 1

1

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

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

1:您可以在命令中添加-Xcc -I/usr/include/mysql/参数。swift build任何一个:

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

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

  • 请注意,这些图像不捆绑libssl-devorlibcurl4-openssl-dev依赖项,因此您需要将它们包含在您的Dockerfile-tools.
于 2019-08-14T09:04:01.390 回答