23. 22
1. テストコードを書く
require './.spec_helper'
describe ("build_test") do
describe ("check pip packages are installed") do
pips = ["ansible"]
describe command("source /root/.bash_profile && pip list") do
pips.each do |pip|
describe ("#{ pip }") do
pip_ver = property['args'][pip.upcase.gsub("-","_") + '_VER']
if pip_ver != nil
its(:stdout) { should match /^#{ pip }s(.*#{ Regexp.escape(pip_ver) }.*)$/ }
else
its(:stdout) { should match /^#{ pip }s(.*)$/ }
end
end
end
<省略>
Serverspecを使うため
Serverspecの規則に則って
書く
24. 23
2. Dockerfileを書く
FROM centos:7.3.1611
WORKDIR /root
# install ansible
RUN yum -y install gcc python-devel openssl-devel libffi-devel
RUN curl -o /tmp/get-pip.py https://bootstrap.pypa.io/get-pip.py
RUN python /tmp/get-pip.py
ARG ANSIBLE_VER
RUN if [ "$ANSIBLE_VER" = "" ] ; then
pip install ansible ;
else
pip install ansible==$ANSIBLE_VER ;
fi
<省略>