refactor: docker file

This commit is contained in:
liqingwei 2021-03-28 13:19:18 +08:00
parent 8b18706161
commit 4c23357d2a
3 changed files with 40 additions and 35 deletions

View File

@ -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"]

View File

@ -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

View File

@ -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<boolean>(
'COOKIE_SECURE',
process.env.NODE_ENV === 'production'
),
},
}