edgex0.7.1_1.0.1的X86编译和交叉编译
一. X86编译
1. 安装zeromq库
根据setup script安装:
wget https://github.com/zeromq/libzmq/releases/download/v4.2.2/zeromq-4.2.2.tar.gz tar xvzf zeromq-4.2.2.tar.gz cd zeromq-4.2.2 ./configure sudo make install sudo ldconfig ldconfig -p | grep zmq libzmq.so.5 (libc6,x86-64) => /usr/local/lib/libzmq.so.5 libzmq.so (libc6,x86-64) => /usr/local/lib/libzmq.so export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/
2. 获取源码
go get github.com/edgexfoundry/edgex-go
3. 安装依赖包
edgex0.7.1采用glide管理go工程
$ glide install [INFO] Lock file (glide.lock) does not exist. Performing update. [INFO] Downloading dependencies. Please wait... [INFO] --> Fetching updates for github.com/BurntSushi/toml [INFO] --> Fetching updates for github.com/eclipse/paho.mqtt.golang [INFO] --> Fetching updates for github.com/stretchr/testify [INFO] --> Fetching updates for github.com/hashicorp/consul [INFO] --> Fetching updates for github.com/docker/docker [INFO] --> Fetching updates for github.com/gorilla/mux [INFO] --> Fetching updates for github.com/docker/go-units [INFO] --> Fetching updates for github.com/go-zoo/bone [INFO] --> Fetching updates for github.com/docker/go-connections [INFO] --> Fetching updates for github.com/mitchellh/consulstructure [INFO] --> Fetching updates for github.com/pelletier/go-toml [INFO] --> Fetching updates for github.com/pebbe/zmq4 [INFO] --> Fetching updates for github.com/robfig/cron [INFO] --> Fetching updates for gopkg.in/mgo.v2 [INFO] --> Fetching updates for gopkg.in/yaml.v2 [INFO] --> Fetching updates for github.com/mattn/go-xmpp [INFO] --> Fetching updates for github.com/satori/go.uuid [INFO] --> Fetching updates for github.com/magiconair/properties [INFO] --> Fetching updates for github.com/docker/distribution [INFO] --> Fetching updates for github.com/gomodule/redigo [INFO] --> Setting version for github.com/mattn/go-xmpp to e543ad3fcd51155e4b39f7487bdfcb5e3772f1ce. [INFO] --> Setting version for github.com/docker/docker to b1116479b23434de7d70710b6454af7cb2484a58. [INFO] --> Setting version for github.com/docker/go-connections to 97c2040d34dfae1d1b1275fa3a78dbdd2f41cf7e. [INFO] --> Setting version for github.com/docker/go-units to 47565b4f722fb6ceae66b95f853feed578a4a51c. [INFO] --> Setting version for github.com/BurntSushi/toml to a368813c5e648fee92e5f6c30e3944ff9d5e8895. [INFO] --> Setting version for github.com/mitchellh/consulstructure to b407c521973b7b902db2f09e65dbf5cb10f2dc5f. [INFO] --> Setting version for github.com/docker/distribution to 16128bbac47f75050e82f7e91b04df33775e0c23. [INFO] --> Setting version for github.com/go-zoo/bone to 9eaad4b99a9a66b85c0cc32cb9691621ccfa4278. [INFO] --> Detected semantic version. Setting version for github.com/pelletier/go-toml to v1.2.0 [INFO] --> Detected semantic version. Setting version for github.com/hashicorp/consul to v1.1.0 [INFO] --> Detected semantic version. Setting version for github.com/stretchr/testify to v1.2.1 [INFO] --> Detected semantic version. Setting version for github.com/gorilla/mux to v1.3.0 [INFO] --> Detected semantic version. Setting version for github.com/pebbe/zmq4 to v1.0.0 [INFO] --> Detected semantic version. Setting version for github.com/robfig/cron to v1.1.0 [INFO] --> Detected semantic version. Setting version for github.com/gomodule/redigo to v2.0.0 [INFO] --> Detected semantic version. Setting version for github.com/magiconair/properties to v1.8.0 [INFO] --> Detected semantic version. Setting version for github.com/satori/go.uuid to v1.2.0 [INFO] --> Detected semantic version. Setting version for github.com/eclipse/paho.mqtt.golang to v1.1.1 [INFO] --> Setting version for gopkg.in/mgo.v2 to 3f83fa5005286a7fe593b055f0d7771a7dce4655. [INFO] --> Setting version for gopkg.in/yaml.v2 to eb3733d160e74a9c7e442f435eb3bea458e1d19f. [INFO] Resolving imports [INFO] --> Fetching updates for github.com/gorilla/context [INFO] --> Fetching updates for github.com/davecgh/go-spew [INFO] --> Fetching updates for github.com/pmezard/go-difflib [INFO] --> Fetching updates for github.com/stretchr/objx [INFO] --> Fetching golang.org/x/net/proxy [WARN] Unable to checkout golang.org/x/net/proxy [ERROR] Error looking for golang.org/x/net/proxy: Cannot detect VCS [INFO] --> Fetching golang.org/x/net/websocket [WARN] Unable to checkout golang.org/x/net/websocket [ERROR] Error looking for golang.org/x/net/websocket: Cannot detect VCS [INFO] --> Fetching updates for github.com/influxdata/influxdb [INFO] --> Fetching updates for github.com/hashicorp/go-cleanhttp [INFO] --> Fetching updates for github.com/hashicorp/go-rootcerts [INFO] --> Fetching updates for github.com/hashicorp/serf [INFO] --> Fetching updates for github.com/cenkalti/backoff [INFO] --> Fetching updates for github.com/mitchellh/copystructure [INFO] --> Fetching updates for github.com/mitchellh/mapstructure [INFO] --> Fetching updates for github.com/opencontainers/go-digest [INFO] --> Fetching updates for github.com/pkg/errors [INFO] --> Fetching golang.org/x/net/context/ctxhttp [WARN] Unable to checkout golang.org/x/net/context/ctxhttp [ERROR] Error looking for golang.org/x/net/context/ctxhttp: Cannot detect VCS [ERROR] Error scanning github.com/influxdata/influxdb/client/v2: cannot find package "." in: /home/wang/.glide/cache/src/https-github.com-influxdata-influxdb/client/v2 [INFO] --> Fetching updates for github.com/mitchellh/go-homedir [INFO] --> Fetching updates for github.com/armon/go-metrics [INFO] --> Fetching updates for github.com/mitchellh/reflectwalk [INFO] --> Fetching updates for github.com/opencontainers/image-spec [INFO] --> Fetching updates for github.com/Microsoft/go-winio [WARN] Unable to set version on golang.org/x/net/proxy to . Err: Cannot detect VCS [INFO] --> Fetching updates for github.com/hashicorp/go-immutable-radix [INFO] --> Fetching updates for github.com/gogo/protobuf [INFO] --> Fetching golang.org/x/sys/windows [WARN] Unable to checkout golang.org/x/sys/windows [ERROR] Error looking for golang.org/x/sys/windows: Cannot detect VCS [INFO] --> Fetching updates for github.com/hashicorp/golang-lru [WARN] Unable to set version on golang.org/x/sys/windows to . Err: Cannot detect VCS [ERROR] Failed to retrieve a list of dependencies: Error resolving imports
提取如下依赖包错误:
golang.org/x/net/proxy golang.org/x/net/websocket golang.org/x/net/context/ctxhttp golang.org/x/sys/windows
glide搜索到的包应该以git或svn等vcs,但上述proxy、websocket和ctxhttp是net的子包,golang.org/x/net/采用git管理。同样,golang.org/x/sys采用git管理,windows是sys的子目录。此时,可在glide.yaml中指定golang.org/x/net和golang.org/x/sys的子包关系:
- package: golang.org/x/net subpackages: - proxy - websocket - context/ctxhttp - package: golang.org/x/sys subpackages: - windows
此时,直接设置git管理包的镜像即可,mirror设置:
glide mirror set https://golang.org/x/net https://github.com/golang/net --vcs git glide mirror set golang.org/x/sys https://github.com/golang/sys --vcs git
此时,glide install成功执行。
注:若安装的依赖包出现错误,可能是包版本不对,需要在glide.yaml中指定软件包的版本(如master中已不包含原来的目录,导致包检索依赖不成功,github.com/influxdata/influxdb/client/v2最新版没有client目录)。
edgex1.0.1采用GO111MODULE管理
首先确保go版本在1.11之上,golang从1.11开始内置module管理功能。
由于golang.org被墙,需要在go.mod中增加替换:
replace ( bitbucket.org/bertimus9/systemstat => github.com/sigma/systemstat v0.0.0-20180207000608-0eeff89b0690 golang.org/x/crypto => github.com/golang/crypto v0.0.0-20181029021203-45a5f77698d3 golang.org/x/net => github.com/golang/net v0.0.0-20181201002055-351d144fa1fc golang.org/x/sync => github.com/golang/sync v0.0.0-20181221193216-37e7f081c4d4 golang.org/x/sys => github.com/golang/sys v0.0.0-20181026203630-95b1ffbd15a5 golang.org/x/tools => github.com/golang/tools v0.0.0-20181112210238-4b1f3b6b1646 )
4. 编译
make prepare
make build
5. 启动mongodb,然后直接运行make run即可。
在自目录保存数据,如/home/wang/edgex/db。
sudo mongod --dbpath "/home/wang/edgex/db" mongo init_mongo.js sudo mongod --dbpath "/home/wang/edgex/db" --shutdown sudo chown -R mongodb:mongodb "/home/wang/edgex/db" sudo mongod --dbpath "/home/wang/edgex/db" --auth
sudo mongod --dbpath "/home/wang/edgex/db" --bind_ip_all ;允许远程访问数据库
make run
若运行报错,可能是mongo权限问题,去除--auth。
6. 测试随机数设备
参考4.3.1. Writing a Device Service in Go编译随机数简单设备,运行device-simple可执行文件。
若不报错,且数据一直上报,可通过如下地址查询数据:
http://localhost:48080/api/v1/event/device/RandNum-Device01/100
http://172.61.1.125:48080/api/v1/event http://172.61.1.125:48071/api/v1/registration http://172.61.1.125:48080/api/v1/event/count http://172.61.1.125:48080/api/v1/valuedescriptor http://172.61.1.125:48081/api/v1/device http://172.61.1.125:48081/api/v1/deviceservice
可注册mosquitto云平台,上传至云平台:
POST to http://192.168.134.144:48071/api/v1/registration {"name":"MyMQTTTopic","addressable":{"name":"MyMQTTBroker","protocol":"TCP","address":"192.168.134.144","port":1883,"publisher":"EdgeXExportPublisher","user":"wang","password":"mypass","topic":"a/b/c"},"format":"JSON","enable":true,"destination":"MQTT_TOPIC"}
在主机192.168.134.144上开启mosquitto,并:
$ mosquitto_sub -t a/b/c {"id":"5cecfb6d902d0f90ade77aca","pushed":0,"device":"RandNum-Device01","created":1559034733008,"modified":0,"origin":1559034733003,"schedule":null,"event":null,"readings":[{"id":"5cecfb6d902d0f90ade77acb","pushed":0,"created":1559034733008,"origin":1559034733002,"modified":0,"device":"RandNum-Device01","name":"Random","value":"58"}]}
二. 交叉编译
在Ubuntu16.04上交叉编译edgex 1.0.1,编译后的程序运行于OKMX6DL-S3(Cortex-A9,32位,双核)。
2.1 交叉编译工具链
板卡自带交叉编译工具链应用
. /opt/fsl-imx-x11/4.1.15-2.1.0/environment-setup-cortexa9hf-neon-poky-linux-gnueabi /opt/fsl-imx-x11/4.1.15-2.1.0/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc /opt/fsl-imx-x11/4.1.15-2.1.0/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-g++
通用交叉编译工具链应用
sudo apt-get install g++-5-arm-linux-gnueabihf g++-5-arm-linux-gnueabihf sudo update-alternatives --install /usr/bin/arm-linux-gnueabihf-gcc arm-linux-gnueabihf-gcc /usr/bin/arm-linux-gnueabihf-gcc-5 100 --slave /usr/bin/arm-linux-gnueabihf-g++ arm-linux-gnueabihf-g++ /usr/bin/arm-linux-gnueabihf-g++-5
注:板卡自带交叉编译工具链编译edgex不成功,随采用通用交叉编译工具链。
2.2 交叉编译zeromq
板卡自带交叉编译工具链应用
./configure --prefix=/home/wang/edgex/edgex_mx6dl/zeromq-4.2.2/winstall --host=arm-poky-linux-gnueabi CC="/opt/fsl-imx-x11/4.1.15-2.1.0/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc --sysroot=$SDKTARGETSYSROOT -mfloat-abi=hard" CXX="/opt/fsl-imx-x11/4.1.15-2.1.0/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-g++ --sysroot=$SDKTARGETSYSROOT -mfloat-abi=hard " make && make install
通用交叉编译工具链应用
./configure --prefix=/home/wang/edgex/edgex_mx6dl/zeromq-4.2.2/winstall --host=arm-poky-linux-gnueabi CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++ make && make install
2.3 交叉编译edgex
采用通用交叉编译器编译edgex,解决包依赖关系后,修改Makefile中编译选项:
GO=GOARCH=arm CGO_ENABLED=0 GO111MODULE=on go GOCGO=GOARCH=arm CGO_ENABLED=1 CC="arm-linux-gnueabihf-gcc" \ CGO_CFLAGS="-I/home/wang/edgex/edgex_mx6dl/zeromq-4.2.2/winstall/include" CGO_LDFLAGS="-L/home/wang/edgex/edgex_mx6dl/zeromq-4.2.2/winstall/lib -lzmq" \ GO111MODULE=on go
然后执行如下命令编译
make build
将生成的zeromq库文件winstall,edgex生成的bin和cmd,及mongodb编译而成的bin(mongodb自编译有问题,从网上下载2.6.4版本可执行文件)拷贝到板卡并安装。
先启动mongodb,然后执行edgex,同X86上运行顺序,可正确执行并运行。
三. docker镜像制作
生成所有docker可运行命令:
make docker
生成单独docker可运行命令(以docker_export_distro为例):
make docker_export_distro
docker_export_distro: docker build \ -f cmd/export-distro/Dockerfile \ --label "git_sha=$(GIT_SHA)" \ -t edgexfoundry/docker-export-distro-go:$(GIT_SHA) \ -t edgexfoundry/docker-export-distro-go:$(DOCKER_TAG) \ .
Dockerfile文件如下:
# # Copyright (c) 2017-2018 # Mainflux # Cavium # # SPDX-License-Identifier: Apache-2.0 # FROM golang:1.11-alpine AS builder ENV GO111MODULE=on WORKDIR /go/src/github.com/edgexfoundry/edgex-go # The main mirrors are giving us timeout issues on builds periodically. # So we can try these. RUN sed -e 's/dl-cdn[.]alpinelinux.org/nl.alpinelinux.org/g' -i~ /etc/apk/repositories RUN apk update && apk add zeromq-dev libsodium-dev pkgconfig build-base git COPY go.mod . #COPY go.sum . RUN go mod download COPY . . RUN make cmd/export-distro/export-distro FROM alpine LABEL license='SPDX-License-Identifier: Apache-2.0' \ copyright='Copyright (c) 2017-2018: Mainflux, Cavium' # The main mirrors are giving us timeout issues on builds periodically. # So we can try these. RUN sed -e 's/dl-cdn[.]alpinelinux.org/nl.alpinelinux.org/g' -i~ /etc/apk/repositories RUN apk --no-cache add zeromq COPY --from=builder /go/src/github.com/edgexfoundry/edgex-go/cmd/export-distro/Attribution.txt / COPY --from=builder /go/src/github.com/edgexfoundry/edgex-go/cmd/export-distro/export-distro / COPY --from=builder /go/src/github.com/edgexfoundry/edgex-go/cmd/export-distro/res/docker/configuration.toml /res/docker/configuration.toml ENTRYPOINT ["/export-distro","--registry","--profile=docker","--confdir=/res"]
上述命令生成两个镜像(其中一个在cache中,另一个为实际镜像,两个tag),没有容器产生(docker ps -a不显示,容器被删除):
export-distro容器镜像生成日志:
make docker_export_distro docker build \ -f cmd/export-distro/Dockerfile \ --label "git_sha=48146ead559bd9f27e80af344e3cf787530a1539" \ -t edgexfoundry/docker-export-distro-go:48146ead559bd9f27e80af344e3cf787530a1539 \ -t edgexfoundry/docker-export-distro-go:1.0.2-dev \ . Sending build context to Docker daemon 161MB Step 1/18 : FROM golang:1.11-alpine AS builder ---> e116d2efa2ab Step 2/18 : ENV GO111MODULE=on ---> Using cache ---> 6f17441d1946 Step 3/18 : WORKDIR /go/src/github.com/edgexfoundry/edgex-go ---> Using cache ---> 1e94eec59dac Step 4/18 : RUN sed -e 's/dl-cdn[.]alpinelinux.org/nl.alpinelinux.org/g' -i~ /etc/apk/reposi tories ---> Using cache ---> 48697136fcca Step 5/18 : RUN apk update && apk add zeromq-dev libsodium-dev pkgconfig build-base git ---> Running in bea28e9e5eb1 fetch http://nl.alpinelinux.org/alpine/v3.10/main/x86_64/APKINDEX.tar.gz fetch http://nl.alpinelinux.org/alpine/v3.10/community/x86_64/APKINDEX.tar.gz v3.10.3-17-g2fd4d3cdac [http://nl.alpinelinux.org/alpine/v3.10/main] v3.10.3-13-g8068beb776 [http://nl.alpinelinux.org/alpine/v3.10/community] OK: 10340 distinct packages available (1/28) Installing binutils (2.32-r0) (2/28) Installing libmagic (5.37-r1) (3/28) Installing file (5.37-r1) (4/28) Installing gmp (6.1.2-r1) (5/28) Installing isl (0.18-r0) (6/28) Installing libgomp (8.3.0-r0) (7/28) Installing libatomic (8.3.0-r0) (8/28) Installing libgcc (8.3.0-r0) (9/28) Installing mpfr3 (3.1.5-r1) (10/28) Installing mpc1 (1.1.0-r0) (11/28) Installing libstdc++ (8.3.0-r0) (12/28) Installing gcc (8.3.0-r0) (13/28) Installing musl-dev (1.1.22-r3) (14/28) Installing libc-dev (0.7.1-r0) (15/28) Installing g++ (8.3.0-r0) (16/28) Installing make (4.2.1-r2) (17/28) Installing fortify-headers (1.1-r0) (18/28) Installing build-base (0.5-r1) (19/28) Installing nghttp2-libs (1.39.2-r0) (20/28) Installing libcurl (7.66.0-r0) (21/28) Installing expat (2.2.8-r0) (22/28) Installing pcre2 (10.33-r0) (23/28) Installing git (2.22.0-r0) (24/28) Installing libsodium (1.0.18-r0) (25/28) Installing pkgconf (1.6.1-r1) (26/28) Installing libsodium-dev (1.0.18-r0) (27/28) Installing libzmq (4.3.2-r1) (28/28) Installing zeromq-dev (4.3.2-r1) Executing busybox-1.30.1-r2.trigger OK: 182 MiB in 43 packages Removing intermediate container bea28e9e5eb1 ---> 650c39be3c34 Step 6/18 : COPY go.mod . ---> 3afaf7b13163 Step 7/18 : RUN go mod download ---> Running in ca37635ae857 go: finding github.com/stretchr/testify v1.3.0 go: finding github.com/BurntSushi/toml v0.3.1 go: finding github.com/edgexfoundry/go-mod-core-contracts v0.1.0 go: finding github.com/ugorji/go v1.1.4 go: finding github.com/vektra/mockery v0.0.0-20181123154057-e78b021dcbb5 go: finding github.com/imdario/mergo v0.3.6 go: finding github.com/pkg/errors v0.8.1 go: finding github.com/edgexfoundry/go-mod-registry v0.1.0 go: finding github.com/OneOfOne/xxhash v1.2.5 go: finding bitbucket.org/bertimus9/systemstat v0.0.0-20180207000608-0eeff89b0690 go: finding github.com/hashicorp/consul v1.4.2 go: finding github.com/magiconair/properties v1.8.0 go: finding github.com/gorilla/mux v1.7.0 go: finding github.com/go-stack/stack v1.8.0 go: finding github.com/hashicorp/go-cleanhttp v0.5.0 go: finding github.com/gorilla/context v1.1.1 go: finding github.com/robfig/cron v0.0.0-20180505203441-b41be1df6967 go: finding github.com/stretchr/testify v1.2.2 go: finding github.com/mitchellh/go-testing-interface v1.0.0 go: finding github.com/go-kit/kit v0.8.0 go: finding github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8 go: finding github.com/golang/tools v0.0.0-20181112210238-4b1f3b6b1646 go: finding github.com/gomodule/redigo v2.0.0+incompatible go: finding github.com/davecgh/go-spew v1.1.1 go: finding github.com/stretchr/objx v0.1.0 go: finding github.com/go-logfmt/logfmt v0.4.0 go: finding github.com/mitchellh/mapstructure v1.1.2 go: finding github.com/edgexfoundry/go-mod-messaging v0.1.8 go: finding github.com/eclipse/paho.mqtt.golang v1.1.1 go: finding github.com/mattn/go-xmpp v0.0.0-20190124093244-6093f50721ed go: finding github.com/hashicorp/serf v0.8.2 go: finding github.com/cenkalti/backoff v2.1.1+incompatible go: finding github.com/pebbe/zmq4 v1.0.0 go: finding github.com/hashicorp/go-rootcerts v1.0.0 go: finding gopkg.in/yaml.v2 v2.2.2 go: finding gopkg.in/eapache/queue.v1 v1.1.0 go: finding github.com/davecgh/go-spew v1.1.0 go: finding github.com/mitchellh/copystructure v1.0.0 go: finding github.com/google/uuid v1.1.0 go: finding github.com/pelletier/go-toml v1.2.0 go: finding github.com/mitchellh/go-homedir v1.0.0 go: finding github.com/mitchellh/consulstructure v0.0.0-20190329231841-56fdc4d2da54 go: finding github.com/stretchr/objx v0.1.1 go: finding github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515 go: finding github.com/pmezard/go-difflib v1.0.0 go: finding github.com/hashicorp/go-syslog v1.0.0 go: finding github.com/hashicorp/memberlist v0.1.3 go: finding github.com/hashicorp/mdns v1.0.0 go: finding github.com/mitchellh/reflectwalk v1.0.0 go: finding github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee go: finding github.com/mitchellh/cli v1.0.0 go: finding github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da go: finding github.com/golang/net v0.0.0-20181023162649-9b4f9f5ad519 go: finding github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f go: finding github.com/hashicorp/go-msgpack v0.5.3 go: finding github.com/miekg/dns v1.0.14 go: finding github.com/mitchellh/gox v0.4.0 go: finding gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 go: finding github.com/posener/complete v1.1.1 go: finding github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c go: finding github.com/hashicorp/go-immutable-radix v1.0.0 go: finding github.com/hashicorp/go-multierror v1.0.0 go: finding github.com/hashicorp/go-uuid v1.0.1 go: finding github.com/mitchellh/iochan v1.0.0 go: finding github.com/mattn/go-isatty v0.0.3 go: finding github.com/bgentry/speakeasy v0.1.0 go: finding github.com/hashicorp/errwrap v1.0.0 go: finding github.com/hashicorp/go.net v0.0.1 go: finding github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310 go: finding github.com/hashicorp/go-uuid v1.0.0 go: finding github.com/hashicorp/logutils v1.0.0 go: finding github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c go: finding github.com/mattn/go-colorable v0.0.9 go: finding github.com/hashicorp/golang-lru v0.5.0 go: finding github.com/hashicorp/go-sockaddr v1.0.0 go: finding github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 go: finding github.com/golang/sys v0.0.0-20181026203630-95b1ffbd15a5 go: finding github.com/golang/sync v0.0.0-20181221193216-37e7f081c4d4 go: finding github.com/golang/crypto v0.0.0-20181029021203-45a5f77698d3 go: finding github.com/fatih/color v1.7.0 go: finding github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e Removing intermediate container ca37635ae857 ---> 2ea018099509 Step 8/18 : COPY . . ---> 84ba3cac05ec Step 9/18 : RUN make cmd/export-distro/export-distro ---> Running in 8a604a3ff538 CGO_ENABLED=1 GO111MODULE=on go build -ldflags "-X github.com/edgexfoundry/edgex-go.Version=1.0.2" -o cmd/export-distro/export-distro ./cmd/export-distro Removing intermediate container 8a604a3ff538 ---> baee083043d1 Step 10/18 : FROM alpine ---> 965ea09ff2eb Step 11/18 : LABEL license='SPDX-License-Identifier: Apache-2.0' copyright='Copyright (c) 201 7-2018: Mainflux, Cavium' ---> Running in a01ad4abfdfb Removing intermediate container a01ad4abfdfb ---> 62e4c99a09a5 Step 12/18 : RUN sed -e 's/dl-cdn[.]alpinelinux.org/nl.alpinelinux.org/g' -i~ /etc/apk/repositories ---> Running in 42ead2d3a8ae Removing intermediate container 42ead2d3a8ae ---> bb1077aa9c15 Step 13/18 : RUN apk --no-cache add zeromq ---> Running in aca49fd6b908 fetch http://nl.alpinelinux.org/alpine/v3.10/main/x86_64/APKINDEX.tar.gz fetch http://nl.alpinelinux.org/alpine/v3.10/community/x86_64/APKINDEX.tar.gz (1/5) Installing libgcc (8.3.0-r0) (2/5) Installing libsodium (1.0.18-r0) (3/5) Installing libstdc++ (8.3.0-r0) (4/5) Installing libzmq (4.3.2-r1) (5/5) Installing zeromq (4.3.2-r1) Executing busybox-1.30.1-r2.trigger OK: 8 MiB in 19 packages Removing intermediate container aca49fd6b908 ---> 87d4d892ce45 Step 14/18 : COPY --from=builder /go/src/github.com/edgexfoundry/edgex-go/cmd/export-distro/Attribu tion.txt / ---> fb0838b3634e Step 15/18 : COPY --from=builder /go/src/github.com/edgexfoundry/edgex-go/cmd/export-distro/export- distro / ---> cbc71f92b1a8 Step 16/18 : COPY --from=builder /go/src/github.com/edgexfoundry/edgex-go/cmd/export-distro/res/doc ker/configuration.toml /res/docker/configuration.toml ---> 249eb2415b09 Step 17/18 : ENTRYPOINT ["/export-distro","--registry","--profile=docker","--confdir=/res"] ---> Running in 3ce321e2bbc9 Removing intermediate container 3ce321e2bbc9 ---> a9e2f471715a Step 18/18 : LABEL git_sha=48146ead559bd9f27e80af344e3cf787530a1539 ---> Running in 4d218e19c2ba Removing intermediate container 4d218e19c2ba ---> 67b4d76a7d45 Successfully built 67b4d76a7d45 Successfully tagged edgexfoundry/docker-export-distro-go:48146ead559bd9f27e80af344e3cf787530a1539 Successfully tagged edgexfoundry/docker-export-distro-go:1.0.2-dev
注:生成其他docker镜像时,都会使用cache中镜像(repository和tag都是<none>),编译一次供多个容器使用。可以通过docker tag保留容器。
docker tag baee083043d1 edgex_mid1:first
make docker_core_data docker build \ -f cmd/core-data/Dockerfile \ --label "git_sha=48146ead559bd9f27e80af344e3cf787530a1539" \ -t edgexfoundry/docker-core-data-go:48146ead559bd9f27e80af344e3cf787530a1539 \ -t edgexfoundry/docker-core-data-go:1.0.2-dev \ . Sending build context to Docker daemon 161MB Step 1/18 : FROM golang:1.11-alpine AS builder ---> e116d2efa2ab Step 2/18 : ENV GO111MODULE=on ---> Using cache ---> 6f17441d1946 Step 3/18 : WORKDIR /go/src/github.com/edgexfoundry/edgex-go ---> Using cache ---> 1e94eec59dac Step 4/18 : RUN sed -e 's/dl-cdn[.]alpinelinux.org/nl.alpinelinux.org/g' -i~ /etc/apk/repositories ---> Using cache ---> 48697136fcca Step 5/18 : RUN apk update && apk add zeromq-dev libsodium-dev pkgconfig build-base git ---> Using cache ---> 650c39be3c34 Step 6/18 : COPY go.mod . ---> Using cache ---> 3afaf7b13163 Step 7/18 : RUN go mod download ---> Using cache ---> 2ea018099509 Step 8/18 : COPY . . ---> 2f43fc26cea8 Step 9/18 : RUN make cmd/core-data/core-data ---> Running in c4f567e254ba CGO_ENABLED=1 GO111MODULE=on go build -ldflags "-X github.com/edgexfoundry/edgex-go.Version=1.0.2" -o cmd/core-data/core-data ./cmd/core-data Removing intermediate container c4f567e254ba ---> 3f47fb78be86 Step 10/18 : FROM alpine ---> 965ea09ff2eb Step 11/18 : LABEL license='SPDX-License-Identifier: Apache-2.0' copyright='Copyright (c) 2018: Dell, Cavium' ---> Running in 0df73306b0d5 Removing intermediate container 0df73306b0d5 ---> 2ab515094063 Step 12/18 : RUN sed -e 's/dl-cdn[.]alpinelinux.org/nl.alpinelinux.org/g' -i~ /etc/apk/repositories ---> Running in db0db60625d5 Removing intermediate container db0db60625d5 ---> ccfa3db0f47e Step 13/18 : RUN apk --no-cache add zeromq ---> Running in 236dcf9889df fetch http://nl.alpinelinux.org/alpine/v3.10/main/x86_64/APKINDEX.tar.gz fetch http://nl.alpinelinux.org/alpine/v3.10/community/x86_64/APKINDEX.tar.gz (1/5) Installing libgcc (8.3.0-r0) (2/5) Installing libsodium (1.0.18-r0) (3/5) Installing libstdc++ (8.3.0-r0) (4/5) Installing libzmq (4.3.2-r1) (5/5) Installing zeromq (4.3.2-r1) Executing busybox-1.30.1-r2.trigger OK: 8 MiB in 19 packages Removing intermediate container 236dcf9889df ---> 01425d9e6bf4 Step 14/18 : COPY --from=builder /go/src/github.com/edgexfoundry/edgex-go/cmd/core-data/Attribution.txt / ---> 31a9a4020f22 Step 15/18 : COPY --from=builder /go/src/github.com/edgexfoundry/edgex-go/cmd/core-data/core-data / ---> 732b0fa69f65 Step 16/18 : COPY --from=builder /go/src/github.com/edgexfoundry/edgex-go/cmd/core-data/res/docker/configuration.toml /res/docker/configuration.toml ---> 7ed81604d03f Step 17/18 : ENTRYPOINT ["/core-data","--registry","--profile=docker","--confdir=/res"] ---> Running in dde57cf9df93 Removing intermediate container dde57cf9df93 ---> 1dbe1e5529bf Step 18/18 : LABEL git_sha=48146ead559bd9f27e80af344e3cf787530a1539 ---> Running in f88f03b51cd0 Removing intermediate container f88f03b51cd0 ---> 3ad0508f7ee4 Successfully built 3ad0508f7ee4 Successfully tagged edgexfoundry/docker-core-data-go:48146ead559bd9f27e80af344e3cf787530a1539 Successfully tagged edgexfoundry/docker-core-data-go:1.0.2-dev
参考:
2. 4.2.2.1. Get EdgeX Foundry - Go Developers