From 4c23357d2a9770333443ba7c117e8c203055692f Mon Sep 17 00:00:00 2001 From: liqingwei Date: Sun, 28 Mar 2021 13:19:18 +0800 Subject: [PATCH] refactor: docker file --- Dockerfile | 38 ++++++++++-------------------- README.md | 32 ++++++++++++++++++------- libs/server/middlewares/session.ts | 5 +++- 3 files changed, 40 insertions(+), 35 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0e264e0..b2ba2b3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,40 +1,28 @@ -# Install dependencies only when needed -FROM node:alpine AS deps -# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. -RUN apk add --no-cache libc6-compat +# Stage 1: Building the code +FROM mhart/alpine-node AS builder + WORKDIR /app + COPY package.json yarn.lock ./ + RUN yarn install --frozen-lockfile -# Rebuild the source code only when needed -FROM node:alpine AS builder -WORKDIR /app COPY . . -COPY --from=deps /app/node_modules ./node_modules -RUN yarn build -# Production image, copy all the files and run next -FROM node:alpine AS runner +RUN yarn build +RUN yarn install --production --frozen-lockfile + + +# Stage 2: And then copy over node_modules, etc from that stage to the smaller base image +FROM mhart/alpine-node:base as production + WORKDIR /app -ENV NODE_ENV production - -# You only need to copy next.config.js if you are NOT using the default configuration -# COPY --from=builder /app/next.config.js ./ +# COPY package.json next.config.js .env* ./ COPY --from=builder /app/public ./public COPY --from=builder /app/.next ./.next COPY --from=builder /app/node_modules ./node_modules -RUN addgroup -g 1001 -S nodejs -RUN adduser -S nextjs -u 1001 -RUN chown -R nextjs:nodejs /app/.next -USER nextjs - EXPOSE 3000 -# Next.js collects completely anonymous telemetry data about general usage. -# Learn more here: https://nextjs.org/telemetry -# Uncomment the following line in case you want to disable telemetry. -# RUN npx next telemetry disable - CMD ["node_modules/.bin/next", "start"] diff --git a/README.md b/README.md index 0a5a596..c843765 100644 --- a/README.md +++ b/README.md @@ -76,17 +76,31 @@ STORE_END_POINT=http://oss-cn-hangzhou.aliyuncs.com STORE_REGION=oss-cn-hangzhou ``` +### Tencent COS + +`.env` + +```sh +STORE_TYPE=AWS +STORE_ACCESS_KEY= +STORE_SECRET_KEY= +STORE_BUCKET=notea +STORE_END_POINT=https://cos.ap-guangzhou.myqcloud.com +STORE_REGION=ap-guangzhou +``` + ## Environment variables -| Name | Description | Default | Optional | Required | -| ---------------- | ---------------------------- | --------- | --------------------- | -------- | -| PASSWORD | password to login to the app | | | true | -| STORE_TYPE | storage service | | `MINIO`, `OSS`, `AWS` | true | -| STORE_ACCESS_KEY | accessKey | | | true | -| STORE_SECRET_KEY | secretKey | | | true | -| STORE_BUCKET | bucket | | | true | -| STORE_END_POINT | host name or an IP address. | | | | -| STORE_REGION | region | us-east-1 | | | +| Name | Description | Default | Optional | Required | +| ---------------- | ------------------------------ | --------- | --------------------- | -------- | +| PASSWORD | password to login to the app | | | true | +| STORE_TYPE | storage service | | `MINIO`, `OSS`, `AWS` | true | +| STORE_ACCESS_KEY | accessKey | | | true | +| STORE_SECRET_KEY | secretKey | | | true | +| STORE_BUCKET | bucket | | | true | +| STORE_END_POINT | host name or an IP address. | | | | +| STORE_REGION | region | us-east-1 | | | +| COOKIE_SECURE | only works under https: scheme | true | | | ## Development diff --git a/libs/server/middlewares/session.ts b/libs/server/middlewares/session.ts index d914145..7bc88b0 100644 --- a/libs/server/middlewares/session.ts +++ b/libs/server/middlewares/session.ts @@ -7,7 +7,10 @@ const sessionOptions = { password: md5('notea' + getEnv('PASSWORD')), // if your localhost is served on http:// then disable the secure flag cookieOptions: { - secure: process.env.NODE_ENV === 'production', + secure: getEnv( + 'COOKIE_SECURE', + process.env.NODE_ENV === 'production' + ), }, }