2015年12月29日火曜日

CentOS6.7にてgolang-1.5.1-0を使用してdocker-machine.exeをビルドする。docker-io-1.7.1-2.el6.x86_64を使用

docker-machine.exeをwindowsでビルドする環境を整える事は少々難がある。
具体的には開発環境用のVisualStudio等をインストールする必要がある訳だが、古い開発環境を今も使わざるを得ないというケースもあるだろう。
docker-machine.exeの為だけに既存の開発環境を変えてしまうのは抵抗があるだろう。

こうした場合はCentOS6.7で用意してしまうのが容易でいい。
epelにgolangがあるのでこれを利用する。
基本、CONTRIBUTING.mdに書いてある通りだが、どの様な環境でビルドすれば良いかは書かれていないのでまとめた。
(docker-machine.exeを必要とする事例は度々ある様だ。)

epelを利用するので、以下の環境となる。
golang-1.5.1-0.el6.x86_64
docker-io-1.7.1-2.el6.x86_64
centos-release-6-7.el6.centos.12.3.x86_64


まずは、epelを追加。
# yum install epel-release
Loaded plugins: fastestmirror
Setting up Install Process
Determining fastest mirrors
 * base: www.ftp.ne.jp
 * extras: www.ftp.ne.jp
 * updates: www.ftp.ne.jp
Resolving Dependencies
--> Running transaction check
---> Package epel-release.noarch 0:6-8 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

======================================================================================================================================
 Package                              Arch                           Version                     Repository                      Size
======================================================================================================================================
Installing:
 epel-release                         noarch                         6-8                         extras                          14 k

Transaction Summary
======================================================================================================================================
Install       1 Package(s)

Total download size: 14 k
Installed size: 22 k
Is this ok [y/N]: y
Downloading Packages:
epel-release-6-8.noarch.rpm                                                                                    |  14 kB     00:00     
warning: rpmts_HdrFromFdno: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
Importing GPG key 0xC105B9DE:
 Userid : CentOS-6 Key (CentOS 6 Official Signing Key) <centos-6-key@centos.org>
 Package: centos-release-6-7.el6.centos.12.3.x86_64 (@anaconda-CentOS-201508042137.x86_64/6.7)
 From   : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
Is this ok [y/N]: y
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : epel-release-6-8.noarch                                                                                            1/1 
  Verifying  : epel-release-6-8.noarch                                                                                            1/1 

Installed:
  epel-release.noarch 0:6-8                                                                                                           

Complete!
次に、goをインストール。
# yum --disablerepo=\* --enablerepo=epel install golang
Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
epel/metalink                                                                                                  | 5.9 kB     00:00     
 * epel: ftp.kddilabs.jp
epel                                                                                                           | 4.3 kB     00:00     
epel/primary_db                                                                                                | 5.7 MB     00:04     
Resolving Dependencies
--> Running transaction check
---> Package golang.x86_64 0:1.5.1-0.el6 will be installed
--> Processing Dependency: golang-src = 1.5.1-0.el6 for package: golang-1.5.1-0.el6.x86_64
--> Processing Dependency: golang-bin for package: golang-1.5.1-0.el6.x86_64
--> Running transaction check
---> Package golang-bin.x86_64 0:1.5.1-0.el6 will be installed
---> Package golang-src.noarch 0:1.5.1-0.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

======================================================================================================================================
 Package                           Arch                          Version                            Repository                   Size
======================================================================================================================================
Installing:
 golang                            x86_64                        1.5.1-0.el6                        epel                        1.2 M
Installing for dependencies:
 golang-bin                        x86_64                        1.5.1-0.el6                        epel                         41 M
 golang-src                        noarch                        1.5.1-0.el6                        epel                        3.7 M

Transaction Summary
======================================================================================================================================
Install       3 Package(s)

Total download size: 46 M
Installed size: 231 M
Is this ok [y/N]: y
Downloading Packages:
(1/3): golang-1.5.1-0.el6.x86_64.rpm                                                                           | 1.2 MB     00:01     
(2/3): golang-bin-1.5.1-0.el6.x86_64.rpm                                                                       |  41 MB     00:40     
(3/3): golang-src-1.5.1-0.el6.noarch.rpm                                                                       | 3.7 MB     00:03     
--------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                 1.0 MB/s |  46 MB     00:46     
warning: rpmts_HdrFromFdno: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
Importing GPG key 0x0608B895:
 Userid : EPEL (6) <epel@fedoraproject.org>
 Package: epel-release-6-8.noarch (@extras)
 From   : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
Is this ok [y/N]: y
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : golang-src-1.5.1-0.el6.noarch                                                                                      1/3 
  Installing : golang-bin-1.5.1-0.el6.x86_64                                                                                      2/3 
  Installing : golang-1.5.1-0.el6.x86_64                                                                                          3/3 
  Verifying  : golang-1.5.1-0.el6.x86_64                                                                                          1/3 
  Verifying  : golang-src-1.5.1-0.el6.noarch                                                                                      2/3 
  Verifying  : golang-bin-1.5.1-0.el6.x86_64                                                                                      3/3 

Installed:
  golang.x86_64 0:1.5.1-0.el6

Dependency Installed:
  golang-bin.x86_64 0:1.5.1-0.el6                                   golang-src.noarch 0:1.5.1-0.el6

 Complete!
次にdockerをインストール。
# yum --disablerepo=\* --enablerepo=epel,base install docker-io.x86_64
Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
 * base: www.ftp.ne.jp
 * epel: ftp.jaist.ac.jp
Resolving Dependencies
--> Running transaction check
---> Package docker-io.x86_64 0:1.7.1-2.el6 will be installed
--> Processing Dependency: lxc for package: docker-io-1.7.1-2.el6.x86_64
--> Processing Dependency: bridge-utils for package: docker-io-1.7.1-2.el6.x86_64
--> Running transaction check
---> Package bridge-utils.x86_64 0:1.2-10.el6 will be installed
---> Package lxc.x86_64 0:1.0.8-1.el6 will be installed
--> Processing Dependency: lua-lxc(x86-64) = 1.0.8-1.el6 for package: lxc-1.0.8-1.el6.x86_64
--> Processing Dependency: lua-alt-getopt for package: lxc-1.0.8-1.el6.x86_64
--> Processing Dependency: liblxc.so.1()(64bit) for package: lxc-1.0.8-1.el6.x86_64
--> Running transaction check
---> Package lua-alt-getopt.noarch 0:0.7.0-1.el6 will be installed
---> Package lua-lxc.x86_64 0:1.0.8-1.el6 will be installed
--> Processing Dependency: lua-filesystem for package: lua-lxc-1.0.8-1.el6.x86_64
---> Package lxc-libs.x86_64 0:1.0.8-1.el6 will be installed
--> Running transaction check
---> Package lua-filesystem.x86_64 0:1.4.2-1.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

======================================================================================================================================
 Package                              Arch                         Version                           Repository                  Size
======================================================================================================================================
Installing:
 docker-io                            x86_64                       1.7.1-2.el6                       epel                       4.6 M
Installing for dependencies:
 bridge-utils                         x86_64                       1.2-10.el6                        base                        30 k
 lua-alt-getopt                       noarch                       0.7.0-1.el6                       epel                       6.9 k
 lua-filesystem                       x86_64                       1.4.2-1.el6                       epel                        24 k
 lua-lxc                              x86_64                       1.0.8-1.el6                       epel                        16 k
 lxc                                  x86_64                       1.0.8-1.el6                       epel                       122 k
 lxc-libs                             x86_64                       1.0.8-1.el6                       epel                       255 k

Transaction Summary
======================================================================================================================================
Install       7 Package(s)

Total download size: 5.0 M
Installed size: 20 M
Is this ok [y/N]: y
Downloading Packages:
(1/7): bridge-utils-1.2-10.el6.x86_64.rpm                                                                      |  30 kB     00:00     
(2/7): docker-io-1.7.1-2.el6.x86_64.rpm                                                                        | 4.6 MB     00:14     
(3/7): lua-alt-getopt-0.7.0-1.el6.noarch.rpm                                                                   | 6.9 kB     00:00     
(4/7): lua-filesystem-1.4.2-1.el6.x86_64.rpm                                                                   |  24 kB     00:00     
(5/7): lua-lxc-1.0.8-1.el6.x86_64.rpm                                                                          |  16 kB     00:00     
(6/7): lxc-1.0.8-1.el6.x86_64.rpm                                                                              | 122 kB     00:00     
(7/7): lxc-libs-1.0.8-1.el6.x86_64.rpm                                                                         | 255 kB     00:00     
--------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                 301 kB/s | 5.0 MB     00:17     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : lxc-libs-1.0.8-1.el6.x86_64                                                                                        1/7 
  Installing : lua-filesystem-1.4.2-1.el6.x86_64                                                                                  2/7 
  Installing : lua-lxc-1.0.8-1.el6.x86_64                                                                                         3/7 
  Installing : lua-alt-getopt-0.7.0-1.el6.noarch                                                                                  4/7 
  Installing : lxc-1.0.8-1.el6.x86_64                                                                                             5/7 
  Installing : bridge-utils-1.2-10.el6.x86_64                                                                                     6/7 
  Installing : docker-io-1.7.1-2.el6.x86_64                                                                                       7/7 
  Verifying  : lxc-libs-1.0.8-1.el6.x86_64                                                                                        1/7 
  Verifying  : lxc-1.0.8-1.el6.x86_64                                                                                             2/7 
  Verifying  : bridge-utils-1.2-10.el6.x86_64                                                                                     3/7 
  Verifying  : docker-io-1.7.1-2.el6.x86_64                                                                                       4/7 
  Verifying  : lua-lxc-1.0.8-1.el6.x86_64                                                                                         5/7 
  Verifying  : lua-alt-getopt-0.7.0-1.el6.noarch                                                                                  6/7 
  Verifying  : lua-filesystem-1.4.2-1.el6.x86_64                                                                                  7/7 

Installed:
  docker-io.x86_64 0:1.7.1-2.el6                                                                                                      

Dependency Installed:
  bridge-utils.x86_64 0:1.2-10.el6          lua-alt-getopt.noarch 0:0.7.0-1.el6          lua-filesystem.x86_64 0:1.4.2-1.el6         
  lua-lxc.x86_64 0:1.0.8-1.el6              lxc.x86_64 0:1.0.8-1.el6                     lxc-libs.x86_64 0:1.0.8-1.el6               

Complete!

ここまででgoでdocker-machieソースをビルドする環境は整う。
ちなみにgo envは以下の通り。

# go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH=""
GORACE=""
GOROOT="/usr/lib/golang"
GOTOOLDIR="/usr/lib/golang/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT=""
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
GOOSの値がlinuxとなっているので、windowsに変えておく。

# export GOOS=windows
再度、 go envで確認する。
GOPATHを設定
# cd /usr/local/src
# mkdir docker-machine
# cd docker-machine
# pwd
/usr/local/src/docker-machine
# export GOPATH="$PWD"

dockerのmachineというレポジトリにdocker-machine.exeのソースがあるので、go get

# go get github.com/docker/machine
# cd src/github.com/docker/machine

次にビルドする。

# make build
go build \
    -o /usr/local/src/docker-machine/src/github.com/docker/machine/bin/docker-machine.exe \
     -tags "" \
    -ldflags "-X `go list ./version`.GitCommit=`git rev-parse --short HEAD 2>/dev/null` -w -s"  ./cmd/machine.go

次の様なバイナリがbinの中に作られるので、これをwindows等にコピーして利用する。

# ls -la bin/docker-machine.exe
-rwxr-xr-x 1 root root 33951232 Dec 29 01:42 bin/docker-machine.exe
# md5sum bin/docker-machine.exe f380ca3fc2d576740a20f57bd2cd0115 bin/docker-machine.exe
これで、docker-machine.exeだけをバージョンアップするといった事もできる。
参考

https://github.com/docker/machine/blob/master/CONTRIBUTING.md

0 件のコメント: