如何在不破坏容器的情况下只推送本地更改?

How to only push local changes without destroying the container?

我已经使用 cf push app-name 将我的应用程序 (PHP Buildpack) 部署到生产环境中。之后,我致力于进一步的功能和错误修复。现在我想将我的本地更改推送到生产中。但是当我这样做时,保存在生产服务器上的所有图像(例如个人资料图像)都会在每次推送时丢失。

如何只接管代码中的更改而不丢失生产服务器上的任何存储文件?

它应该像一个“git pull

您的应用程序容器应该是无状态的。要持久化数据,您应该使用提供的服务。 Swisscom 应用云提供 S3 compatible Dynamic Storage (e.g. for pictures or user avatars) or different database services (MongoDB, MariaDB and others). If you need to save user data, you should save it in one of these services instead of the local filesystem of the app's container. If you keep your app stateless, you can migrate and scale it more easily. You can find more information about how your app should be structured to run in a modern cloud environment here. To get more information about how to use your app with a service, please check this link.

引用自Avoid Writing to the Local File System

Applications running on Cloud Foundry should not write files to the local file system for the following reasons:

Local file system storage is short-lived. When an application instance crashes or stops, the resources assigned to that instance are reclaimed by the platform including any local disk changes made since the app started. When the instance is restarted, the application will start with a new disk image. Although your application can write local files while it is running, the files will disappear after the application restarts.

Instances of the same application do not share a local file system. Each application instance runs in its own isolated container. Thus a file written by one instance is not visible to other instances of the same application. If the files are temporary, this should not be a problem. However, if your application needs the data in the files to persist across application restarts, or the data needs to be shared across all running instances of the application, the local file system should not be used. We recommend using a shared data service like a database or blobstore for this purpose.

将来您的问题将是 "solved" 和 Volume Services (Experimental)。您的应用程序将拥有一个永久性磁盘。

Cloud Foundry application developers may want their applications to mount one or more volumes in order to write to a reliable, non-ephemeral file system. By integrating with service brokers and the Cloud Foundry runtime, providers can offer these services to developers through an automated, self-service, and on-demand user experience.

请订阅我们的时事通讯以获取功能公告。也请关注 CF 社区的上游开发。