rubyã®RPMãä½ãã®ãDockerã¨CircleCIã«ããããã便å©ã ã£ã
ãã®è¨äºã¯フィードフォースエンジニア Advent Calendar 2015 - Adventar4æ¥ç®ã§ãï¼
ã¿ãªããrubyã®RPMãã«ãã£ã¦ã©ããã¦ã¾ããï¼
CentOSãã¡ã¤ã³ã§ä½¿ã£ã¦ããã¨ææ°ã®rubyã¯yumã§å ¥ããªãã®ã§ã©ããã®ãªãã¸ããªããã¤ã³ã¹ãã¼ã«ãããèªåã§ãã«ãããå¿ è¦ããããã¨æãã¾ãã
ãããã¸ã§ãã³ã°ã®ã¿ã¤ãã³ã°ã§rbenvãmakeã§å ¥ãã¦ãããã®ã§ããciãæ°è¦ãã¹ããç«ã¦ãæãªã©æ¯årubyã®ãã«ããããã®ã§æéãããã£ã¦ãã¾ããã§ãããã ãããå«ã§rubyã¯ãªãªã¼ã¹ããããã³ã«rpmåãã¦ã¤ã³ã¹ãã¼ã«ããããã«ãã¦ãã¾ãã ã¨ãããrpmã®ãã«ãç°å¢ã£ã¦ç¨æããã®ãé¢åã ã£ãããã«ããããç°å¢ãã¨ã«vagrantãç«ã¡ä¸ãã¦ãã¨ãæå¤ã¨æéããããã
èªååããããªã¼ã¨æã£ã¦ãã¦ãDockerã¯ç¹å®ã®ç°å¢ãåç¾ããã®ã«æé©ã ããCircleCIã¯GitHubã®pushãmergeãããªã¬ã¼ã«ãã¦ããããã§ããããããã ï¼ã£ã¦ãããã¨ã§Dockerã¨CircleCIã使ã£ã¦èªåã§ãã«ãã§ããããã«ãã¾ããã
ä»åã®è¨äºã§ä½¿ã£ãã½ã¼ã¹ã³ã¼ãã¯ãã¡ãã§ãã
critical-alert/oreno-ruby-rpm · GitHub
å ¨ä½ã®æµã
circle.ymlãè¦ãã¨ãªãã¨ãªããããã¨æãã¾ãããæµãã¨ãã¦ã¯ä»¥ä¸ã®ãããªæãã
- GitHubã«pushã¾ãã¯ãã¼ã¸ãããã¿ã¤ãã³ã°ã§CircleCIãèµ°ã
- docker build ã§docker imageããã«ããã
- docker run ã§å®éã«RPMãã«ããè¡ã
- docker cp ã§ã³ã³ããã®ä¸ããåºæ¥ãRPMãåãåºã
RPMãåãåºãã¨æ¸ãã¦ãã¾ããããã¯æ£ç¢ºã§ã¯ãªãã$CIRCLE_ARTIFACTS
ã¨ãããã¹ã«ãã¡ã¤ã«ãç½®ãã¨CircleCiã®ArtifactsããDLã§ããããã«ãªã£ã¦ãã¾ãã
ãã¤ã³ã
å®éã«RPMã®ãã«ããè¡ã£ã¦ããã®ã¯docker run
ã§ç«ã¡ä¸ããã³ã³ããã®ä¸ã§ãã
èå¿ã®Dockerfileã¯ãã®ããã«ãªã£ã¦ãã¾ãã
FROM centos:6.6 MAINTAINER hirokazu SUGIUCHI # setup RUN yum update -y RUN yum install -y rpm-build tar # ruby depends RUN yum -y install readline-devel ncurses-devel gdbm-devel glibc-devel gcc openssl-devel libyaml-devel libffi-devel zlib-devel # builduser RUN useradd rpmbuilder # build prepare RUN mkdir -p /home/rpmbuilder/rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS} RUN chown rpmbuilder:rpmbuilder /home/rpmbuilder/rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS} WORKDIR /home/rpmbuilder/rpmbuild ADD http://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.3.tar.gz SOURCES/ COPY ruby22x.spec SPECS/ruby22x.spec RUN chmod 777 /home/rpmbuilder/rpmbuild/SOURCES/* # build USER rpmbuilder CMD ["rpmbuild", "-ba", "/home/rpmbuilder/rpmbuild/SPECS/ruby22x.spec"]
ããã¤ããã¤ã³ãããã®ã§ãããã解説ãã¾ãã
rpmãbuildããuserãä½ã£ã
é常Dockerã¯ãã¹ã¦rootã¦ã¼ã¶ã¼ã§ã³ãã³ããå®è¡ããã¾ãããrpmããã«ãããã¨ãã¯rootã§ã®ãã«ãã¯æ¨å¥¨ããã¾ããã(ä»åã«éãã°ããã»ã©åé¡ã¯ç¡ãã¨æãã¾ãã)
ãä½æ³ã«åã£ã¦rpmbuilder
ã¨ããä¸è¬ã¦ã¼ã¶ã¼ãä½æãã¦ãã¾ãã
Dockerfileå
ã§USER
ã¨æå®ããã¨ããã以éã¯ãã®æå®ãããã¦ã¼ã¶ã¼ã§ã³ãã³ããå®è¡ããã¾ãã
ããããåã§ãã¼ããã·ã§ã³ã®èª¿æ´ãã¦ããã®ã¯ãã®ããã§ãã
æå¾ã«CMDã§rpmbuild
åæã®æ®µéã§ã¯ build.sh ãªããã®ãä½ã£ã¦ãã®ãªãã§rubyã®ã½ã¼ã¹ããã¦ã³ãã¼ãããrpmbuild
ã³ãã³ããå®è¡ãããã¨ãã¦ãã¾ããã
ãã®ãã¨docker runæã« docker run ruby-rpm /bin/sh ./build.sh
ã¨ãã£ãããã«shã¹ã¯ãªãããå®è¡ããã¦ãã¾ããã
runæã«ã¹ã¯ãªãããå©ãã®ã¯ããããã§ããããã®ããã«ãã¦ãã¾ãã¨ãã®ã¹ã¯ãªããã®ä¸ã§ãããããã£ã¦ãã¾ãä½ããã£ã¦ããã®ããããã¥ãããªãã®ã¨ãã¹ã¯ãªãã ã®ã¡ã³ããå¿ è¦ã«ãªã£ã¦ãã¾ãã®ã§Dockerfileã§å®çµãããªããã®æ¹ãè¯ãã¨èãDockerfileã®ã¿ã§å®çµããããã«ãã¾ããã
Dockerfileã®ä¸ã«CMDããããã¨ã«ãã£ã¦ãã®ã³ã³ããã®å½¹å²ãæ確ã«ãªãã¨ããã¡ãªãããããã¾ãã ãããããã¨ã§ããã®ã³ã³ããã¯rpmãä½ããã¤ããªã¨ãã¦æ±ããããã«ãªã£ãã¨ãè¨ãã¾ãã (docker imageãrunããã ãã§rpmããã³ã¨ã§ãããããª...)
課é¡
è¤æ°ã®OSã«å¯¾å¿ãã¦ããªããä»åã¯CentOS6ã§ãã«ããã¾ããããCentOS7ã«ã対å¿ãããã§ãã
ããã¯DockerfileãDockerfile
ã¨ããååã§ã¯ãªãã¦ããããªã£ããã¨ãå©ç¨ãã¦Dockerfileãè¤æ°(Dockerfile_centos6
ã¨Dockerfile_centos7
)ä½ããdocker buildæã«æå®ãããããå®è¡ããã°ä½ãããã§ãã
ã¾ã¨ã
- ç¹å®ã®ç°å¢ã§å®è¡ããå¦çãDockerã§è¡ã£ã
- GitHubã¨CircleCIã使ããã¨ã«ãã£ã¦èª°ã§ãRPMãä½ããããã«ãªã£ã
- Dockerfileãç¥ãããæ©ä¼ã«ãªã£ã
ããã§rpmã®specãã¡ã¤ã«ã¨rubyã®ã½ã¼ã¹URLãã¡ããã£ã¨å¤æ´ãã¦pushããã°rubyã®rpmãåºæ¥ä¸ããã¾ãã 12/25æ¥ã«ã¯rubyã®2.3.0ãå ¬éãããã¯ããªã®ã§ãã®æã«ã¯æ´»èºãã¦ããããã¨æã£ã¦ãã¾ãï¼
ã¨ããããã§ã5æ¥ç®ã®ææ¥ã¯ãã£ã¼ããã©ã¼ã¹ã®Makerãkasei_sanã§ãï¼
åèãªã³ã¯
大å¤åèã«ããã¦ããã ãã¾ãã