0

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

Vinhas
  • 181
  • 1
  • 5

3 Answers3

1

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://stackoverflow.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/

Community
  • 1
  • 1
Jens A. Koch
  • 39,862
  • 13
  • 113
  • 141
  • I know this method as well, I'll probably try to use this implementation and GitLab. I need to figure out where GitLab keep the repos to write the hooks. Thanks Jens – Vinhas Oct 24 '14 at 16:00
  • I think GitLab stores repos in `/var/opt/gitlab/git-data/repositories`. But it depends on configuration. - You might give Gogs (Go Git Service) a try - good alternative to Gitlab. – Jens A. Koch Oct 24 '14 at 16:54
  • Seems to be a nice option! Very lightweight, I like it :) I'm going to install it here and see how it goes! Thanks for the hint – Vinhas Oct 24 '14 at 19:40
1

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)

preyz
  • 3,029
  • 5
  • 29
  • 36
  • That's probably the ideal situation for me but I need to fit GitLab in the process. I have no way to remove it, since we are already using it for older projects. Thanks for sharing, if you could elaborate how you do it, would be nice! :) – Vinhas Oct 24 '14 at 15:57
0

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.

simonhamp
  • 3,078
  • 1
  • 20
  • 26