ã¯ããã¾ãã¦ï¼ä»å¹´ï¼æããã¸ã§ã¤ã³ãã¾ããtjinjinã§ããfeedforceã§ã¯ã¢ãã¡ã¤ã³ãã©ãæ
å½ãã¦ãã¾ããã¡ãªã¿ã«ä»å£ãªã¹ã¹ã¡ã¢ãã¡ã¯SHIROBAKOã§ãã
ä»åãµã¼ãCIã«Dockerãå°å ¥ãã¾ããã®ã§ãå®éã®è¨å®ã工夫ããç¹ãªã©æ稿ãããã¨æãã¾ãã
feedforceã®ãµã¼ãCI
å¼ç¤¾ã§ã¯ããã¾ã§CircleCIã¾ãã¯Jenkinsã¨AWSãçµã¿åããã¦ãµã¼ãã®CIãè¡ã£ã¦åãã¾ããã
åè: Jenkinsã§ãµã¼ãã®CIãå§ãã¾ãã
ããããCircleCIãå©ç¨ããããã¸ã§ã¯ããå¢ããã«ã¤ããCircleCIã«å®è¡å¾ ã¡ãçºçããããã«ãªãã¾ãããCircleCIã®å®è¡ãã°ã確èªããã¨ãããAWSã®ã»ããã¢ããã«æéãããã£ã¦ãããã¨ãããã£ãã®ã§ãç°å¢ã®ã»ããã¢ããæéãç縮ã§ãããã®ã®ã¯ãªããã¨æ¢ãã¦ãã¾ããããããªæãDockerãããã®ã§ã¯ã¨ãã話ãè³ã«ãã¾ãããDocker ã¯Docker社ãéçºãã¦ããã³ã³ããåã®ä»®æ³åã½ããã¦ã§ã¢ã§ãã²ã¹ãåã®VMãã軽éã§ãããèµ·åãéããªã©ã®ç¹å¾´ãããã¾ããããã§ãä»åãµã¼ãCIã«Dockerã使ããããæ¤è¨¼ãã¾ããã
Dockerã®è¨å®
Dockerfileãæºåãã
Dockerfileã¨ã¯ãªãªã¸ãã«ã®Docker imageãä½æããããã®è¨å®ãã¡ã¤ã«ã®ãããªãã®ã§ãããã®è¨å®ã«å¾ãDocker imageãä½æããã¾ãã主ã«ãã£ã¦ãããã¨ã¨ãã¦3ç¹ããã¾ãã
- å ¬å¼ã®Docker imageãå ã«æ¢åã§ä½¿ã£ã¦ããã¤ã¡ã¼ã¸ã¨æ¯è¼ãè¡ãã足ããªãããã±ã¼ã¸ãäºåã«ã¤ã³ã¹ãã¼ã«ï¼ããã¯ä»å¾æ¹åãããï¼
- Dockerfileã®ä¸ã§Chefãäºåã«ã¤ã³ã¹ãã¼ã«ããã
- SSHãã°ã¤ã³ç¨ããããã®è¨å®
å®éã®è¨å®ã¯ä¸è¨ã®ããã«ãªãã¾ããï¼ä¸é¨ä¿®æ£ãã¦ãã¾ããï¼
FROM centos:6.6
MAINTAINER FF
RUN yum update -y
RUN yum -y install openssh-server sudo acl attr audit authconfig bzip2 cloog-ppl cronie-anacron \
(ä¸ç¥)
yum clean all && \
## Create user
useradd docker && \
passwd -f -u docker && \
## Set up SSH
mkdir -p /home/docker/.ssh; chown docker /home/docker/.ssh; chmod 700 /home/docker/.ssh && \
echo "<public_key>" > /home/docker/.ssh/authorized_keys && \
chown docker /home/docker/.ssh/authorized_keys && \
chmod 600 /home/docker/.ssh/authorized_keys && \
## setup sudoers
echo "docker ALL=(ALL) ALL" >> /etc/sudoers.d/docker && \
## Set up SSHD config
sed -ri 's/#PermitRootLogin yes/PermitRootLogin yes/g' /etc/ssh/sshd_config && \
sed -ri 's/#UsePAM no/UsePAM no/g' /etc/ssh/sshd_config && \
sed -ri 's/^UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config && \
## Pamèªè¨¼ãæå¹ã§ããã°ã¤ã³ããããã®è¨å®
sed -i -e 's/^\(session.*pam_loginuid.so\)/#\1/g' /etc/pam.d/sshd && \
## Chef-soloãäºåã«ã¤ã³ã¹ãã¼ã«ãã
curl -L https://www.chef.io/chef/install.sh | bash && \
## Init SSHD
/etc/init.d/sshd start && \
/etc/init.d/sshd stop
CMD /usr/sbin/sshd -D
&& \
ã¨ããå½¢ã§RUNã®æ°ããªãã¹ãæ¸ããã¦ãã¾ããDockerã¯instruction(RUNãCMDãªã©)æ¯ã«ã¤ã¡ã¼ã¸ãå·®åã³ããããã¦ãããããä¾ãã°yumããã±ã¼ã¸æ¯ã«instructionãæ¸ãã¦ãã¾ãã¨ãã®åã ãimageãåå²ããã¾ããimageãå¢ããã»ã©ä½åãªæ
å ±ãå¢ããçµæçã«ãµã¤ãºã大ãããªã£ã¦ãã¾ãã¾ããå°ãå¼·å¼ãªããæ¹ã«ã¯ãªãã¾ãããã²ã¨ã¤ã®ã³ãã³ãã®ç¶ãã¨ãããã¨ã§imageãã¾ã¨ãããµã¤ãºãæãããã¨ãå¯è½ã§ãã
CircleCIã®ã³ã³ããããDockerã³ã³ããã«å¯¾ãã¦sshã§ããããã«ãã
å¼ç¤¾ã§ã¯ç¾å¨Chef-soloã¨serverspecã使ã£ã¦æ§æ管çãã¦ãããããã³ã³ããã«å¯¾ãSSHã§æ¥ç¶ããå¿ è¦ãããã¾ããããã§ãDockerèµ·åæã«ãã¼ããæå®ããã¼ããã©ã¯ã¼ãã£ã³ã°ããã¦ãã¾ãã~/.ssh/configã§ãã®ãã¼ãã«å¯¾ãsshããããã«è¨å®ãããã¨ã§ãæ¥ç¶ãå¯è½ã«ãªãã¾ãã
Host test
HostName 127.0.0.1
User docker
Port 40122
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile ~/.ssh/<secret_key_path>
IdentitiesOnly yes
LogLevel FATAL
CircleCIã®è¨å®
ç§å¯éµã¯CircleCIä¸ã«äºåã«è¨å®ãã¦ãã¾ãã
circle.ymlã«ã¤ãã¦ã¯ä»¥ä¸ã®ããã«è¨å®ãã¦ãã¾ãã
machine:
timezone:
Asia/Tokyo
services:
- docker
checkout:
post:
- git submodule sync
- git submodule update --init
dependencies:
cache_directories:
- "~/cache"
pre:
- cp ./.docker/ssh-config.circleci ~/.ssh/config
- ./script/docker-build.sh
- docker run -d --privileged -p 40122:22 docker/centos-sshd; sleep 2
test:
pre:
- bundle exec knife solo cook test:
timeout: 600
override:
- bundle exec rake spec:test:
timeout: 600
docker runã®éã«ã¯--privileged
ãªãã·ã§ã³ãã¤ãã¦ãã¾ããhostnameã®å¤æ´ãããã¬ã·ããããã--privileged
ãªãã·ã§ã³ãä»ããªãã¨ãhostnameã®å¤æ´ããã¾ããããªãã£ãããã§ãã
Docker imageã®ãã£ãã·ã¥æ¹æ³
docker-build.shã¨ããã¹ã¯ãªããã®ä¸ã§ã¯ãã£ãã·ã¥ã®æç¡ã«ãã£ã¦ãå¦çãåå²ãã¦ãã¾ããé常æã¯ãã£ãã·ã¥ããããã¡ã¤ã«ããã¼ãããDockerfileã«å¤æ´ãããå ´åã®ã¿ãã«ããããããã¨ã§å¦çã®æé©åããã¦ãã¾ãã
#!/bin/sh
set -xe
if [ -e ~/cache/centos-sshd.tar ] && [ $(md5sum Dockerfile | cut -d' ' -f1) = $(cat ~/cache/dockerfile.digest) ]
then
docker load < ~/cache/centos-sshd.tar
else
mkdir -p ~/cache
docker build -t docker/centos-sshd .
md5sum Dockerfile | cut -d' ' -f1 > ~/cache/dockerfile.digest
docker save docker/centos-sshd > ~/cache/centos-sshd.tar
fi
å®æ½ããçµæ
çµæã¨ãã¦ã¯ä¸è¨ã®ããã«ãªãã¾ããã
â» CircleCI ã®ã«ãã´ãªã«åºã¥ãã¦ã°ã©ãã«ãã¦ãã¾ã
å½åã®æ³å®ã§ã¯dependenciesï¼ç°å¢ã®ã»ããã¢ãããããé¨åï¼ãç縮ã§ããæ³å®ã§ãããcacheãå¹ãã¦ããªã赤ãã°ã©ãã§ãå¦çæéãåæ¸ãã¦ãã¾ãããæ´ã«cacheãå¹ããããã¨ã§ç´ï¼åã®ï¼ã¾ã§æéãç縮ã§ãã¾ãããã¾ããæ³å®å¤ã®çµæã§ããããtestå·¥ç¨ï¼chef & serverspecï¼ã®æéãå§åçã«çããªãã¾ãããAWSã¯m3.mediumã使ã£ã¦ãã¾ãããCircleCIã®æ¹ãå§åçã«éãã¿ããã§ãããå ¨ä½ã¨ãã¦ï¼ï¼å以ä¸ã®ç縮ãã§ããããæå³ã¯ãã£ããã¨æãã¾ãã
æå¾ã«
ä»åã¯ãDockerHubä¸ã«ããã¦ããimageã使ãã¾ããããã»ãã¥ãªãã£ä¸ã®åé¡ãèããã¨ç®¡çãã¦ããããã§ãããä¸åº¦å ±éçãªDocker imageãä½ã£ã¦ãã¾ãã°ããã«ãããæéãçããã®ã§ãããªãé«éåãã§ãããã§ãã