这个花了点时间,可以正式跑起来了。

加了常用的工具及中文时区,非root帐号。

除了pm2,其它的module放到应用程序本身的node_modules目录下来实现的。

一,3rd_part/node/node:8.16.2-alpine

FROM alpine:3.9

ENV NODE_VERSION 8.16.2

RUN addgroup -g 1000 node \
    && adduser -u 1000 -G node -s /bin/sh -D node \
    && apk add --no-cache \
        libstdc++ \
    && apk add --no-cache --virtual .build-deps \
        binutils-gold \
        curl \
        g++ \
        gcc \
        gnupg \
        libgcc \
        linux-headers \
        make \
        python \
  # gpg keys listed at https://github.com/nodejs/node#release-keys
  && for key in \
    94AE36675C464D64BAFA68DD7434390BDBE9B9C5 \
    FD3A5288F042B6850C66B31F09FE44734EB7990E \
    71DCFD284A79C3B38668286BC97EC7A07EDE3FC1 \
    DD8F2338BAE7501E3DD5AC78C273792F7D83545D \
    C4F0DFFF4E8C1A8236409D08E73BC641CC11F4C8 \
    B9AE9905FFD7803F25714661B63B535A4C206CA9 \
    77984A986EBC2AA786BC0F66B01FBB92821C587A \
    8FCCA13FEF1D0C2E91008E09770F7A9A5AE15600 \
    4ED778F539E3634C779C87C6D7062848A1AB005C \
    A48C2BEE680E841632CD4E44F07496B3EB3C1762 \
    B9E2F5981AA6E0CD28160D9FF13993A75599653C \
  ; do \
    gpg --batch --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys "$key" || \
    gpg --batch --keyserver hkp://ipv4.pool.sks-keyservers.net --recv-keys "$key" || \
    gpg --batch --keyserver hkp://pgp.mit.edu:80 --recv-keys "$key" ; \
  done \
    && curl -fsSLO --compressed "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION.tar.xz" \
    && curl -fsSLO --compressed "https://nodejs.org/dist/v$NODE_VERSION/SHASUMS256.txt.asc" \
    && gpg --batch --decrypt --output SHASUMS256.txt SHASUMS256.txt.asc \
    && grep " node-v$NODE_VERSION.tar.xz\$" SHASUMS256.txt | sha256sum -c - \
    && tar -xf "node-v$NODE_VERSION.tar.xz" \
    && cd "node-v$NODE_VERSION" \
    && ./configure \
    && make -j$(getconf _NPROCESSORS_ONLN) V= \
    && make install \
    && apk del .build-deps \
    && cd .. \
    && rm -Rf "node-v$NODE_VERSION" \
    && rm "node-v$NODE_VERSION.tar.xz" SHASUMS256.txt.asc SHASUMS256.txt

ENV YARN_VERSION 1.19.1

RUN apk add --no-cache --virtual .build-deps-yarn curl gnupg tar \
  && for key in \
    6A010C5166006599AA17F08146C2130DFD2497F5 \
  ; do \
    gpg --batch --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys "$key" || \
    gpg --batch --keyserver hkp://ipv4.pool.sks-keyservers.net --recv-keys "$key" || \
    gpg --batch --keyserver hkp://pgp.mit.edu:80 --recv-keys "$key" ; \
  done \
  && curl -fsSLO --compressed "https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v$YARN_VERSION.tar.gz" \
  && curl -fsSLO --compressed "https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v$YARN_VERSION.tar.gz.asc" \
  && gpg --batch --verify yarn-v$YARN_VERSION.tar.gz.asc yarn-v$YARN_VERSION.tar.gz \
  && mkdir -p /opt \
  && tar -xzf yarn-v$YARN_VERSION.tar.gz -C /opt/ \
  && ln -s /opt/yarn-v$YARN_VERSION/bin/yarn /usr/local/bin/yarn \
  && ln -s /opt/yarn-v$YARN_VERSION/bin/yarnpkg /usr/local/bin/yarnpkg \
  && rm yarn-v$YARN_VERSION.tar.gz.asc yarn-v$YARN_VERSION.tar.gz \
  && apk del .build-deps-yarn

COPY docker-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["docker-entrypoint.sh"]

CMD [ "node" ]

二,3rd_part/node/p4k_node:8.16.2-alphine

From 3rd_part/node/node:8.16.2-alpine
MAINTAINER P4K

RUN echo -e "export http_proxy=http://xxx.local:8080 \nexport https_proxy=http://xxx.local:8080 \nexport ftp_proxy=http://xxx.local:8080 " >>/etc/profile.1

ENV  TIME_ZONE Asia/Shanghai
ENV  SIS_HOME=/xxx/appsystems
ENV  APP_HOME=${SIS_HOME}/webapps
ENV  CONFIG_HOME=${SIS_HOME}/webconfigs
ENV  LOG_HOME=${SIS_HOME}/weblogs

RUN source /etc/profile.1 \
    && npm --registry https://registry.npm.taobao.org  install [email protected] -g \
    && sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories\
    && apk update \
    && apk add --no-cache busybox-extras tzdata \
    && echo "${TIME_ZONE}" > /etc/timezone \
    && ln -sf /usr/share/zoneinfo/${TIME_ZONE} /etc/localtime \
    && apk add --no-cache zip unzip  curl wget vim bash \
    && alias ll='ls -lh' \
    && addgroup -g 000 -S docker \
    && adduser  -u 000 -D -S docker -G docker \
    #&& npm --registry http://r.cnpmjs.org install [email protected] -g \
    && mkdir -p /home/docker \
    && mkdir -p /p4k/temp/ \
    && mkdir -p ${CONFIG_HOME} \
    && mkdir -p ${APP_HOME} \
    && mkdir -p ${LOG_HOME} \
    && chown -R docker.docker /xxx/ /p4k/ /home/docker \
    && chmod 755 -R /xxx/ /p4k/ /home/docker \
    && echo "finished!!!!"

WORKDIR ${APP_HOME}
USER docker

三,应用

FROM 3rd_part/node/p4k_node:8.16.2-alphine
MAINTAINER P4k
COPY ${PACKAGE_NAME} /p4k/temp/${PACKAGE_NAME}
COPY bootstart.sh  /p4k/bootstart.sh
CMD sh  /p4k/bootstart.sh

四,bootstart.sh示例

#!/bin/bash
set -ex
config_dir="/xxx/webconfigs"
app_dir="/xxx/webapps"
log_dir="/xxx/weblogs"
war_dir="/p4k/temp/"
mkdir -p  "$war_dir/deploy_temp"

war_file=`ls ${war_dir}/*.zip`

unzip ${war_file} -d  $war_dir/deploy_temp
cp -ar  $war_dir/deploy_temp/common/* ${app_dir}/

if [ ${ENV_NAME}="fat" ] || [ ${ENV_NAME}="uat" ] || [ ${ENV_NAME}="prd" ];then
         echo "deploying the environment is:" ${ENV_NAME}
         cp_str="${war_dir}/deploy_temp/differ/${ENV_NAME}_k8s/config/*  ${config_dir}/"
         echo ${cp_str}
         cp -ar ${cp_str}
         if  [ -f ${war_dir}/deploy_temp/differ/${ENV_NAME}_k8s/config/k8s.properties ]; then
             cp -ar ${war_dir}/deploy_temp/differ/${ENV_NAME}_k8s/config/k8s.properties $log_dir
         fi
else
         echo "please give ENV first using '-e' when docker run"
fi

rm -rf ${war_dir}
cd $app_dir
pm2 start websocket.js --no-daemon --max-memory-restart 1G
05-29 00:19