繁体   English   中英

Google 云函数部署:EROFS:只读文件系统

[英]Google Clould Functions deploy: EROFS: read-only file system

我正在尝试将我的 api 部署到 Google Cloud Functions,我得到了这个:

EROFS:只读文件系统,mkdir '/user_code/uploads'

⚠  functions[post]: Deployment error. Function load error: 
    Code in file index.js can't be loaded. Is there a syntax error in your code? 
    Detailed stack trace: Error: EROFS: read-only file system, mkdir '/user_code/uploads'
    at Error (native)
    at Object.fs.mkdirSync (fs.js:932:18)
    at Function.sync (/user_code/node_modules/multer/node_modules/mkdirp/index.js:71:13)
    at new DiskStorage (/user_code/node_modules/multer/storage/disk.js:21:12)
    at module.exports (/user_code/node_modules/multer/storage/disk.js:65:10)
    at new Multer (/user_code/node_modules/multer/index.js:15:20)
    at multer (/user_code/node_modules/multer/index.js:95:12)
    at Object.<anonymous> (/user_code/api/user.js:105:46)
    at Module._compile (module.js:577:32)
    at Object.Module._extensions..js (module.js:586:10)

Cloud Functions 运行时中的所有内容都是只读的,除了os.tmpdir() (可能是/tmp ,但您不应该假设)。 如果您有任何代码(例如在api/user.js中)尝试在其他任何地方编写代码,则会出错。

python的同样问题,上面的答案对我有用,但为了清楚起见。 我的错误——

File "/env/local/lib/python3.7/site-packages/google/cloud/storage/blob.py", line 753, in download_to_filename
    with open(filename, "wb") as file_obj:
OSError: [Errno 30] Read-only file system: 'testFile.zip'

可以在此处找到Google 的文档。

虽然 Cloud Storage 是在 App Engine 中读取和写入文件的推荐解决方案,但如果您的应用程序只需要写入临时文件,您可以使用标准 Python 3.7 方法将文件写入名为 /tmp 的目录。

此目录中的所有文件都存储在实例的 RAM 中,因此写入 /tmp 会占用系统内存。 此外,/tmp 目录中的文件仅对创建这些文件的应用程序实例可用。 当实例被删除时,临时文件也被删除。

Gen1 云函数是只读系统,而 Gen2 云函数不是。 我建议将您的 function 更改为 Gen2(小心,这可能会干扰其他配置,因为 gen 2 可被视为云运行)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM