简体   繁体   English

将Laravel PHP应用程序部署到开发和生产服务器

[英]Deploy Laravel PHP apps to development and production server

I'm trying to figure out a way to deploy my company intranet PHP apps automatically, using GitLab, but so far, I'm not sure if the options that I've found on the internet will do the job. 我正在尝试找到一种使用GitLab自动部署公司内部网PHP应用程序的方法,但是到目前为止,我不确定我在Internet上找到的选项是否能胜任。

Here's the scenario: 这是场景:

VM1: Remote Git server, that uses GitLab to administrate projects repos. VM1:远程Git服务器,它使用GitLab管理项目存储库。
VM2: Development server. VM2:开发服务器。 Each project has it's own development server. 每个项目都有自己的开发服务器。
VM3: Production server. VM3:生产服务器。 Each project has it's own, as well. 每个项目也都有自己的。
Developers: Each developer uses a vagrant box, based on the project's development server. 开发人员:每个开发人员都根据项目的开发服务器使用一个无聊的盒子。

What I want to do: 我想做的事:

Whenever a developer push it's commits to the development branch, a hook in the remote server must update the development server tree with the last commit on that branch. 每当开发人员将其提交到开发分支时,远程服务器中的钩子都必须使用该分支上的最后提交来更新开发服务器树。

The same must occur when the master branch is updated, but it must update the production server tree. 更新master分支时,必须执行相同的操作,但是必须更新生产服务器树。

However, since we use Laravel, we must run some extra console commands using Artisan, depending on each case. 但是,由于我们使用Laravel,因此必须根据具体情况使用Artisan运行一些额外的控制台命令。

We are following Vincent Driessen's Git Branching Model. 我们正在遵循Vincent Driessen的Git分支模型。

What I know so far: 我到目前为止所知道的:

I know that GitLab uses Web Hooks, but I'm not sure if that's going to work in this case, since I need to access a custom URL, doesn't sound very safe, but if it's the only solution, I can write a script to handle just that. 我知道GitLab使用Web Hooks,但是我不确定在这种情况下是否可以使用,因为我需要访问自定义URL,听起来不是很安全,但是,如果这是唯一的解决方案,我可以编写一个脚本来处理。
The other possible solution is to use Jenkins but I'm not an expert and I don't know yet if Jenkins is too much for my case, since I'm not using unit tests yet. 另一个可能的解决方案是使用Jenkins,但我不是专家,我还不知道Jenkins是否适合我的情况,因为我还没有使用单元测试。

Do you guys have implemented a solution that could help in my case? 你们是否实施了对我的案例有帮助的解决方案? Can anyone suggest an easy and elegant way to do that? 有人可以建议一种简单而优雅的方法吗?

Thanks guys! 多谢你们! Have a nice one 有一个不错的

I would suggest to keep things simple and work with git, hooks and remote repositores. 我建议保持简单,并使用git, hook和远程存储库。 Pulling out heavy guns, like Jenkins or Gitlab for this task could be a bit too much. 拔掉像詹金斯(Jenkins)或吉塔布拉(Gitlab)这样的重炮可能太过分了。

I see your request as the following: "git after push and/or git after merge: push to remote repo". 我看到您的请求如下:“推送后的git和/或合并后的git:推送到远程仓库”。

You could setup "bare" remote repositories - one for "dev-stage", one for "production-stage". 您可以设置“裸机”远程存储库-一个用于“开发阶段”,一个用于“生产阶段”。 Their only purpose is to receive pushes. 它们的唯一目的是接收推送。

Each developer works on his feature-branch, based on the development branch. 每个开发人员都基于开发分支在其功能分支上工作。 When the feature-branch is ready, it is merge back to the main development branch. 功能分支准备就绪后,它将合并回到主开发分支。 Both trigger a "post merge" or "post-receive" hook, which execute a script. 两者都触发执行脚本的“合并后”或“接收后”钩子。 The executed script can do whatever you want. 执行的脚本可以执行您想要的任何操作。

(Same approach for production: When the dev-branch has enough new features, it is merged to prod branch - triggers merge event - scripts...) (相同的生产方法:当开发分支具有足够的新功能时,它将合并到prod分支-触发合并事件-脚本...)

Here you want two things: 在这里,您需要两件事:

  1. You want to push a specific branch to a specific remote repo. 您想将特定分支推送到特定远程仓库。 In order to do this, you have to find out the specific branch in your hook script. 为此,您必须在挂钩脚本中找出特定的分支。 That's tricky, but solveable, see: https://stackoverflow.com/a/13057643/1163786 (writing a "git post-receive hook" to deal with a specific branch) 这很棘手,但可以解决,请参阅: https ://stackoverflow.com/a/13057643/1163786(编写“ git post-receive hook”以处理特定分支)

  2. You want to execute additional steps for configuration/setup, like artisan, etc. You might add these steps directly or as triggers to the hook script. 您想要执行其他用于配置/设置的步骤,例如artisan等。您可以直接将这些步骤添加或作为钩子脚本的触发器添加。

I think this request is related to internal and external deployment via git. 我认为此请求与通过git进行的内部和外部部署有关。 You might also search for tutorials, like "deployment with git", which might be helpful. 您可能还会搜索教程,例如“使用git部署”,这可能会有所帮助。 For example: http://ryanflorence.com/deploying-websites-with-a-tiny-git-hook/ 例如: http : //ryanflorence.com/deploying-websites-with-a-tiny-git-hook/

We do it the following way: 我们通过以下方式进行操作:

  • Developers checkout whatever Git branches, and as many branches as they want/need locally (Debian in VM Ware on Mac) 开发人员签出Git的任何分支,以及他们在本地想要/需要的分支数量(在Mac上的VM Ware中为Debian)

  • All branches get pulled to dev server whenever a change is pushed to Git. 每当将更改推送到Git时,所有分支都将被拉到开发服务器。 They are available in feature-x.dev.domain.com, feature-y.dev.domain.com etc., running against dev database. 它们可在feature-x.dev.domain.com,feature-y.dev.domain.com等中使用,并针对dev数据库运行。

  • Release branches are manually checked out on live system for testing, made available on release-x.test.domain.com etc. against the live database (if possible, depending on migrations). 发行分支是在实时系统上手动检出以进行测试的,可在release-x.test.domain.com等网站上针对实时数据库使用(如果可能,取决于迁移)。

We've semi-automated this using own scripts. 我们使用自己的脚本对此进行了半自动化。

Database changes are made manually, due the sensitivity of their nature. 由于其性质的敏感性,数据库更改是手动进行的。 However, we don't fint that a hassle, after getting used to migrations - and just remembering to note the alterations. 但是,在习惯了迁移之后,我们不会觉得有麻烦,只是记得要记下所做的更改。 We find good support by cloning databases locally for each branch that needs changes. 通过为每个需要更改的分支本地克隆数据库,我们找到了很好的支持。 An automated schema comparison quickly helps then, if changes to a migration file have been forgotten. 如果忘记了对迁移文件的更改,则自动进行模式比较会很快提供帮助。

(The second point is the most productive one, making instant test on the dev platform available to everyone as soon as the first commit of a new branch is pushed) (第二点是最有效的一点,一旦推送新分支的第一次提交,就可以在开发平台上进行即时测试,供所有人使用)

If you prefer to keep things straightforward and don't mind using paid third-party options, check out one of these: 如果您想让事情简单明了并且不介意使用付费的第三方选项,请查看以下选项之一:

Alternatively, if you fancy shifting to an integrated solution, I've not used better than Beanstalk . 另外,如果您想转向集成解决方案,那我不会比Beanstalk更好用。

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

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