Providers
Koyeb
将 Nitro 应用部署到 Koyeb。
预设:koyeb
¥Preset: koyeb
使用控制面板
¥Using the control panel
- 在 Koyeb 控制面板 中,点击“创建应用”。
- 选择 GitHub 作为你的部署方法。
- 选择包含你的应用代码的 GitHub 存储库和分支。
- 命名你的服务。
- 如果你没有在
package.json
文件中添加start
命令,请在“构建和部署”设置下,切换与运行命令字段关联的覆盖开关。在“运行命令”字段中,输入:node .output/server/index.mjs`
- 在“高级”部分,点击“添加变量”,然后添加一个设置为
koyeb
的NITRO_PRESET
变量。 - 命名应用。
- 点击“部署”按钮。
使用 Koyeb CLI
¥Using the Koyeb CLI
- 请按照说明,使用安装程序将你的操作系统升级到 安装 Koyeb CLI 客户端。或者,访问 GitHub 上的发布页面 直接下载所需文件。
- 通过 Koyeb 控制面板中的 你组织的 API 设置 创建 Koyeb API 访问令牌。
- 使用 Koyeb CLI 输入以下命令登录你的账户:
koyeb login
出现提示时粘贴你的 API 凭据。 - 使用以下命令从 GitHub 存储库部署你的 Nitro 应用。请务必使用你自己的值替换
<APPLICATION_NAME>
、<YOUR_GITHUB_USERNAME>
和<YOUR_REPOSITORY_NAME>
:koyeb app init <APPLICATION_NAME> \ --git github.com/<YOUR_GITHUB_USERNAME>/<YOUR_REPOSITORY_NAME> \ --git-branch main \ --git-run-command "node .output/server/index.mjs" \ --ports 3000:http \ --routes /:3000 \ --env PORT=3000 \ --env NITRO_PRESET=koyeb
使用 Docker 容器
¥Using a docker container
- 在项目根目录中创建一个
.dockerignore
文件,并添加以下行:Dockerfile .dockerignore node_modules npm-debug.log .nitro .output .git dist README.md
- 将
Dockerfile
添加到项目根目录:FROM node:18-alpine AS base FROM base AS deps RUN apk add --no-cache libc6-compat WORKDIR /app COPY package.json package-lock.json ./ RUN npm ci FROM base AS builder WORKDIR /app COPY --from=deps /app/node_modules ./node_modules COPY . . RUN npm run build && npm cache clean --force FROM base AS runner WORKDIR /app RUN addgroup --system --gid 1001 nodejs RUN adduser --system --uid 1001 nitro COPY --from=builder /app . USER nitro EXPOSE 3000 ENV PORT 3000 CMD ["npm", "run", "start"]
上面的 Dockerfile 提供了运行 Nitro 应用的最低要求。你可以根据需要轻松扩展它。然后,你需要将 Docker 镜像推送到镜像仓库。例如,你可以使用 Docker Hub 或 GitHub 容器注册表。在 Koyeb 控制面板中,使用镜像和标签字段指定要部署的镜像。你还可以使用 Koyeb CLI 函数。有关更多信息,请参阅 Koyeb Docker 文档。
¥The Dockerfile above provides the minimum requirements to run the Nitro application. You can easily extend it depending on your needs. You will then need to push your Docker image to a registry. You can use Docker Hub or GitHub Container Registry for example. In the Koyeb control panel, use the image and the tag field to specify the image you want to deploy. You can also use the Koyeb CLI Refer to the Koyeb Docker documentation for more information.