docker 从入门到放弃—4.Jenkins 构建node docker镜像

1.Dockerfile 内容如下:发布至代码根目录

# Start with a base image containing Java runtime
FROM node:latest

#未镜像设定作者
MAINTAINER liuhubo@*.com

# 给镜像制定标签
LABEL h5.*.com node

#set workdir
WORKDIR /work

# Add a volume pointing to /work
VOLUME /work

# Make port 8080 available to the world outside this container
EXPOSE 3000

#将打包好的jar 上传到镜像的对应工作目录
ADD . /work/

#将在当前镜像基础上执行指定命令,并提交为新的镜像
RUN npm install -g cnpm –registry=https://registry.npm.taobao.org \
npm install pm2 -g –registry=https://registry.npm.taobao.org

RUN chmod +x /work/docker_start.sh

CMD /bin/sh /work/docker_start.sh

 

2,docker_start.sh 内容如下:发布至代码根目录

cd /work
npm run start-test
pm2 logs -f 0

此处的启动需要解决启动后项目自动停止的问题,所以添加了pm2 logs -f 0

 

3.shell 内容

cd $WORKSPACE
project_name=”h5″
find $WORKSPACE -type d -name “.git”|xargs rm -rf
. ~/.nvm/nvm.sh
nvm use 8.11.2
echo `date +%y_%m_%d_%H%M_%S`_N_${BUILD_NUMBER} >version.txt
cnpm install
cnpm run build-test
chmod 755 docker_start.sh

docker build -t node_pm2_$project_name .
echo ‘================开始推送镜像================’
docker tag -f node_pm2_$project_name:latest registry.cn-beijing.aliyuncs.com/yourname/test:$project_name
docker push registry.cn-beijing.aliyuncs.com/yourname/test:$project_name
echo ‘================结束推送镜像================’

 

 

发表评论

电子邮件地址不会被公开。