设为首页 收藏本站
查看: 1900|回复: 0

[经验分享] Infer工具Docker image发布

[复制链接]

尚未签到

发表于 2015-10-13 11:19:48 | 显示全部楼层 |阅读模式
制作该Image的目的
  由于Infer工具刚刚推出来,很多人想试用该工具,但是又苦于环境的配置略显复杂,最近有很多人找我解决关于环境配置的问题,这阻碍了Infer的推广。而Docker技术具有易移植的特性,将该工具的环境制作成Image,你只需下载在到本地就可以体验该新工具的特性,就可以对其做一个简单的了解。
  注意:OC和iOS项目的分析是不支持的
Dockerfile
  我并没有利用Dockerfile来制作该Image,但是我将我制作的Dockerfile贴出来,方便大家了解我的制作过程:


# Base image
FROM heikomaass/android-sdk
# Author
MAINTAINER doctorq <542113578@qq.com>
# Upgrade apt-get tool
RUN apt-get update
RUN apt-get -y upgrade
# Install tools
RUN apt-get install -y git m4 zlib1g-dev python-software-properties \
build-essential libgmp-dev libmpfr-dev libmpc-dev unzip software-properties-common python-software-properties

# Install opam
RUN add-apt-repository ppa:avsm/ppa
RUN apt-get update
RUN apt-get install -y ocaml ocaml-native-compilers camlp4-extra opam
RUN opam init --comp=4.01.0  # (answer 'y' to the question)
ENV CAML_LD_LIBRARY_PATH /root/.opam/4.01.0/lib/stublibs
ENV MANPATH :/root/.opam/4.01.0/man
ENV PERL5LIB /root/.opam/4.01.0/lib/perl5
ENV OCAML_TOPLEVEL_PATH /root/.opam/4.01.0/lib/toplevel
ENV OPAM_HOME /root/.opam/4.01.0/bin
ENV PATH ${PATH}:${CAML_LD_LIBRARY_PATH}:${MANPATH}:${PERL5LIB}:${OCAML_TOPLEVEL_PATH}:${OPAM_HOME}
#RUN opam update
RUN opam install sawja.1.5.1 atdgen.1.6.0 javalib.2.3.1 extlib.1.5.4

# Download infer source code
RUN git clone https://github.com/facebook/infer.git
# Install facebook-clang-plugin,clang
RUN cd infer;./update-fcp.sh;
RUN cd infer;apt-get install -y groff
RUN cd infer;../facebook-clang-plugin/clang/setup.sh;
RUN eval `opam config env`;cd infer;./compile-fcp.sh
RUN eval `opam config env`;cd infer;make -C infer
ENV INFER_HOME /infer/infer
ENV PATH ${PATH}:${INFER_HOME}/bin
#Install gradle-2.5
RUN add-apt-repository ppa:cwchien/gradle
RUN apt-get update
#RUN apt-cache search gradle
RUN apt-get install gradle-2.5
CMD eval `opam config env`

  (我会实际操作一次,等我有时间的时候)
上传
  在经历了1个礼拜的上传失败后,公司的网络终于给力了,infer 的image终于上传Docker Hub成功.
成功信息



58deMacBook-Pro:~ wuxian$ docker push doctorq/infer
The push refers to a repository [doctorq/infer] (len: 1)
334f8536c724: Image already exists
79c86a401c9e: Image already exists
b08982ff2ae7: Image already exists
295452c2332e: Image already exists
6f7ac6b3c22e: Image successfully pushed
2f723dfaaf02: Image successfully pushed
4f8c30699e9d: Image successfully pushed
cd797a7e1a37: Image successfully pushed
3ebbcb595d4f: Image successfully pushed
2d901fe5706a: Image successfully pushed
2ab20d71784e: Image already exists
86f5a419baeb: Image successfully pushed
87936850fe94: Image already exists
6a34f2ecf1ae: Image already exists
896c84d68ec8: Image successfully pushed
f95fdfd19566: Image successfully pushed
68f48e28c14b: Image successfully pushed
918558524beb: Image successfully pushed
e81d2d3af07f: Image successfully pushed
569a964ec2cc: Image successfully pushed
1885bd64f8f7: Image successfully pushed
c00c3cf3b2b4: Image successfully pushed
d473f52c6131: Image successfully pushed
8d9b9414ed80: Image successfully pushed
76a68924d522: Image already exists
6be21d1e5d1e: Image already exists
020431a88ee9: Image successfully pushed
602e15acbcda: Image successfully pushed
cab7c4dcf81b: Image successfully pushed
Digest: sha256:ba58f6ad6d2725e2bc94bfc381217b2de7b477d4448eafd8366474aab873f609

成功截图
DSC0000.jpg
使用步骤
  前提是你的docker环境已经配置完成

下载到本地
进入容器
  docker run -it doctorq/infer /bin/bash
infer源码位置
  root/infer


root@f71395f22159:/# cd root/infer
root@f71395f22159:~/infer# ls -l
total 56
-rw-r--r-- 1 root root  235 Jul 13 04:11 CONTRIBUTING.md
-rw-r--r-- 1 root root 1206 Jul 13 04:11 FILES.md
-rw-r--r-- 1 root root 3795 Jul 13 04:11 INSTALL.md
-rw-r--r-- 1 root root 1501 Jul 13 04:11 LICENSE
-rw-r--r-- 1 root root 1982 Jul 13 04:11 PATENTS
-rw-r--r-- 1 root root  429 Jul 13 04:11 README.md
-rwxr-xr-x 1 root root 1787 Jul 13 04:11 compile-fcp.sh
drwxr-xr-x 4 root root 4096 Jul 13 04:11 dependencies
drwxr-xr-x 6 root root 4096 Jul 16 07:39 examples
drwxr-xr-x 9 root root 4096 Jul 13 04:19 infer
-rw-r--r-- 1 root root  304 Jul 13 04:11 infer.install
-rw-r--r-- 1 root root  545 Jul 13 04:11 opam
drwxr-xr-x 2 root root 4096 Jul 13 04:11 scripts
-rwxr-xr-x 1 root root  739 Jul 13 04:11 update-fcp.sh

分析
  我们以源码中的例子来分析,首先进入examples目录。


root@f71395f22159:~/infer# cd examples/
root@f71395f22159:~/infer/examples# ls -l
total 40
-rw-r--r-- 1 root root  396 Jul 16 07:39 Hello.class
-rw-r--r-- 1 root root   79 Jul 13 04:11 Hello.java
-rw-r--r-- 1 root root  182 Jul 13 04:11 Hello.m
-rw-r--r-- 1 root root 1221 Jul 13 04:11 README
drwxr-xr-x 7 root root 4096 Jul 13 09:16 android_hello
drwxr-xr-x 3 root root 4096 Jul 13 07:58 c_hello
-rw-r--r-- 1 root root   65 Jul 13 04:11 hello.c
-rw-r--r-- 1 root root 1240 Jul 13 07:58 hello.o
drwxr-xr-x 8 root root 4096 Jul 16 07:39 infer-out
drwxr-xr-x 6 root root 4096 Jul 13 08:00 ios_hello

Java文件


root@f71395f22159:~/infer/examples# infer -- javac Hello.java
Starting analysis (Infer version git-1356fd331f3db485be9ee38446a7389c9310d344)
Analysis done
1 file analyzed

/root/infer/examples/Hello.java:4: error: NULL_DEREFERENCE
object s last assigned on line 3 could be null and is dereferenced at line 4
root@f71395f22159:~/infer/examples#

Android项目


root@f71395f22159:~/infer/examples/android_hello# gradle clean
:app:clean
BUILD SUCCESSFUL
Total time: 6.522 secs
This build could be faster, please consider using the Gradle Daemon: http://gradle.org/docs/2.5/userguide/gradle_daemon.html
root@f71395f22159:~/infer/examples/android_hello# infer -- gradle build
08:11:22.183 [ERROR] [org.gradle.api.Project] /root/infer/examples/android_hello/app/build/intermediates/exploded-aar/com.android.support/appcompat-v7/22.0.0/res/drawable-hdpi-v4/abc_spinner_mtrl_am_alpha.9.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
08:11:36.470 [ERROR] [org.gradle.api.Project] /root/infer/examples/android_hello/app/build/intermediates/exploded-aar/com.android.support/appcompat-v7/22.0.0/res/drawable-hdpi-v4/abc_spinner_mtrl_am_alpha.9.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
Starting analysis (Infer version git-1356fd331f3db485be9ee38446a7389c9310d344)
Analysis done
5 files analyzed

/root/infer/examples/android_hello/app/src/main/java/infer/inferandroidexample/MainActivity.java:20: error: NULL_DEREFERENCE
object s last assigned on line 19 could be null and is dereferenced at line 20
/root/infer/examples/android_hello/app/src/main/java/infer/inferandroidexample/MainActivity.java:37: error: RESOURCE_LEAK
resource acquired to fis by call to FileOutputStream(...) at line 34 is not released after line 37
root@f71395f22159:~/infer/examples/android_hello#


C文件


root@f71395f22159:~/infer/examples# infer -- gcc -c hello.c
Starting analysis (Infer version git-1356fd331f3db485be9ee38446a7389c9310d344)
Analysis done
1 file analyzed

hello.c:5: error: NULL_DEREFERENCE
pointer s last assigned on line 4 could be null and is dereferenced at line 5, column 3


C 项目



root@f71395f22159:~/infer/examples/c_hello# make clean
rm -rf example.o
root@f71395f22159:~/infer/examples/c_hello# infer -- make
cc -c example.c
Starting analysis (Infer version git-1356fd331f3db485be9ee38446a7389c9310d344)
Analysis done
1 file analyzed

example.c:22: error: NULL_DEREFERENCE
pointer max last assigned on line 21 could be null and is dereferenced at line 22, column 10
example.c:36: error: NULL_DEREFERENCE
pointer joe last assigned on line 35 could be null and is dereferenced by call to get_age() at line 36, column 10
example.c:45: error: RESOURCE_LEAK
resource acquired to fd by call to open() at line 41, column 12 is not released after line 45, column 5
example.c:51: error: MEMORY_LEAK
memory dynamically allocated to p by call to malloc() at line 51, column 14 is not reachable after line 51, column 3
example.c:57: error: MEMORY_LEAK
memory dynamically allocated to p by call to malloc() at line 56, column 14 is not reachable after line 57, column 3
root@f71395f22159:~/infer/examples/c_hello#

版权声明:本文为博主原创文章,未经博主允许不得转载。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-126223-1-1.html 上篇帖子: Docker 使用自定义网桥 下篇帖子: 业内docker技巧和最佳实践的想法
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表