From cea308462863dcd60344db4685fbe4ec9f397367 Mon Sep 17 00:00:00 2001 From: xueye Date: Wed, 16 Mar 2022 20:00:31 +0800 Subject: [PATCH] update build config --- Dockerfile | 46 +++++++++++++++------------------------------- config.json | 19 ------------------- docker-compose.yml | 16 ++++------------ entrypoint.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ start.sh | 30 ------------------------------ 5 files changed, 62 insertions(+), 92 deletions(-) delete mode 100644 config.json create mode 100644 entrypoint.sh delete mode 100644 start.sh diff --git a/Dockerfile b/Dockerfile index 48a3702..5251e5a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,49 +1,33 @@ FROM node:12-alpine as builder -ENV YAPI_VERSION="1.9.2" +ENV YAPI_VERSION="1.9.3" ENV YAPI_HOME="/yapi" ENV GIT_URL="https://github.com/YMFE/yapi.git" -ENV GIT_MIRROR_URL="https://gitee.com/mirrors/YApi.git" - WORKDIR ${YAPI_HOME} - -COPY config.json . -COPY start.sh . - -RUN apk add --no-cache wget python make git curl -RUN chmod +x start.sh -RUN ret=`curl -s https://api.ip.sb/geoip | grep China | wc -l` && \ - if [ $ret -ne 0 ]; then \ - GIT_URL=${GIT_MIRROR_URL} && npm config set registry https://registry.npm.taobao.org; \ - fi; +RUN apk add --no-cache wget python3 make git curl RUN git clone --depth 1 --branch v${YAPI_VERSION} --single-branch ${GIT_URL} vendors - WORKDIR ${YAPI_HOME}/vendors #RUN npm install -g node-gyp yapi-cli -RUN npm install --production - +RUN npm install --production -registry https://registry.npm.taobao.org +WORKDIR ${YAPI_HOME} FROM node:12-alpine - ENV TZ="Asia/Shanghai" -ENV YAPI_VERSION="1.9.2" +ENV YAPI_VERSION="1.9.3" ENV YAPI_HOME="/yapi" -ENV YAPI_PORT="3000" ENV ADMIN_EMAIL="master@simaek.com" -ENV DB_HOST="mongo" +ENV DB_HOST="127.0.0.1" ENV DB_NAME="yapi" ENV DB_PORT="27017" ENV MAIL_ENABLE="false" -ENV MAIL_HOST="127.0.0.1" -ENV MAIL_PORT="465" -ENV MAIL_FROM="master@simaek.com" -ENV MAIL_USER="user" -ENV MAIL_PWD="password" - +ENV MAIL_HOST="" +ENV MAIL_PORT="" +ENV MAIL_FROM="" +ENV MAIL_USER="" +ENV MAIL_PWD="" WORKDIR ${YAPI_HOME} - COPY --from=builder /yapi . - -EXPOSE ${YAPI_PORT} -#ENTRYPOINT ["node", "server/app.js"] -ENTRYPOINT ["sh", "start.sh"] \ No newline at end of file +COPY entrypoint.sh / +RUN chmod +x /entrypoint.sh +EXPOSE 3000 +ENTRYPOINT ["/entrypoint.sh"] diff --git a/config.json b/config.json deleted file mode 100644 index 261444e..0000000 --- a/config.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "port": "YAPI_PORT", - "adminAccount": "ADMIN_EMAIL", - "db": { - "servername": "DB_HOST", - "DATABASE": "DB_NAME", - "port": "DB_PORT" - }, - "mail": { - "enable": "MAIL_ENABLE", - "host": "MAIL_HOST", - "port": "MAIL_PORT", - "from": "MAIL_FROM", - "auth": { - "user": "MAIL_USER", - "pass": "MAIL_PWD" - } - } -} \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 2145875..c5a6b73 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,29 +4,21 @@ services: mongo: image: mongo:2.8.0 container_name: mongo - # restart: always + restart: always # volumes: # - ~/data/yapi/mongodb:/data/db #db dir networks: - backend # yapi server yapi: - image: simaek/yapi:latest -# build: ./ + image: yapi:latest + build: ./ container_name: yapi environment: - - YAPI_PORT=3000 - ADMIN_EMAIL=master@simaek.com - DB_HOST=mongo - DB_NAME=yapi - - DB_PORT=27017 - - MAIL_ENABLE=false - - MAIL_HOST=127.0.0.1 - - MAIL_PORT=465 - - MAIL_FROM=master@simaek.com - - MAIL_USER=master - - MAIL_PWD=master - # restart: always + restart: always ports: - 3000:3000 # volumes: diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..a53f7da --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env sh + +cd ${YAPI_HOME} + +# configure with environment variables +cat << EOF > config.json +{ + "port": 3000, + "adminAccount": "${ADMIN_EMAIL}", + "db": { + "servername": "${DB_HOST}", + "DATABASE": "${DB_NAME}", + "port": ${DB_PORT} + }, + "mail": { + "enable": "${MAIL_ENABLE}", + "host": "${MAIL_HOST}", + "port": "${MAIL_PORT}", + "from": "${MAIL_FROM}", + "auth": { + "user": "${MAIL_USER}", + "pass": "${MAIL_PASS}" + } + } +} +EOF + +cd ${YAPI_HOME}/vendors +if [ ! -e "init.lock" ] +then + # yapi install -v ${YAPI_VERSION} + npm run install-server + touch init.lock +fi + +cd ${YAPI_HOME}/vendors + +if [ $1 ] +then + node $i +else + node server/app.js +fi diff --git a/start.sh b/start.sh deleted file mode 100644 index e7cb780..0000000 --- a/start.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env sh - -cd ${YAPI_HOME}/vendors - -if [ ! -e "init.lock" ] -then - sed -i "s/YAPI_PORT/${YAPI_PORT}/g" config.json - sed -i "s/ADMIN_EMAIL/${ADMIN_EMAIL}/g" config.json - sed -i "s/DB_HOST/${DB_HOST}/g" config.json - sed -i "s/DB_NAME/${DB_NAME}/g" config.json - sed -i "s/DB_PORT/${DB_PORT}/g" config.json - sed -i "s/\"MAIL_ENABLE\"/${MAIL_ENABLE}/g" config.json - sed -i "s/MAIL_HOST/${MAIL_HOST}/g" config.json - sed -i "s/MAIL_PORT/${MAIL_PORT}/g" config.json - sed -i "s/MAIL_FROM/${MAIL_FROM}/g" config.json - sed -i "s/MAIL_USER/${MAIL_USER}/g" config.json - sed -i "s/MAIL_PWD/${MAIL_PWD}/g" config.json - # yapi install -v ${YAPI_VERSION} - npm run install-server - touch init.lock -fi - -cd ${YAPI_HOME}/vendors - -if [ $1 ] -then - node $i -else - node server/app.js -fi \ No newline at end of file