build: 使用dockerfile构建docker镜像
Some checks failed
deploy to server / build-and-deploy (push) Has been cancelled
Some checks failed
deploy to server / build-and-deploy (push) Has been cancelled
- 添加dockerfile,基于node:22-alpine构建docker镜像 - 完善相关README文档
This commit is contained in:
58
.dockerignore
Normal file
58
.dockerignore
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
# ------------------------
|
||||||
|
# Node / Package Manager
|
||||||
|
# ------------------------
|
||||||
|
node_modules
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
pnpm-debug.log*
|
||||||
|
.pnpm-store
|
||||||
|
|
||||||
|
# Nuxt build outputs
|
||||||
|
.output
|
||||||
|
.nuxt
|
||||||
|
dist
|
||||||
|
.cache
|
||||||
|
.unimport
|
||||||
|
.h3
|
||||||
|
.nitro
|
||||||
|
**/.nitro
|
||||||
|
|
||||||
|
# Dev tools / OS files
|
||||||
|
.DS_Store
|
||||||
|
Thumbs.db
|
||||||
|
|
||||||
|
# Logs
|
||||||
|
*.log
|
||||||
|
logs
|
||||||
|
!.gitkeep
|
||||||
|
|
||||||
|
# Local env files (runtime env should be provided by Docker/K8s)
|
||||||
|
.env
|
||||||
|
.env.*
|
||||||
|
!.env.example
|
||||||
|
|
||||||
|
# Git
|
||||||
|
.git
|
||||||
|
.gitignore
|
||||||
|
.gitattributes
|
||||||
|
|
||||||
|
# Editor / IDE
|
||||||
|
.vscode
|
||||||
|
.idea
|
||||||
|
*.swp
|
||||||
|
*.swo
|
||||||
|
|
||||||
|
# Tests
|
||||||
|
coverage
|
||||||
|
*.lcov
|
||||||
|
|
||||||
|
# Docker
|
||||||
|
Dockerfile*
|
||||||
|
docker-compose.yml
|
||||||
|
|
||||||
|
# CI / Local build artifacts
|
||||||
|
*.tgz
|
||||||
|
*.zip
|
||||||
|
*.tar
|
||||||
|
*.mdx
|
||||||
41
Dockerfile
Normal file
41
Dockerfile
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
-------- Base image --------
|
||||||
|
FROM node:22-alpine AS base
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# -------- Dependencies layer -------
|
||||||
|
FROM base AS deps
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
RUN corepack enable
|
||||||
|
|
||||||
|
# Copy package.json and lockfile
|
||||||
|
COPY package.json pnpm-lock.yaml .npmrc ./
|
||||||
|
|
||||||
|
# Install dependencies with cache
|
||||||
|
RUN --mount=type=cache,target=/root/.local/share/pnpm/store pnpm install
|
||||||
|
|
||||||
|
# -------- Build layer -------
|
||||||
|
FROM deps AS build
|
||||||
|
# Copy entire project
|
||||||
|
COPY . ./
|
||||||
|
|
||||||
|
ENV NITRO_PRESET=node-server
|
||||||
|
|
||||||
|
# Build the project
|
||||||
|
RUN pnpm run build
|
||||||
|
|
||||||
|
# ------- Runtime layer -------
|
||||||
|
FROM base AS runtime
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# COPY .output folder
|
||||||
|
COPY --from=build /app/.output ./
|
||||||
|
|
||||||
|
ENV PORT=3000
|
||||||
|
ENV NITRO_PRESET=node-server
|
||||||
|
ENV HOST=0.0.0.0
|
||||||
|
|
||||||
|
EXPOSE 3000
|
||||||
|
|
||||||
|
CMD ["node", "/app/server/index.mjs"]
|
||||||
27
README.md
27
README.md
@ -58,9 +58,12 @@ pnpm run dev
|
|||||||
|
|
||||||
项目用到以下环境变量,请自行在项目中配置
|
项目用到以下环境变量,请自行在项目中配置
|
||||||
|
|
||||||
- 'DIRECTUS_URL': 后端Directus服务URL
|
> [!NOTE]
|
||||||
- 'DIRECTUS_TOKEN': Directus服务的API Token
|
>
|
||||||
- 'MEILI_HOST': Meilsearch服务地址
|
> - NUXT_PUBLIC_DIRECTUS_URL: 后端Directus服务URL
|
||||||
|
> - NUXT_PUBLIC_DIRECTUS_TOKEN: 后端Directus服务的API Token
|
||||||
|
> - MEILI_HOST: Meilisearch服务地址
|
||||||
|
> - MEILI_SEARCH_KEY: MeilisearchKey
|
||||||
|
|
||||||
## 构建与部署
|
## 构建与部署
|
||||||
|
|
||||||
@ -81,3 +84,21 @@ pnpm run preview
|
|||||||
2. 部署
|
2. 部署
|
||||||
|
|
||||||
部署构建后的项目并推送到文件服务器中,具体步骤视服务器配置而定
|
部署构建后的项目并推送到文件服务器中,具体步骤视服务器配置而定
|
||||||
|
|
||||||
|
## Dockerfile部署
|
||||||
|
|
||||||
|
1. 构建Docker镜像
|
||||||
|
|
||||||
|
在项目根目录执行docker build
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker build -t jinshen-website .
|
||||||
|
```
|
||||||
|
|
||||||
|
2. 运行docker容器
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run --name <container-name> jinshen-website
|
||||||
|
```
|
||||||
|
|
||||||
|
网站默认在3000端口开放
|
||||||
|
|||||||
Reference in New Issue
Block a user