收藏
回答

云托管部署报错是什么原因?

只要写上const OpenAI = require('openai');就会报错

package.json也已经写了依赖

这是index.js完整代码

const Koa = require("koa");

const Router = require("koa-router");

const logger = require("koa-logger");

const bodyParser = require("koa-bodyparser");

const fs = require("fs");

const path = require("path");

const axios = require('axios');

const cors = require('koa2-cors');

const { PassThrough } = require('stream');

const OpenAI = require('openai');

const {

init: initDB,

Counter

} = require("./db");


const router = new Router();


const homePage = fs.readFileSync(path.join(__dirname, "index.html"), "utf-8");


const openai = new OpenAI({

apiKey: '',

baseURL: 'https://ark.cn-beijing.volces.com/api/v3',

});

router.get("/api/douyin", async (ctx) => {

ctx.set('Content-Type', 'text/event-stream');

ctx.set('Cache-Control', 'no-cache');

ctx.set('Connection', 'keep-alive');

const stream = new PassThrough();

ctx.body = stream;


// 获取前端传递的用户输入

const userMessage = ctx.query.message || '默认用户消息';

// Streaming:

console.log('----- streaming request -----');

const aiStream = await openai.chat.completions.create({

messages: JSON.parse(userMessage),

model: 'ep-20241120160801-7tnrg',

stream: true,

});


for await (const part of aiStream) {

console.log(part.choices[0]);

stream.write(`data: ${JSON.stringify(part)}\n\n`);

}

})

docketile文件代码

# 二开推荐阅读[如何提高项目构建效率](https://developers.weixin.qq.com/miniprogram/dev/wxcloudrun/src/scene/build/speed.html)

FROM alpine:3.13


# 容器默认时区为UTC,如需使用上海时间请启用以下时区设置命令

# RUN apk add tzdata && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo Asia/Shanghai > /etc/timezone


# 使用 HTTPS 协议访问容器云调用证书安装

RUN apk add ca-certificates


# 安装依赖包,如需其他依赖包,请到alpine依赖包管理(https://pkgs.alpinelinux.org/packages?name=php8*imagick*&branch=v3.13)查找。

RUN apk add --update --no-cache nodejs npm


# # 指定工作目录

WORKDIR /app


# 拷贝包管理文件

COPY package*.json /app


# npm 源,选用国内镜像源以提高下载速度

RUN npm config set registry https://mirrors.cloud.tencent.com/npm/

# RUN npm config set registry https://registry.npm.taobao.org/


# npm 安装依赖

RUN npm install


# 将当前目录(dockerfile所在目录)下所有文件都拷贝到工作目录下(.gitignore中的文件除外)

COPY . /app


# 执行启动命令.

# 写多行独立的CMD命令是错误写法!只有最后一行CMD命令会被执行,之前的都会被忽略,导致业务报错。

# 请参考[Docker官方文档之CMD命令](https://docs.docker.com/engine/reference/builder/#cmd)

CMD ["npm", "start"]



[2024-11-22 12:20:39] Started by user coding

[2024-11-22 12:20:39] Running in Durability level: MAX_SURVIVABILITY

[2024-11-22 12:20:41] [Pipeline] Start of Pipeline

[2024-11-22 12:20:41] [Pipeline] node

[2024-11-22 12:20:41] Running on Jenkins in /root/workspace

[2024-11-22 12:20:41] [Pipeline] {

[2024-11-22 12:20:41] [Pipeline] stage

[2024-11-22 12:20:41] [Pipeline] { (检出软件包)

[2024-11-22 12:20:41] Stage "检出软件包" skipped due to when conditional

[2024-11-22 12:20:41] [Pipeline] }

[2024-11-22 12:20:41] [Pipeline] // stage

[2024-11-22 12:20:41] [Pipeline] stage

[2024-11-22 12:20:41] [Pipeline] { (检出 ZIP 包)

[2024-11-22 12:20:41] Stage "检出 ZIP 包" skipped due to when conditional

[2024-11-22 12:20:41] [Pipeline] }

[2024-11-22 12:20:41] [Pipeline] // stage

[2024-11-22 12:20:41] [Pipeline] stage

[2024-11-22 12:20:41] [Pipeline] { (检出代码仓库)

[2024-11-22 12:20:42] [Pipeline] sh

[2024-11-22 12:20:42] + git clone ****** .

[2024-11-22 12:20:42] Cloning into '.'...

[2024-11-22 12:20:50] [Pipeline] sh

[2024-11-22 12:20:50] + git checkout master

[2024-11-22 12:20:50] Already on 'master'

[2024-11-22 12:20:50] Your branch is up to date with 'origin/master'.

[2024-11-22 12:20:50] [Pipeline] }

[2024-11-22 12:20:50] [Pipeline] // stage

[2024-11-22 12:20:50] [Pipeline] stage

[2024-11-22 12:20:50] [Pipeline] { (写入 dockerfile)

[2024-11-22 12:20:50] Stage "写入 dockerfile" skipped due to when conditional

[2024-11-22 12:20:50] [Pipeline] }

[2024-11-22 12:20:50] [Pipeline] // stage

[2024-11-22 12:20:50] [Pipeline] stage

[2024-11-22 12:20:50] [Pipeline] { (构建 Docker 镜像)

[2024-11-22 12:20:50] [Pipeline] sh

[2024-11-22 12:20:51] + docker login -u ****** -p ****** ccr.ccs.tencentyun.com/tcb-******-cclm/ca-goytyvue_koa-oass:koa-oass-024-20241122122036

[2024-11-22 12:20:51] WARNING! Using --password via the CLI is insecure. Use --password-stdin.

[2024-11-22 12:20:51] WARNING! Your password will be stored unencrypted in /root/.docker/config.json.

[2024-11-22 12:20:51] Configure a credential helper to remove this warning. See

[2024-11-22 12:20:51] https://docs.docker.com/engine/reference/commandline/login/#credentials-store

[2024-11-22 12:20:51]

[2024-11-22 12:20:51] Login Succeeded

[2024-11-22 12:20:51] [Pipeline] sh

[2024-11-22 12:20:51] + docker build -f ././/Dockerfile -t ccr.ccs.tencentyun.com/tcb-******-cclm/ca-goytyvue_koa-oass:koa-oass-024-20241122122036 ./

[2024-11-22 12:20:52 #0 building with "default" instance using docker driver

[2024-11-22 12:20:52]

[2024-11-22 12:20:52 #1 [internal] load build definition from Dockerfile

[2024-11-22 12:20:52 #1 transferring dockerfile: 1.40kB done

[2024-11-22 12:20:52 #1 DONE 0.1s

[2024-11-22 12:20:52]

[2024-11-22 12:20:52 #2 [internal] load .dockerignore

[2024-11-22 12:20:52 #2 transferring context: 2B done

[2024-11-22 12:20:52 #2 DONE 0.1s

[2024-11-22 12:20:52]

[2024-11-22 12:20:52 #3 [internal] load metadata for docker.io/library/alpine:3.13

[2024-11-22 12:20:53 #3 DONE 1.1s

[2024-11-22 12:20:53]

[2024-11-22 12:20:53 #4 [1/8] FROM docker.io/library/alpine:3.13@sha256:469b6e04ee185740477efa44ed5bdd64a07bbdd6c7e5f5d169e540889597b911

[2024-11-22 12:20:53 #4 resolve docker.io/library/alpine:3.13@sha256:469b6e04ee185740477efa44ed5bdd64a07bbdd6c7e5f5d169e540889597b911 0.1s done

[2024-11-22 12:20:53 #4 sha256:469b6e04ee185740477efa44ed5bdd64a07bbdd6c7e5f5d169e540889597b911 1.64kB / 1.64kB done

[2024-11-22 12:20:53 #4 sha256:16fd981ddc557fd3b38209d15e7ee8e3e6d9d4d579655e8e47243e2c8525b503 528B / 528B done

[2024-11-22 12:20:53 #4 sha256:6b5c5e00213a401b500630fd8a03f6964f033ef0e3a6845c83e780fcd5deda5c 1.47kB / 1.47kB done

[2024-11-22 12:20:53 #4 sha256:72cfd02ff4d01b1f319eed108b53120dea0185b916d2abeb4e6121879cbf7a65 0B / 2.83MB 0.1s

[2024-11-22 12:20:54 #4 sha256:72cfd02ff4d01b1f319eed108b53120dea0185b916d2abeb4e6121879cbf7a65 2.83MB / 2.83MB 0.4s

[2024-11-22 12:20:54 #4 extracting sha256:72cfd02ff4d01b1f319eed108b53120dea0185b916d2abeb4e6121879cbf7a65 0.1s done

[2024-11-22 12:20:54 #4 sha256:72cfd02ff4d01b1f319eed108b53120dea0185b916d2abeb4e6121879cbf7a65 2.83MB / 2.83MB 0.4s done

[2024-11-22 12:20:54 #4 DONE 0.7s

[2024-11-22 12:20:54]

[2024-11-22 12:20:54 #5 [internal] load build context

[2024-11-22 12:20:54 #5 transferring context: 73.02MB 0.8s done

[2024-11-22 12:20:54 #5 DONE 0.9s

[2024-11-22 12:20:54]

[2024-11-22 12:20:54 #6 [2/8] RUN apk add ca-certificates

[2024-11-22 12:20:54 #6 0.214 fetch https://dl-cdn.alpinelinux.org/alpine/v3.13/main/x86_64/APKINDEX.tar.gz

[2024-11-22 12:20:54 #6 0.747 fetch https://dl-cdn.alpinelinux.org/alpine/v3.13/community/x86_64/APKINDEX.tar.gz

[2024-11-22 12:20:55 #6 1.223 (1/1) Installing ca-certificates (20220614-r0)

[2024-11-22 12:20:55 #6 1.269 Executing busybox-1.32.1-r9.trigger

[2024-11-22 12:20:55 #6 1.272 Executing ca-certificates-20220614-r0.trigger

[2024-11-22 12:20:55 #6 1.301 OK: 6 MiB in 15 packages

[2024-11-22 12:20:55 #6 DONE 1.6s

[2024-11-22 12:20:55]

[2024-11-22 12:20:55 #7 [3/8] RUN apk add --update --no-cache nodejs npm

[2024-11-22 12:20:56 #7 0.317 fetch https://dl-cdn.alpinelinux.org/alpine/v3.13/main/x86_64/APKINDEX.tar.gz

[2024-11-22 12:20:56 #7 0.585 fetch https://dl-cdn.alpinelinux.org/alpine/v3.13/community/x86_64/APKINDEX.tar.gz

[2024-11-22 12:20:56 #7 0.769 (1/7) Installing nghttp2-libs (1.42.0-r1)

[2024-11-22 12:20:56 #7 0.802 (2/7) Installing brotli-libs (1.0.9-r3)

[2024-11-22 12:20:56 #7 0.840 (3/7) Installing c-ares (1.17.2-r0)

[2024-11-22 12:20:56 #7 0.872 (4/7) Installing libgcc (10.2.1_pre1-r3)

[2024-11-22 12:20:56 #7 0.905 (5/7) Installing libstdc++ (10.2.1_pre1-r3)

[2024-11-22 12:20:56 #7 0.946 (6/7) Installing nodejs (14.20.1-r0)

[2024-11-22 12:20:57 #7 1.392 (7/7) Installing npm (14.20.1-r0)

[2024-11-22 12:20:57 #7 1.703 Executing busybox-1.32.1-r9.trigger

[2024-11-22 12:20:57 #7 1.708 OK: 71 MiB in 22 packages

[2024-11-22 12:20:57 #7 DONE 1.8s

[2024-11-22 12:20:57]

[2024-11-22 12:20:57 #8 [4/8] WORKDIR /app

[2024-11-22 12:20:57 #8 DONE 0.2s

[2024-11-22 12:20:57]

[2024-11-22 12:20:57 #9 [5/8] COPY package*.json /app

[2024-11-22 12:20:57 #9 DONE 0.1s

[2024-11-22 12:20:57]

[2024-11-22 12:20:57 #10 [6/8] RUN npm config set registry https://mirrors.cloud.tencent.com/npm/

[2024-11-22 12:20:58 #10 DONE 0.4s

[2024-11-22 12:20:58]

[2024-11-22 12:20:58 #11 [7/8] RUN npm install

[2024-11-22 12:20:58 #11 0.751 npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion@1, but package-lock.json was generated for lockfileVersion@3. I'll try to do my best with it!

[2024-11-22 12:20:59 #11 1.292 npm WARN deprecated koa-router@10.1.1: **IMPORTANT 10x+ PERFORMANCE UPGRADE**: Please upgrade to v12.0.1+ as we have fixed an issue with debuglog causing 10x slower router benchmark performance, see https://github.com/koajs/router/pull/173

[2024-11-22 12:21:04 #11 6.543 npm WARN wxcloudrun-koa@1.0.0 No repository field.

[2024-11-22 12:21:04 #11 6.544

[2024-11-22 12:21:04 #11 6.545 added 147 packages from 200 contributors and audited 147 packages in 5.825s

[2024-11-22 12:21:04 #11 6.595

[2024-11-22 12:21:04 #11 6.595 17 packages are looking for funding

[2024-11-22 12:21:04 #11 6.595 run `npm fund` for details

[2024-11-22 12:21:04 #11 6.595

[2024-11-22 12:21:04 #11 6.596 found 5 vulnerabilities (2 moderate, 1 high, 2 critical)

[2024-11-22 12:21:04 #11 6.596 run `npm audit fix` to fix them, or `npm audit` for details

[2024-11-22 12:21:04 #11 DONE 6.8s

[2024-11-22 12:21:04]

[2024-11-22 12:21:04 #12 [8/8] COPY . /app

[2024-11-22 12:21:05 #12 DONE 0.6s

[2024-11-22 12:21:05]

[2024-11-22 12:21:05 #13 exporting to image

[2024-11-22 12:21:05 #13 exporting layers

[2024-11-22 12:21:06 #13 exporting layers 0.7s done

[2024-11-22 12:21:06 #13 writing image sha256:4a5ebe5d9f58db3a45f45a4b3a4842c65a7b04477ae1dbd2d2d2d9a48855e3f4 done

[2024-11-22 12:21:06 #13 naming to ccr.ccs.tencentyun.com/tcb-******-cclm/ca-goytyvue_koa-oass:koa-oass-024-20241122122036 done

[2024-11-22 12:21:06 #13 DONE 0.7s

[2024-11-22 12:21:06] [Pipeline] }

[2024-11-22 12:21:06] [Pipeline] // stage

[2024-11-22 12:21:06] [Pipeline] stage

[2024-11-22 12:21:06] [Pipeline] { (推送 Docker 镜像到 TCR)

[2024-11-22 12:21:06] [Pipeline] sh

[2024-11-22 12:21:06] + docker push ccr.ccs.tencentyun.com/tcb-******-cclm/ca-goytyvue_koa-oass:koa-oass-024-20241122122036

[2024-11-22 12:21:06] The push refers to repository [ccr.ccs.tencentyun.com/tcb-******-cclm/ca-goytyvue_koa-oass]

[2024-11-22 12:21:06] 63a6ea71939b: Preparing

[2024-11-22 12:21:06] 3939b7e44f93: Preparing

[2024-11-22 12:21:06] d43a2a7c1b91: Preparing

[2024-11-22 12:21:06] 0dc12778368a: Preparing

[2024-11-22 12:21:06] 058689fe2b3d: Preparing

[2024-11-22 12:21:06] 54a29fc9b264: Preparing

[2024-11-22 12:21:06] 79aadad60446: Preparing

[2024-11-22 12:21:06] 7df5bd7bd262: Preparing

[2024-11-22 12:21:06] 7df5bd7bd262: Layer already exists

[2024-11-22 12:21:07] 058689fe2b3d: Pushed

[2024-11-22 12:21:07] d43a2a7c1b91: Pushed

[2024-11-22 12:21:07] 0dc12778368a: Pushed

[2024-11-22 12:21:09] 79aadad60446: Pushed

[2024-11-22 12:21:15] 3939b7e44f93: Pushed

[2024-11-22 12:21:16] 54a29fc9b264: Pushed

[2024-11-22 12:21:20] 63a6ea71939b: Pushed

[2024-11-22 12:21:21] koa-oass-024-20241122122036: digest: sha256:8e8262ed07e730c2ad5ec19c7843d40dcef6b8f0abc54510394fa895c7d87ae4 size: 1998

[2024-11-22 12:21:22] [Pipeline] }

[2024-11-22 12:21:22] [Pipeline] // stage

[2024-11-22 12:21:22] [Pipeline] }

[2024-11-22 12:21:22] [Pipeline] // node

[2024-11-22 12:21:22] [Pipeline] End of Pipeline

[2024-11-22 12:21:22] Finished: SUCCESS

***

-----------构建koa-oass-024-----------

2024-11-22 12:20:38 create_build_image : succ,

2024-11-22 12:21:26 check_build_image : succ, ,

-----------服务koa-oass部署koa-oass-024-----------

2024-11-22 12:21:27 create_eks_virtual_service : succ,

2024-11-22 12:21:27 check_eks_virtual_service : process, DescribeVersion_user_error_Back-off restarting failed container, [service]:[Back-off restarting failed container,]



回答关注问题邀请回答
收藏

1 个回答

  • Alfred Huang
    Alfred Huang
    星期三 10:41

    除了部署日志外,可以看看有没有服务日志打印。

    Back-off restarting failed container 这个错误是容器启动不起来,需要排查是否是引入的包导致的进程启动失败

    星期三 10:41
    有用
    回复
登录 后发表内容