I created a deployment application for my PHP applications, in fact this is a simple PHP page managing 3 environments (dev, rc, prod).
This page gets the informations about the last commit and about each environments, allowing developer to change the version of an environments using tags.
I saw several application (e.g. github, packagist...) using tags for versions but i am getting some trouble with it.
Previously, i was using SVN and it was very easy and fast to do it, so i am getting frustated by Git and maybe you could help me.
I am using gitlab and github for several projects.
First, be careful that only one git remote request can be very slow (1 to 6 seconds)
Get informations about last commit
To get these informations, i have to fetch the dev environment then i am doing
git --no-pager show --name-status --format="__TOKEN__%n%H%n%T%n%P%n%d%n%an%n%ae%n%aD%n%cn%n%ce%n%cD"
I am using a random __TOKEN__ to parse the result, git can add more information before it but i dont care.
So the result could be:
___DATA-57a988c31bbf2___
b4041b95c0221fe211ea74110a421842f625f2c8
2287ccb797fc886055a5f4afc56aa90d7dcf4a4e
d1c618e0f50783efff209ba6c0752d55f14bd241
(HEAD, v0.1.7.2, origin/master, origin/HEAD, master)
Loenix
myemail@domain.com
Mon, 8 Aug 2016 15:09:44 +0200
Loenix
myemail@domain.com
Mon, 8 Aug 2016 15:09:44 +0200
This is working but i have to fetch it each time.
I am getting informations about environments in the same way.
List versions (tags)
Now, I need to list all version with name and date, so i am doing git for-each-ref --sort=taggerdate --format "%(tag)|%(taggerdate)" refs/tags | sort -V
I am getting as results:
v0.1.5|Mon Jun 6 22:14:18 2016 +0200
v0.1.6|Mon Jun 6 22:47:02 2016 +0200
v0.1.7.1|Mon Aug 8 13:55:59 2016 +0200
v0.1.7.2|Mon Aug 8 15:10:02 2016 +0200
v0.1.7|Mon Aug 8 13:36:12 2016 +0200
This is not sorting well.
Change version of an environment
I currently find 2 solutions:
-
git checkout v0.1.7.2
This update current version to new one. The problem is when i am using composer, composer.lock is changed locally and git return an error. -
git reset --hard v0.1.7.2
This replaces all things in folder...
I could fix the composer.lock error by ignoring it.
I am getting some trouble to manipulate versions because an environment could be branched on master or on a tag and i am not able to efficiently identify the tag (version) of an environment.
I am caching tags but by this way, my page takes 5-10 seconds to load...
Can you help me to fix the troubles ? Have you some advices ? Do you think I should do it by another way ? I could also use a simple existing deployment application but i didn't find any good one.
PS: All commands are runned using system() PHP function on a debian/ubuntu OS.