Automate generate Dockerfile within Jenkins pipeline job
# generate Dockerfile
/bin/rm -rf ${WORKSPACE}/docker
/bin/mkdir -p ${WORKSPACE}/docker
cd ${WORKSPACE}/docker
touch Dockerfile
cat <<EOF > Dockerfile
# set the base image to Centos
FROM centos:6.7
# File Author / Maintainer
MAINTAINER buildmaster <buildmaster@qxc.com>
RUN rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
RUN yum install -y salt salt-minion
# udpate salt file_roots, and pillar_roots
RUN echo 'file_roots:' >> /etc/salt/minion
RUN echo ' base:' >> /etc/salt/minion
RUN echo ' - /srv/salt' >> /etc/salt/minion
RUN echo ' - /srv/formulas' >> /etc/salt/minion
RUN echo ' dev:' >> /etc/salt/minion
RUN echo ' - /srv/salt' >> /etc/salt/minion
RUN echo ' - /srv/formulas' >> /etc/salt/minion
RUN echo 'pillar_roots:' >> /etc/salt/minion
RUN echo ' base:' >> /etc/salt/minion
RUN echo ' - /srv/pillar' >> /etc/salt/minion
RUN echo ' dev:' >> /etc/salt/minion
RUN echo ' - /srv/pillar/qa' >> /etc/salt/minion
# use local file_client
RUN echo 'file_client: local' >> /etc/salt/minion
# define Salt role
RUN salt-call grains.setval roles "[${MY_ROLE}]"
EOF
Build docker image, consume with docker container
# build a docker image from Dockerfilecd ${WORKSPACE}/docker
docker build -t ${DOCKER_IMAGE}.v${PIPELINE_VERSION} .
# add host directory as a data volume (which only works with at least centos6.7)
# invoke salt-call with docker container
docker run –v salt_scripts:/srv/rw -t ${DOCKER_IMAGE}.v${PIPELINE_VERSION} salt-call --local pillar.items | /usr/bin/tee ${OUTPUT}
# handle return code and clean up successful docker container
CHECK_SH=${WORKSPACE}/${PIPELINE_VERSION}.`date "+%Y%m%d%M%S"`.sh
/bin/echo "#!/bin.sh" > ${CHECK_SH}
/bin/echo "RET_CODE=0" >> ${CHECK_SH}
/bin/echo "/bin/grep -n -i error ${OUTPUT} > ${OUTPUT}.tmp" >> ${CHECK_SH}
/bin/echo "if [ ! -s ${OUTPUT}.tmp ]; then" >> ${CHECK_SH}
/bin/echo " docker rmi -f ${DOCKER_IMAGE}.v${PIPELINE_VERSION}" >> ${CHECK_SH}
/bin/echo "else" >> ${CHECK_SH}
/bin/echo " RET_CODE=1" >> ${CHECK_SH}
/bin/echo "fi" >> ${CHECK_SH}
/bin/echo "exit ${RET_CODE}" >> ${CHECK_SH}
/bin/sh ${CHECK_SH}
Great blog, I was searching this for a while. Do post more like this.
ReplyDeleteDevOps course in Chennai
Best DevOps Training in Chennai
AWS Training in Chennai
AWS Certification in Chennai
RPA Training in Chennai
Robotics Process Automation Training in Chennai
DevOps Training in Anna Nagar
DevOps Training in Chennai
This post is giving very good guidance and I am very happy to see your great blog. This blog is very attractive and very interesting content. Thank you..!
ReplyDeleteExcel Training in Chennai
Excel Course in Chennai
Tableau Training in Chennai
Pega Training in Chennai
Tableau Training in Chennai
Linux Training in Chennai
Oracle Training in Chennai
Spark Training in Chennai
corporate training in chennai
Power BI Training in Chennai
ReplyDeleteGet inspired by your blog. Keep doing like this....
Tally Course in Chennai
Tally Course in Hyderabad
Tally training in coimbatore
Tally course in madurai
Best tally training institute in bangalore
tally course in marathahalli
tally Training in bangalore
Tally Classes in Bangalore
Ethical hacking course in bangalore
Software Testing course in Bangalore
The Star Grand at The Star Gold Coast | JTM Hub
ReplyDeleteWith the launch of the 고양 출장마사지 Star Grand 광양 출장마사지 at The Star Gold Coast, the hotel was The resort will be located on 여주 출장샵 the Gold Coast's Gold 용인 출장샵 Coast 울산광역 출장샵 (Broadbeach),
GlassWire Elite Activation Key provides you fantastic info and simplifies the system identification that at which the infected document GlassWire Pro Elite Crack
ReplyDeleteReimage PC Repair License Key specializes in the overall protection of your system and all its programs. It detects any suspicious programs Free Reimage Repair
ReplyDelete