SwiftPM Package building target in docker - swift

Im trying to setup an external library in a SwiftPM Package project. This package (Mockingbird) is only used from within my test target, and therefor my main application target does not depend on this.
On my MacOS host machine, building and executing this test target works perfectly fine. No errors whatsoever.
However, i'm also building this application within a dockerized container within a CI process. Im using the official swift docker images (swift 5.5) for this.
From within this docker container, building the main target itself works fine, because it does not depends on the Mockingbird lib. But building the test target fails when compiling mockingbird.
When starting this Docker container, i always clean the build folder and resolve the packages first before building the targets.
This is the error im getting:
In file included from /app/.build/checkouts/mockingbird/Sources/MockingbirdFramework/Objective-C/Bridge/sources/MKBTypeFacade.m:1:
/app/.build/checkouts/mockingbird/Sources/MockingbirdFramework/Objective-C/Bridge/sources/../include/MKBTypeFacade.h:1:9: fatal error: 'Foundation/Foundation.h' file not found
#import <Foundation/Foundation.h>
^~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /app/.build/checkouts/mockingbird/Sources/MockingbirdFramework/Objective-C/Bridge/sources/MKBTestExpectation.m:1:
/app/.build/checkouts/mockingbird/Sources/MockingbirdFramework/Objective-C/Bridge/sources/../include/MKBTestExpectation.h:1:9: fatal error: 'XCTest/XCTest.h' file not found
#import <XCTest/XCTest.h>
^~~~~~~~~~~~~~~~~
/app/.build/checkouts/mockingbird/Sources/MockingbirdFramework/Objective-C/Bridge/sources/MKBTestUtils.m:1:
/app/.build/checkouts/mockingbird/Sources/MockingbirdFramework/Objective-C/Bridge/sources/../include/MKBTestUtils.h:1:9: fatal error: 'Foundation/Foundation.h' file not found
#import <Foundation/Foundation.h>
^~~~~~~~~~~~~~~~~~~~~~~~~
/app/.build/checkouts/mockingbird/Sources/MockingbirdFramework/Objective-C/Bridge/sources/MKBMocking.m:1:
/app/.build/checkouts/mockingbird/Sources/MockingbirdFramework/Objective-C/Bridge/sources/../include/MKBMocking.h:1:9: fatal error: 'Foundation/Foundation.h' file not found
#import <Foundation/Foundation.h>
Maybe im missing out on something?
Thanks in advance!
Edit 1: Added dockerfile
FROM swift:5.6.2-focal
WORKDIR /app
RUN apt-get update \
&& apt-get install openssh-client lcov -y
ARG INSTALL_COMMANDS="echo \"No custom install commands provided, proceeding\""
RUN ${INSTALL_COMMANDS}
ARG GITLAB_SSH_PRIVATE_KEY
RUN mkdir -p ~/.ssh \
&& echo "${GITLAB_SSH_PRIVATE_KEY}" > ~/.ssh/id_rsa \
&& chmod 0600 ~/.ssh/id_rsa \
&& eval "$(ssh-agent -s)" \
&& ssh-add ~/.ssh/id_rsa \
&& ssh-keyscan ${GIT_URL} > ~/.ssh/known_hosts
## Copy entire repo into container
COPY ./Package.* ./
RUN swift package resolve
COPY . .
## Remove SSH keys
RUN rm -rf /root/.ssh/
After my image was created containing the source files, i run it like:
docker run ${IMAGE_NAME} \
/bin/sh -c "swift build --target AppTests"

Related

Dockerfile postgres install extention pg_stat_monitor

I want to install pg_stat_monitor extension in Dockerfile. I found this article https://pgxn.org/dist/pg_stat_monitor/. Prepared this step in the Dockerfile
RUN git clone https://github.com/percona/pg_stat_monitor \
&& cd /build/pg_stat_monitor \
&& make USE_PGXS=1 \
&& make USE_PGXS=1 install
No, I get this error
---> Running in baece8df47d0
fetch https://dl-cdn.alpinelinux.org/alpine/v3.15/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.15/community/x86_64/APKINDEX.tar.gz
ERROR: unable to select packages:
clone (no such package):
required by: .fetch-deps-20220504.193645[clone]
https://github.com/percona/pg_stat_monitor (no such package):
required by: .fetch-deps-20220504.193645[https://github.com/percona/pg_stat_monitor]
Could you please help me install this extension inside the docker container. Thanks.

Building postgres from source throws "'utils/errcodes.h' file not found" when called from other makefile

I am currently constructing a Makefile and one of the things it will be doing is downloading and building postgres from source. Before starting to write the makefile file I always used the following set of commands to do this:
curl -LJ https://github.com/postgres/postgres/archive/refs/tags/REL_13_3.zip -o postgres.zip
unzip postgres.zip
rm postgres.zip
cd postgres-REL_13_3
./configure --prefix "`pwd`" --without-readline --without-zlib
make
make install
Executing the above listed commands in the terminal results in the successful installation of postgres. Then I translated these into a makefile which looks as follows:
build:
curl -LJ https://github.com/postgres/postgres/archive/refs/tags/REL_13_3.zip -o postgres.zip
unzip postgres.zip
rm postgres.zip
cd postgres-REL_13_3 \
&& ./configure --prefix "`pwd`" --without-readline --without-zlib \
&& $(MAKE) \
&& $(MAKE) install
Running this Makefile results in the error:
../../src/include/utils/elog.h:71:10: fatal error: 'utils/errcodes.h' file not found
It seems that something about calling the make from another Makefile causes a referencing issue with the files during the build process, but I just can figure out for the life of me what I have to change to fix this.
It appears to be the influence of Makefile enviromental variables. I didn't discover the exact mechanism, but unsetting them helps.
build:
curl -LJ https://github.com/postgres/postgres/archive/refs/tags/REL_13_3.zip -o postgres.zip
unzip postgres.zip
rm postgres.zip
unset MAKELEVEL && unset MAKEFLAGS && unset MFLAGS && cd postgres-REL_13_3 \
&& ./configure --prefix "`pwd`" --without-readline --without-zlib \
&& $(MAKE) \
&& $(MAKE) install

Run Kitura Docker Image causes libmysqlclient.so.18 Error

after i had some previous problem to Dockerise my MySQL Kitura SETUP here : Docker Build Kitura Sqift Container - Shim.h mysql.h file not found
I am running in a new Problem i can not solve following the Guide from : https://www.kitura.io/docs/deploying/docker.html .
After i followed all the steps and also did the fixing on the MySQL issue previously i was now able to run the following command :
docker run -p 8080:8080 -it myapp-run
THis however leads to the following issue :
error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
i assume something tries again to open the libmysqclclient from some wrong Environmental Directories ?
But how can i fix this issues by building the docker images ... is there any way and better a smart way ?
Thanks a lot again for the help.
I was able to update and enhance my dockerfile this is now running smoothly and also can be used for CI and CD tasks.
FROM ibmcom/swift-ubuntu-runtime:latest
##FROM ibmcom/swift-ubuntu-runtime:5.0.1
LABEL maintainer="IBM Swift Engineering at IBM Cloud"
LABEL Description="Template Dockerfile that extends the ibmcom/swift-ubuntu-runtime image."
# We can replace this port with what the user wants
EXPOSE 8080
# 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 libmysqlclient-dev
# Add utils files
ADD https://raw.githubusercontent.com/IBM-Swift/swift-ubuntu-docker/master/utils/run-utils.sh /swift-utils/run-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
# Bundle application source & binaries
COPY ./.build /swift-project/.build
# Command to start Swift application
CMD [ "sh", "-c", "cd /swift-project && .build/release/Beautylivery_Server_New" ]

Add plpython3 Extension to Postgres/timescaledb Alpine Docker Image

I try to add the plpython3 extension to my timescaledb/postgres (based on linux alpine) image:
FROM timescale/timescaledb:0.9.0-pg10
RUN set -ex \
&& apk add --no-cache --virtual .plpython3-deps --repository http://nl.alpinelinux.org/alpine/edge/testing \
postgresql-plpython3
When I try to create the extension I get the following error:
postgres=# CREATE EXTENSION plpython3u;
ERROR: could not open extension control file "/usr/local/share/postgresql/extension/plpython3u.control": No such file or directory
But when I search for the files inside my container I can find them within a different directory:
/ # find / -name '*plpy*'
/usr/lib/postgresql/plpython3.so
/usr/share/postgresql/extension/plpython3u.control
/usr/share/postgresql/extension/plpython3u--1.0.sql
/usr/share/postgresql/extension/plpython3u--unpackaged--1.0.sql
How can I install postgresql-plpython3 to a different directory or configure postgres to recognize my added extension?
Update
When I just mv the files to /usr/local/share/postgresql/extension I get the error:
postgres=# CREATE EXTENSION plpython3u;
ERROR: could not access file "$libdir/plpython3": No such file or directory
Update 2
So the issue with $libdir was that pg_config --pkglibdir points to /usr/local/lib/postgresql but plpython3.so is inside /usr/lib/postgresql. When I move everything to the according /usr/local directories I can successfully create the extension.
This leads to the question where I hope to find an answer. How can I install postgresql-plpython3 to /usr/local/... instead of /usr/...?
I am fairly certain that if you use prebuilt packages you are stuck with hardcoded installation paths.
The easiest way around your problem is to create symlinks after installation:
FROM timescale/timescaledb:0.9.0-pg10
RUN set -ex \
&& apk add --no-cache --virtual .plpython3-deps --repository http://nl.alpinelinux.org/alpine/edge/testing \
postgresql-plpython3 \
&& ln -s /usr/lib/postgresql/plpython3.so /usr/local/lib/postgresql/plpython3.so \
&& ln -s /usr/share/postgresql/extension/plpython3u.control /usr/local/share/postgresql/extension/plpython3u.control \
&& ln -s /usr/share/postgresql/extension/plpython3u--1.0.sql /usr/local/share/postgresql/extension/plpython3u--1.0.sql \
&& ln -s /usr/share/postgresql/extension/plpython3u--unpackaged--1.0.sql /usr/local/share/postgresql/extension/plpython3u--unpackaged--1.0.sql

How to install Grafana on Mac

I tied the following steps
cd $GOPATH/src/github.com/grafana/grafana
go run build.go setup
I got the following
Version: 2.5.0-pre1, Linux Version: 2.5.0, Package Iteration: pre1
go get -v github.com/tools/godep
github.com/tools/godep (download)
github.com/tools/godep/Godeps/_workspace/src/github.com/kr/fs
github.com/tools/godep/Godeps/_workspace/src/github.com/pmezard/go-difflib/difflib
github.com/tools/godep/Godeps/_workspace/src/golang.org/x/tools/go/vcs
github.com/tools/godep
go get -v github.com/blang/semver
github.com/blang/semver (download)
github.com/blang/semver
go get -v github.com/mattn/go-sqlite3
go install -v github.com/mattn/go-sqlite3
then i executed
$GOPATH/bin/godep restore
i got no putput but command got executed
then i ran the command
go run build.go build
Version: 2.5.0-pre1, Linux Version: 2.5.0, Package Iteration: pre1
rm -r bin
rm -r Godeps/_workspace/pkg
rm -r Godeps/_workspace/bin
rm -r dist
rm -r tmp
rm -r /Users/skhare/sk/go/pkg/darwin_amd64/github.com/grafana
rm -r ./bin/grafana-server
rm -r ./bin/grafana-server.md5
GOPATH=/Users/skhare/sk/go/src/github.com/grafana/grafana/Godeps/_workspace:/Users/skhare/sk/go
go build -ldflags -w -X main.version '2.5.0-pre1' -X main.commit 'v2.1.2+394- gfb767f5' -X main.buildstamp 1442671169 -o ./bin/grafana-server .
# github.com/grafana/grafana
link: warning: option -X main.version 2.5.0-pre1 may not work in future releases; use -X main.version=2.5.0-pre1
link: warning: option -X main.commit v2.1.2+394-gfb767f5 may not work in future releases; use -X main.commit=v2.1.2+394-gfb767f5
link: warning: option -X main.buildstamp 1442671169 may not work in future releases; use -X main.buildstamp=1442671169
then i executed
npm install
i had to install npm
>npm install -g grunt-cli
/usr/local/bin/grunt -> /usr/local/lib/node_modules/grunt-cli/bin/grunt
grunt-cli#0.1.13 /usr/local/lib/node_modules/grunt-cli
├── resolve#0.3.1
├── nopt#1.0.10 (abbrev#1.0.7)
└── findup-sync#0.1.3 (lodash#2.4.2, glob#3.2.11)
>grunt
Running "jscs:src" (jscs) task
>> 156 files without code style errors.
Running "jshint:source" (jshint) task
✔ No problems
Running "jshint:tests" (jshint) task
✔ No problems
Running "tslint:source" (tslint) task
>> 11 files lint free.
Running "clean:gen" (clean) task
Cleaning public_gen...OK
Running "copy:public_to_gen" (copy) task
Created 122 directories, copied 553 files
Running "less:src" (less) task
File public_gen/css/bootstrap.dark.min.css created.
File public_gen/css/bootstrap.light.min.css created.
File public_gen/css/bootstrap-responsive.min.css created.
Running "concat:cssDark" (concat) task
File public_gen/css/grafana.dark.min.css created.
Running "concat:cssLight" (concat) task
File public_gen/css/grafana.light.min.css created.
Running "typescript:build" (typescript) task
42 files created. js: 14 files, map: 14 files, declaration: 14 files (968ms)
Done, without errors.
>go get github.com/Unknwon/bra
the above command did not give any output, nor an error message
bra run
it says -bash: bra: command not found
i tried to look for the resolution, but i could not find it. Please help
Recompile backend on source change
To rebuild on source change (requires that you executed godep restore)
go get github.com/Unknwon/bra
bra run
Running Grafana Locally
You can run a local instance of Grafana by running:
./bin/grafana-server
You must have missed this step!
go get github.com/Unknwon/bra
You can install Grafana using home brew.
brew update
brew install grafana
This sounds like an issue where Go is just being installed to build something else (for me, it was Grafana). In which case $GOPATH/bin is not in your PATH. $GOPATH/bin/bra should work. It did for me.
I suggest you installing Grafana inside Docker. If you install Docker for Mac, the GUI (Kitematic) will allow you to install grafana as easily as one click. You will just need to create a new container with "+ New" button, search grafana through the exisiting image lists and click "Create"
Docker will download grafana and it will appear in the left sidebar: