Building riot/helloworld with Docker - docker

This is my setup:
docker pull riot/riotbuild
wget https://github.com/RIOT-OS/RIOT/archive/2019.04.zip
unzip 2019.04.zip
cd RIOT-2019.04/examples/hello-world/
make BUILD_IN_DOCKER=1 BOARD=stm32f4discovery all
All of this is OK.
make BUILD_IN_DOCKER=1 BOARD=stm32f4discovery flash
This step failed. Error is :
> Building application "hello-world" for "stm32f4discovery" with MCU
> "stm32f4". "make" -C /data/riotbuild/riotbase/boards/stm32f4discovery
> "make" -C /data/riotbuild/riotbase/core "make" -C
> /data/riotbuild/riotbase/cpu/stm32f4 "make" -C
> /data/riotbuild/riotbase/cpu/cortexm_common "make" -C
> /data/riotbuild/riotbase/cpu/cortexm_common/periph "make" -C
> /data/riotbuild/riotbase/cpu/stm32_common "make" -C
> /data/riotbuild/riotbase/cpu/stm32_common/periph "make" -C
> /data/riotbuild/riotbase/cpu/stm32f4/periph "make" -C
> /data/riotbuild/riotbase/drivers "make" -C
> /data/riotbuild/riotbase/drivers/periph_common "make" -C
> /data/riotbuild/riotbase/sys "make" -C
> /data/riotbuild/riotbase/sys/auto_init "make" -C
> /data/riotbuild/riotbase/sys/isrpipe "make" -C
> /data/riotbuild/riotbase/sys/newlib_syscalls_default "make" -C
> /data/riotbuild/riotbase/sys/pm_layered "make" -C
> /data/riotbuild/riotbase/sys/stdio_uart "make" -C
> /data/riotbuild/riotbase/sys/tsrb text data bss dec
> hex filename 8756 140 2620 11516 2cfc
> /data/riotbuild/riotbase/examples/hello-world/bin/stm32f4discovery/hello-world.elf
> /home/huaxing/oproj/riot/RIOT-2019.04/dist/tools/openocd/openocd.sh
> flash
> /home/huaxing/oproj/riot/RIOT-2019.04/examples/hello-world/bin/stm32f4discovery/hello-world.elf
> Flashing Target sh: 1: openocd: not found
> /home/huaxing/oproj/riot/RIOT-2019.04/examples/hello-world/../../Makefile.include:538:
> recipe for target 'flash' failed make: *** [flash] Error 127

I check the script, in fact it will finally call docker as next:
a) make BUILD_IN_DOCKER=1 BOARD=stm32f4discovery all
docker run --rm -t -u "$(id -u)" \
-v '/usr/share/zoneinfo/PRC:/etc/localtime:ro' -v '/home/shubuntu1/g/RIOT-2019.04:/data/riotbuild/riotbase' -e 'RIOTBASE=/data/riotbuild/riotbase' -e 'CCACHE_BASEDIR=/data/riotbuild/riotbase' -e 'BUILD_DIR=/data/riotbuild/riotbase/build' -e 'RIOTPROJECT=/data/riotbuild/riotbase/examples/hello-world' -e 'RIOTCPU=/data/riotbuild/riotbase/cpu' -e 'RIOTBOARD=/data/riotbuild/riotbase/boards' -e 'RIOTMAKE=/data/riotbuild/riotbase/makefiles' \
-e 'BOARD=stm32f4discovery' \
-w '/data/riotbuild/riotbase/examples/hello-world/' \
'riot/riotbuild:latest' make all 'BOARD=stm32f4discovery'
b) make BUILD_IN_DOCKER=1 BOARD=stm32f4discovery flash
docker run --rm -t -u "$(id -u)" \
-v '/usr/share/zoneinfo/PRC:/etc/localtime:ro' -v '/home/shubuntu1/g/RIOT-2019.04:/data/riotbuild/riotbase' -e 'RIOTBASE=/data/riotbuild/riotbase' -e 'CCACHE_BASEDIR=/data/riotbuild/riotbase' -e 'BUILD_DIR=/data/riotbuild/riotbase/build' -e 'RIOTPROJECT=/data/riotbuild/riotbase/examples/hello-world' -e 'RIOTCPU=/data/riotbuild/riotbase/cpu' -e 'RIOTBOARD=/data/riotbuild/riotbase/boards' -e 'RIOTMAKE=/data/riotbuild/riotbase/makefiles' \
-e 'BOARD=stm32f4discovery' \
-w '/data/riotbuild/riotbase/examples/hello-world/' \
'riot/riotbuild:latest' make 'BOARD=stm32f4discovery'
They are nearly same, and the main use for container is just to build the source to stm32 binary as it's not add any permissions to control hardware when start container.
Compare to a), the b) also have next output:
### Flashing Target ###
sh: 1: openocd: not found
/home/shubuntu1/g/RIOT-2019.04/examples/hello-world/../../Makefile.include:538: recipe for target 'flash' failed
make: *** [flash] Error 127
This in fact not related to container, it runs on host, the root cause is you do not install openocd on host which used to flash the stm32 binary to device.
See this, search OpenOCD, it clear requires you to install openocd, then after the docker container finish the build, the binary will also be in host as it's in docker volume, and finally the openocd on host could flash your binary.

Related

how to execute several commands in a running temporary container

I want to run a temporary docker and execute several command in it:
.PHONY : Test
Test:
#echo Starting Docker container
/home/pagl_home/bin/SI.docker_17cy/bin/pagl-build-env run -b '$(PRJ_BUILD_TREE)' -w '$(PRJ_WORK_DIR)' --objdir '' -c 'rm -rf build_results; \
make clean_brutal; \
$(PRJ_MISRA_CMD)/cov-build --dir build_results --encoding UTF-8 make SUB_PRODUCT=$(SUB_PRODUCT); \
$(if $(COVERITY_MISRA_2012), \
$(PRJ_test_CMD)/cov-analyze --dir build_results --disable-default --coding-standard-config /home/XX/XX-linux64-2018.06/config/coding-standards/XX/XX-all.config --paths 100000 --tu-pattern "file('.*\.c$\')"; \
$(PRJ_test_CMD)/cov-format-errors --dir build_results --html-output build_results/results/HTML_2012, );'
but I het the following error:
Illegal character in pattern: .
[ERROR] No results found.
I want to know how to run command seperately in a running container?
like:
.PHONY : Test
Test:
#echo Starting Docker container
/home/pagl_home/bin/SI.docker_17cy/bin/pagl-build-env run -b '$(PRJ_BUILD_TREE)' -w '$(PRJ_WORK_DIR)' --objdir '' -c 'rm -rf build_results; \
/home/pagl_home/bin/SI.docker_17cy/bin/pagl-build-env run -c 'make clean_brutal';
/home/pagl_home/bin/SI.docker_17cy/bin/pagl-build-env run -c '$(PRJ_MISRA_CMD)/cov-build --dir build_results --encoding UTF-8 make SUB_PRODUCT=$(SUB_PRODUCT)'
/home/pagl_home/bin/SI.docker_17cy/bin/pagl-build-env run -c '$(if $(FFFF), \
/home/pagl_home/bin/SI.docker_17cy/bin/pagl-build-env run $(PRJ_test_CMD)/cov-analyze --dir build_results --disable-default --coding-standard-config /home/XX/XX-linux64-2018.06/config/coding-standards/XX/XX-all.config --paths 100000 --tu-pattern "file('.*\.c$\')"'
/home/pagl_home/bin/SI.docker_17cy/bin/pagl-build-env run -c '$(PRJ_test_CMD)/cov-format-errors --dir build_results --html-output'build_results/results/HTML_2012, );'
I know this doesn't work but to give an idea what I want to do

Docker syntax error end of file unexpected

Hello im new in docker and im having problem to build this:
MySQL install well
PhpMyadmin instal wel...
but in apache i have this error
error:
: not foundbin/pete_install.sh: 2:
/usr/local/bin/pete_install.sh: 110: Syntax error: end of file unexpected (expecting "then")
pete_install.sh
Line 1 to 10
#!/bin/bash
FILE=/var/www/html/.installed
if [ ! -f "$FILE" ]; then
echo "#######################################"
echo "Starting WordPress Pete installation..."
echo "#######################################"
rm -rf /var/www/html/Pete4
Linea 99 to 110
FILE=/var/www/.ssh/id_rsa.pub
if [ ! -f "$FILE" ]; then
ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa
fi
chmod 600 -R /var/www/.ssh/id_rsa
chmod 600 -R /var/www/.ssh/id_rsa.pub
apachectl -DFOREGROUND
#systemctl start
#/etc/init.d/apache2 reload
echo "Loading apache..."
full file https://pastebin.com/1f5a3pJY
Most of time, the error causes because you write your script on windows, the line break on windows is \r\n, while on linux it's \n.
You should install some tools to change format, e.g.:
$ sudo apt-get update
$ sudo apt-get install -y dos2unix
$ dos2unix /usr/local/bin/pete_install.sh

how to make docker keep running in frontend and not exit so that I could see the running log output

Now I want to make a docker command run in frontend so that I could see the log output. Now I am using this command to run my docker container:
docker run -p 11110:11110 -p 11111:11111 -p 11112:11112 --name canal-server dolphinjiang/canal-server:v1.1.5
this is the Dockerfile of my project:
FROM centos:7
RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
RUN echo ZONE=\"Asia/Shanghai\" > /etc/sysconfig/clock
RUN rm -rf /etc/yum.repos.d/*.repo
COPY CentOS6-Base-163.repo /etc/yum.repos.d/
RUN yum clean all
RUN groupadd -g 2500 canal; useradd -u 2501 -g canal -d /home/canal -m canal
RUN echo canal:De#2018er | chpasswd; echo root:dockerroot | chpasswd
RUN yum -y update && yum -y install wget vi openssl.x86_64 glibc.x86_64 tar tar.x86_64 inetutils-ping net-tools telnet which file
RUN yum clean all
COPY jdk-8u291-linux-x64.tar.gz /opt
RUN tar -zvxf /opt/jdk-8u291-linux-x64.tar.gz -C /opt && \
rm -rf /opt/jdk-8u291-linux-x64.tar.gz && \
chmod -R 755 /opt/jdk1.8.0_291 && \
chown -R root:root /opt/jdk1.8.0_291
RUN echo 'export JAVA_HOME=/opt/jdk1.8.0_291' >> /etc/profile
RUN echo 'export JRE_HOME=$JAVA_HOME/jre' >> /etc/profile
RUN echo 'export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH' >> /etc/profile
RUN echo 'export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH' >> /etc/profile
RUN source /etc/profile
RUN yum install kde-l10n-Chinese -y
RUN yum install glibc-common -y
RUN localedef -c -f UTF-8 -i zh_CN zh_CN.utf8
ENV JAVA_HOME /opt/jdk1.8.0_291
ENV PATH $PATH:$JAVA_HOME/bin
ENV LANG zh_CN.UTF-8
ENV LC_ALL zh_CN.UTF-8
ADD canal-server /home/canal/
RUN chmod 755 /home/canal/bin
WORKDIR /home/canal/bin
RUN chmod 777 /home/canal/bin/restart.sh
RUN chmod 777 /home/canal/bin/startup.sh
RUN chmod 777 /home/canal/bin/stop.sh
RUN chmod 777 /home/canal/bin/config.sh
CMD /home/canal/bin/config.sh
this is the config.sh:
cat > /home/canal/conf/canal.properties <<- EOF
# register ip
canal.register.ip = ${HOSTNAME}.canal-server-discovery-svc-stable.testcanal.svc.cluster.local
# canal admin config
canal.admin.manager = canal-admin-stable:8089
canal.admin.port = 11110
canal.admin.user = admin
canal.admin.passwd = 4ACFE3202A5FF5CF467898FC58AAB1D615029441
# admin auto register
canal.admin.register.auto = true
canal.admin.register.cluster =
EOF
sh /home/canal/bin/restart.sh
and this is the restart.sh:
#!/bin/bash
args=$#
case $(uname) in
Linux)
bin_abs_path=$(readlink -f $(dirname $0))
;;
*)
bin_abs_path=$(cd $(dirname $0) ||exit ; pwd)
;;
esac
sh "$bin_abs_path"/stop.sh $args
sh "$bin_abs_path"/startup.sh $args
and this is the start.sh:
#!/bin/bash
current_path=`pwd`
case "`uname`" in
Linux)
bin_abs_path=$(readlink -f $(dirname $0))
;;
*)
bin_abs_path=`cd $(dirname $0); pwd`
;;
esac
base=${bin_abs_path}/..
canal_conf=$base/conf/canal.properties
canal_local_conf=$base/conf/canal_local.properties
logback_configurationFile=$base/conf/logback.xml
export LANG=en_US.UTF-8
export BASE=$base
if [ -f $base/bin/canal.pid ] ; then
echo "found canal.pid , Please run stop.sh first ,then startup.sh" 2>&2
exit 1
fi
if [ ! -d $base/logs/canal ] ; then
mkdir -p $base/logs/canal
fi
## set java path
if [ -z "$JAVA" ] ; then
JAVA=$(which java)
fi
ALIBABA_JAVA="/usr/alibaba/java/bin/java"
TAOBAO_JAVA="/opt/taobao/java/bin/java"
if [ -z "$JAVA" ]; then
if [ -f $ALIBABA_JAVA ] ; then
JAVA=$ALIBABA_JAVA
elif [ -f $TAOBAO_JAVA ] ; then
JAVA=$TAOBAO_JAVA
else
echo "Cannot find a Java JDK. Please set either set JAVA or put java (>=1.5) in your PATH." 2>&2
exit 1
fi
fi
case "$#"
in
0 )
;;
1 )
var=$*
if [ "$var" = "local" ]; then
canal_conf=$canal_local_conf
else
if [ -f $var ] ; then
canal_conf=$var
else
echo "THE PARAMETER IS NOT CORRECT.PLEASE CHECK AGAIN."
exit
fi
fi;;
2 )
var=$1
if [ "$var" = "local" ]; then
canal_conf=$canal_local_conf
else
if [ -f $var ] ; then
canal_conf=$var
else
if [ "$1" = "debug" ]; then
DEBUG_PORT=$2
DEBUG_SUSPEND="n"
JAVA_DEBUG_OPT="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=$DEBUG_PORT,server=y,suspend=$DEBUG_SUSPEND"
fi
fi
fi;;
* )
echo "THE PARAMETERS MUST BE TWO OR LESS.PLEASE CHECK AGAIN."
exit;;
esac
str=`file -L $JAVA | grep 64-bit`
if [ -n "$str" ]; then
JAVA_OPTS="-server -Xms2048m -Xmx3072m -Xmn1024m -XX:SurvivorRatio=2 -XX:PermSize=96m -XX:MaxPermSize=256m -Xss256k -XX:-UseAdaptiveSizePolicy -XX:MaxTenuringThreshold=15 -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:+HeapDumpOnOutOfMemoryError"
else
JAVA_OPTS="-server -Xms1024m -Xmx1024m -XX:NewSize=256m -XX:MaxNewSize=256m -XX:MaxPermSize=128m "
fi
JAVA_OPTS=" $JAVA_OPTS -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true -Dfile.encoding=UTF-8"
CANAL_OPTS="-DappName=otter-canal -Dlogback.configurationFile=$logback_configurationFile -Dcanal.conf=$canal_conf"
if [ -e $canal_conf -a -e $logback_configurationFile ]
then
for i in $base/lib/*;
do CLASSPATH=$i:"$CLASSPATH";
done
CLASSPATH="$base/conf:$CLASSPATH";
echo "cd to $bin_abs_path for workaround relative path"
cd $bin_abs_path
echo LOG CONFIGURATION : $logback_configurationFile
echo canal conf : $canal_conf
echo CLASSPATH :$CLASSPATH
$JAVA $JAVA_OPTS $JAVA_DEBUG_OPT $CANAL_OPTS -classpath .:$CLASSPATH com.alibaba.otter.canal.deployer.CanalLauncher 2>&1
echo $! > $base/bin/canal.pid
echo "cd to $current_path for continue"
cd $current_path
else
echo "canal conf("$canal_conf") OR log configration file($logback_configurationFile) is not exist,please create then first!"
fi
after I start the docker, it exit automaticlly, and the docker not startup, no log output. what should I do to make it run in frontend. after successs, switch to the backend. I also tried to run in deamon like this(make the container run background and not exit):
docker run -it -d -p 11110:11110 -p 11111:11111 -p 11112:11112 --name canal-server canal/canal-server:v1.1.5
the process still exit automaticlly. and docker container did not startup.
Basically, you should get the point (based on your latest comment).
Docker is based on some command, when it's done - it stops the container.
So to make it continuously running you should have command and run infinitely.
Also check this answer as well, there are more explanation
Why docker exiting with code 0
One of the easiest solution is to tail some logs.
Like,
tail -f /dev/null
Taken from here
you can use tail -f /dev/null to keep the container from stopping, try this
docker run -it -d -p 11110:11110 -p 11111:11111 -p 11112:11112 --name canal-server canal/canal-server:v1.1.5 tail -f /dev/null
see also this post

How to workaround "the input device is not a TTY" when using grunt-shell to invoke a script that calls docker run?

When issuing grunt shell:test, I'm getting warning "the input device is not a TTY" & don't want to have to use -f:
$ grunt shell:test
Running "shell:test" (shell) task
the input device is not a TTY
Warning: Command failed: /bin/sh -c ./run.sh npm test
the input device is not a TTY
Use --force to continue.
Aborted due to warnings.
Here's the Gruntfile.js command:
shell: {
test: {
command: './run.sh npm test'
}
Here's run.sh:
#!/bin/sh
# should use the latest available image to validate, but not LATEST
if [ -f .env ]; then
RUN_ENV_FILE='--env-file .env'
fi
docker run $RUN_ENV_FILE -it --rm --user node -v "$PWD":/app -w /app yaktor/node:0.39.0 $#
Here's the relevant package.json scripts with command test:
"scripts": {
"test": "mocha --color=true -R spec test/*.test.js && npm run lint"
}
How can I get grunt to make docker happy with a TTY? Executing ./run.sh npm test outside of grunt works fine:
$ ./run.sh npm test
> yaktor#0.59.2-pre.0 test /app
> mocha --color=true -R spec test/*.test.js && npm run lint
[snip]
105 passing (3s)
> yaktor#0.59.2-pre.0 lint /app
> standard --verbose
Remove the -t from the docker run command:
docker run $RUN_ENV_FILE -i --rm --user node -v "$PWD":/app -w /app yaktor/node:0.39.0 $#
The -t tells docker to configure the tty, which won't work if you don't have a tty and try to attach to the container (default when you don't do a -d).
This solved an annoying issue for me. The script had these lines:
docker exec **-it** $( docker ps | grep mysql | cut -d' ' -f1) mysql --user= ..... > /var/tmp/temp.file
mutt -s "File is here" someone#somewhere.com < /var/tmp/temp.file
The script would run great if run directly and the mail would come with the correct output. However, when run from cron, (crontab -e) the mail would come with no content. Tried many things around permissions and shells and paths etc. However no joy!
Finally found this:
*/20 * * * * scriptblah.sh > $HOME/cron.log 2>&1
And on that cron.log file found this output:
the input device is not a TTY
Search led me here. And after I removed the -t, it's working great now!
docker exec **-i** $( docker ps | grep mysql | cut -d' ' -f1) mysql --user= ..... > /var/tmp/temp.file

SMO: No model built yet

I am able to create a model in MOA(Weka) for case 1 but not for "case 2" (same data set). Could anyone explain why?
Case 1 (IBk/LWL):
java -cp moa.jar:weka.jar -javaagent:sizeofag.jar moa.DoTask "LearnModel -l (meta.WEKAClassifier -l (weka.classifiers.lazy.IBk)) -s (ArffFileStream -f training_s2w.arff -c 1) -O model.moa"
java -cp moa.jar:weka.jar -javaagent:sizeofag.jar moa.DoTask "EvaluateModel -m file:model.moa -s (ArffFileStream -f test_s2w.arff -c 1) -o predicted.txt"
Above two commands creates a model and apply it on test data successfully.
Case 2 (SMO/J48/NaiveBayes/BayesNet):
java -cp moa.jar:weka.jar -javaagent:sizeofag.jar moa.DoTask "LearnModel -l (meta.WEKAClassifier -l (weka.classifiers.functions.SMO)) -s (ArffFileStream -f training_s2w.arff -c 1) -O model.moa"
java -cp moa.jar:weka.jar -javaagent:sizeofag.jar moa.DoTask "EvaluateModel -m file:model.moa -s (ArffFileStream -f test_s2w.arff -c 1) -o predicted.txt"
But these two commands gives output as:
"Model description:
SMO: No model built yet"
(I checked through Weka CLI that both training and test data is Weka compatible.)
What could be the possible reason(s)?

Resources