Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

优化 Dockerfile #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.DS_Store
node_modules
/dist

/tests/e2e/videos/
/tests/e2e/screenshots/

# local env files
.env.local
.env.*.local

# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw*

build/env.js
50 changes: 12 additions & 38 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,50 +1,24 @@
FROM centos:7 as build-stage
# 设置编码
ENV LANG en_US.UTF-8
# 同步时间
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
FROM node:10.18.0-jessie as build-stage

# 1. 安装基本依赖和nginx
RUN yum update -y && yum install epel-release -y && yum update -y && yum install wget nginx git -y
WORKDIR /app

# 2. 准备node
#RUN wget -q -c https://npm.taobao.org/mirrors/node/v10.16.1/node-v10.16.1-linux-x64.tar.xz && tar xf node-v10.16.1-linux-x64.tar.xz -C /usr/local/
RUN wget -q -c https://nodejs.org/dist/v10.16.1/node-v10.16.1-linux-x64.tar.xz && tar xf node-v10.16.1-linux-x64.tar.xz -C /usr/local/

RUN rm -rf /usr/local/bin/node && rm -rf /usr/local/bin/npm \
&& ln -s /usr/local/node-v10.16.1-linux-x64/bin/node /usr/local/bin/node \
&& ln -s /usr/local/node-v10.16.1-linux-x64/bin/node /usr/bin/node \
&& ln -s /usr/local/node-v10.16.1-linux-x64/bin/npm /usr/local/bin/npm \
&& ln -s /usr/local/node-v10.16.1-linux-x64/bin/npm /usr/bin/npm

# 4. 复制代码
RUN mkdir -p /app
ADD . /app

RUN rm -rf /app/node_modules && npm config set registry https://registry.npmjs.org/ \
&& npm cache clean --force \
&& npm install --ignore-script \
&& npm run build

# 1. 安装依赖
COPY package.json .
RUN npm install --ignore-script
# 2. 编译
COPY . /app
RUN npm run build

############################

FROM nginx as production

MAINTAINER "shenshuo<[email protected]>"

RUN mkdir -p /var/www/codo
# 设置编码
ENV LANG en_US.UTF-8
# 同步时间
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

WORKDIR /var/www/codo/

COPY nginx_ops.conf /etc/nginx/conf.d/codo_frontend.conf
COPY --from=build-stage /app/dist /var/www/codo

EXPOSE 80
EXPOSE 443

STOPSIGNAL SIGTERM

CMD ["nginx", "-g", "daemon off;"]