简体   繁体   English

在Git提交与用于测试和开发的PHP代码不同的测试环境中,有什么方法可以在项目上工作?

[英]What ways are there to work on a project in a testing environment where the Git commit needs to be different to the PHP code used for testing and dev?

In my project the deployable version needs to have a copy of each of the external libs, a different config file and install and setup files, for security concerns, the main project is set to refuse to run if they are present. 在我的项目中,可部署版本需要具有每个外部库的副本,一个不同的配置文件以及安装和设置文件,出于安全方面的考虑,如果存在主项目,则将其设置为拒绝运行。 Thus the upstream copies of the other projects need to be committed to repo. 因此,其他项目的上游副本需要提交回购。 How can I work on code running on localhost where the file layout and sometimes file contents from dev and testing are different to what I need to commit? 如何在本地主机上运行的代码上工作,在本地主机上,文件布局以及有时来自开发和测试的文件内容与我需要提交的内容不同?

Background 背景

I am working on a project on hosted on github and my main IDE is netbeans which has imperfect git support (good enough for >99% of my needs). 我正在github上托管的一个项目上,我的主要IDE是netbeans,它对git的支持不完善(足以满足我的99%以上的需求)。 The project is in PHP and uses several other projects as libraries. 该项目使用PHP,并使用其他几个项目作为库。

As Netbeans does not have the best support for sub-repos I have chosen to keep each additional project in a separate project. 由于Netbeans对子存储库没有最好的支持,因此我选择将每个其他项目保留在单独的项目中。 This is fine as the central project looks at the config data for where to find these outside libs. 这很好,因为中央项目会在配置数据中查找在何处可以找到这些外部库。

Half an answer 一半答案

My instinct is to suppose that there will need to be some "build stage" prior to committing to the github repo but how on earth do I go about setting all that up? 我的本能是假设在提交github存储库之前需要有一些“构建阶段”,但是到底该如何设置所有这些呢?

I could write some sort of homebrew thing but then when I pull other people's contributions I would need to reverse the process unless we had a branch for builds and a branch for working copies which seems needlessly complex and could leave the dev(s) config data on public display (not to mention updates being a mess). 我可以写一些自制的东西,但是当我拉别人的贡献时,除非我们有一个用于构建的分支和一个用于工作副本的分支,这似乎不必要地复杂,并且可能留下开发配置数据,否则我将需要逆转该过程。在公开展示中(更不用说更新是一团糟了)。

I have seen that others have wrestled with somewhat similar problems to no conclusion (at time of asking) ( How to push and pull from github without sharing sensitive information? Smudge & clean? ) so I am looking for anything that might help me come up with a solution 我已经看到其他人也遇到了一些类似的问题,但都没有得出结论(在提出问题时)( 如何在不共享敏感信息的情况下从github推送和拉取?解决方案

my main IDE is netbeans which has imperfect git support 我的主要IDE是netbeans,它对git的支持不完善

Most devs just use the command line. 大多数开发人员仅使用命令行。 I switch to the NetBeans conflict resolver occasionally, which is very good, but for normal stuff the console is usually faster. 我偶尔会切换到NetBeans冲突解决程序,这非常好,但是对于普通的东西,控制台通常更快。

My instinct is to suppose that there will need to be some "build stage" prior to committing to the github repo 我的本能是假设在提交github存储库之前需要有一些“构建阶段”

... unless we had a branch for builds and a branch for working copies ...除非我们有一个用于构建的分支和一个用于工作副本的分支

No, there is only ever one repository. 不,只有一个存储库。 It is better to think of your repo as your code history, rather than your deployment state. 最好将存储库视为代码历史记录,而不是部署状态。 Branches should just be for features or large changes, which merge into your mainline/master. 分支应该仅用于合并到您的主线/母版中的功能或较大的更改。

There are a good deal of options available to you when deploying. 部署时有很多可用的选项。 The first is Composer, which Mark points out: when deploying you issue an install or update command, which fetches the dependencies that satisfy your library requirements recursively. 第一个是Composer,Mark指出:在部署时,您发出installupdate命令,该命令以递归方式获取满足库要求的依赖项。 You can use Bower to do the same thing for your JavaScript dependencies. 您可以使用Bower对JavaScript依赖项执行相同的操作。

Some deployment strategies prefer to build locally and then scp / rsync to a remote server. 一些部署策略倾向于在本地构建,然后将scp / rsync到远程服务器。 Composer and Bower are still probably a good idea, but you write a build script (using Ant or Phing , for example) to create a build copy in a local temporary folder, and then send it to the server. Composer和Bower可能仍然是一个好主意,但是您编写了一个构建脚本(例如,使用AntPhing )来在本地临时文件夹中创建一个构建副本,然后将其发送到服务器。 It is common here also to push it to a new release folder on the server, and then swap a symlink or Apache config file when it's ready to go live. 在这里也很常见,将其推送到服务器上的新发行版文件夹,然后在其准备就绪时交换符号链接或Apache配置文件。

the deployable version needs to have a copy of each of the external libs, a different config file and install and setup files, for security concerns 出于安全考虑,可部署版本需要具有每个外部库的副本,不同的配置文件以及安装和设置文件

Assuming this is a web project, have you tried adding your sensitive environment data to your Apache configuration file? 假设这是一个Web项目,您是否尝试过将敏感的环境数据添加到Apache配置文件中? This can be trivially read in PHP, and of course PHP does not care that this information is different according to whether you are developing, testing, demoing a branch or operating live. 这可以在PHP中轻松阅读,当然,PHP并不关心此信息是否有所不同,具体取决于您是开发,测试,演示分支还是实时运行。


Further reading: an excellent PHP deployment book , free of charge, that suggests Phing and Capistrano. 进一步阅读:免费的优秀PHP部署书 ,其中建议Phing和Capistrano。

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

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