i am trying to move my current Kitura Dev setup into a real running environment by first moving it into a Docker Container to later migrate it to a Cloud Provider.
However while trying to build my Docker Setup for Kitura i run into problems i did not find any proper solution how to fix these.
I am Building my docker Container from The instructions from this page https://www.kitura.io/docs/deploying/docker.html
But i am also using SwiftKuery with MySQL in the package.
My Docker Tools file looks like the following
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
I get the following error
[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
^
after using this commands
docker build -t myapp-build -f Dockerfile-tools .
The First one still works
docker run -v $PWD:/swift-project -w /swift-project myapp-build /swift-utils/tools-utils.sh build release
Error Appears while Building the Container
Any one has an idea what i could do to fix this issue ... ?
UPDATE:
I tried one provided suggestion to add a .swift-build-linux file with one entry
swift build -Xcc -I/usr/include/mysql/
Into the source files of my project .
up on running the command:
docker run -v $PWD:/swift-project -w /swift-project myapp-build /swift-utils/tools-utils.sh build release
It seems to pick it up as you can see below... but still i run into the same issue :(
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
^
UPDATE :
It seems to work after i added this line in my Dockerfile-tools . :
RUN apt-get update && apt-get install -y sudo libmysqlclient-dev
... but now i get a new error i first have to investigate ...
[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)
UPDATE - Resolution:
Ok i added the entry
swift build -Xcc -I/usr/include/mysql/
to the new created .swift-build-linux file in the root directory in my project. (previously i had a small spelling mistake in the line).
Now i was able to pass this step of the Dockerisation process ... :)
UPDATE - NEW Problem:
Hello Together, i was running in a new problem related to the tutorial and this is to run the conatainer after building it: As i assume it is a different topic, i have raised a new question: Run Kitura Docker Image causes libmysqlclient.so.18 Error
its is that up on running the container, i get an error message:
error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
Thanks a lot for the Help !
The problem here is that the ibmcom/swift-ubuntu:5.0.2
image is built on top of Ubuntu 14.04. The version of libmysqlclient-dev
supplied with 14.04 does not include the pkg-config information that allows the Swift compiler to find the headers without help.
There are two solutions to this problem:
1: You could add -Xcc -I/usr/include/mysql/
arguments to the swift build
command. Either:
swift build -Xcc -I/usr/include/mysql/
, or tools-utils.sh
script, you can create a file in your project called .swift-build-linux
which contains a single line: swift build -Xcc -I/usr/include/mysql/
- this will be picked up by the tools-utils.sh
script when it runs the build.2: You can replace your base images with FROM swift:5.0.2
(for the build image) and FROM swift:5.0.2-slim
(for the run image) - these are the official Swift-maintained images which are based on Ubuntu 18.04, and as of the Swift 5.0.2 release, provide a 'slim' image similar to ibmcom's 'runtime' image.
libssl-dev
or libcurl4-openssl-dev
dependencies, so you will need to include those in your Dockerfile-tools
.