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

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

问题描述:

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.

Here's the scenario:

VM1: Remote Git server, that uses GitLab to administrate projects repos.
VM2: Development server. Each project has it's own development server.
VM3: Production server. 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.

However, since we use Laravel, we must run some extra console commands using Artisan, depending on each case.

We are following Vincent Driessen's Git Branching Model.

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.
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.

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

我正在尝试使用GitLab自动部署我的公司Intranet PHP应用程序,但到目前为止 ,我不确定我在互联网上找到的选项是否可以完成这项任务。 p>

以下是该场景: h2>

VM1: strong>远程Git服务器,它使用GitLab来管理项目回购。
VM2: strong>开发服务器。 每个项目都有自己的开发服务器。
VM3: strong>生产服务器。 每个项目都有它自己的。
开发人员: strong>每个开发人员都使用一个基于项目开发服务器的流浪盒。 p>

我想做什么: h2>

每当开发人员将其提交到开发分支时,远程服务器中的钩子必须更新开发服务器 在该分支上最后一次提交的树。 p>

更新主分支时必须进行相同的操作,但必须更新生产服务器树。 p>

但是,由于我们使用Laravel,我们 必须使用Artisan运行一些额外的控制台命令,具体取决于每种情况。 p>

我们正在关注Vincent Driessen的Git分支模型。 em> p>

到目前为止我所知道的: h2>

我知道GitLab使用Web Hooks,但我不确定这是否适用于这种情况,因为我需要访问自定义URL,听起来不太安全,但如果它是唯一的解决方案 我可以编写一个脚本来处理这个问题。
另一个可能的解决方案是使用Jenkins,但我不是专家,我不知道Jenkins是否对我的情况太多了,因为我是 还没有使用单元测试。 p>

你们有没有实现一个可以帮助我的案例的解决方案? 任何人都可以建议一种简单而优雅的方式吗? strong> p>

谢谢大家! 有一个好的 p> div>

I would suggest to keep things simple and work with git, hooks and remote repositores. Pulling out heavy guns, like Jenkins or Gitlab for this task could be a bit too much.

I see your request as the following: "git after push and/or git after merge: push to remote repo".

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...)

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://*.com/a/13057643/1163786 (writing a "git post-receive hook" to deal with a specific branch)

  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.

I think this request is related to internal and external deployment via git. You might also search for tutorials, like "deployment with git", which might be helpful. For example: 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)

  • All branches get pulled to dev server whenever a change is pushed to Git. They are available in feature-x.dev.domain.com, feature-y.dev.domain.com etc., running against dev database.

  • 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).

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.