gpt4 book ai didi

docker - Docker Build Kitura Sqift容器-找不到Shim.h mysql.h文件

转载 作者:行者123 更新时间:2023-12-02 19:24:19 26 4
gpt4 key购买 nike

我试图通过先将其当前的Kitura Dev设置移至实际运行的环境中,方法是先将其移至Docker容器中,然后再将其迁移至Cloud Provider。

但是,在尝试为Kitura构建我的Docker安装程序时,遇到了问题,但我没有找到任何适当的解决方案来解决这些问题。

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

但我也在软件包中将SwiftKuery与MySQL一起使用。

我的Docker Tools文件如下所示

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流程的这一步... :)

更新-新问题:

大家好,我遇到了一个与教程相关的新问题,这是在构建容器之后运行容器:由于我认为这是一个不同的主题,所以我提出了一个新问题:
Run Kitura Docker Image causes libmysqlclient.so.18 Error

它是在运行容器上,我收到一条错误消息:
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版本不包含pkg-config信息,该信息使Swift编译器无需帮助即可查找 header 。

有两种方法可以解决此问题:

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脚本拾取。

  • 2:您可以将基础镜像替换为 FROM swift:5.0.2(用于构建镜像)和 FROM swift:5.0.2-slim(用于运行镜像)-这些是基于Ubuntu 18.04的正式Swift维护镜像,从Swift 5.0.2版本开始,提供类似于ibmcom的“运行时”图像的“ slim ”图像。
  • 请注意,这些图像不 bundle libssl-devlibcurl4-openssl-dev依赖项,因此您需要在Dockerfile-tools中包括它们。
  • 关于docker - Docker Build Kitura Sqift容器-找不到Shim.h mysql.h文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57486811/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com