0

I am looking for a way to automatically fetch those information on a cloudControl container. So I wrote a little Symfony2 service that returns some git information, e.g. the commit hash

public function getCommitHash() {
    exec('git rev-parse --short HEAD', $output);
    $hash = implode(', ', $output);
    return $hash;
}

If I run this on my local machine, it returns the proper shortened commit hash. But if I push this to my cloudControl machine, the return is null. I manually connected to the machine and ran this command on the command line (in the www folder, that is where the repository is pushed into). That throws the following error:

fatal: Not a git repository (or any parent up to mount parent )
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).

I am really confused, as I thought I simply push my whole repository (including the .git folder) onto the remote machine. Why do I get this error and how can I fetch the git information instead?

Gottlieb Notschnabel
  • 9,408
  • 18
  • 74
  • 116

2 Answers2

1

You cannot fetch the git info from inside a container, since the git repository is not initialized where the code is located.

All the code is located in a repository node. You can get the remote address by executing cctrlapp APP_NAME/DEP_NAME details, it will have the following format: ssh://APP_NAME@cloudcontrolled.com/repository.git.

Given this git address, you can add it as a remote to your local directory (git remote add cctrl ssh://APP_NAME@cloudcontrolled.com/repository.git) and get all git information as you want.

Fernando Á.
  • 7,295
  • 7
  • 30
  • 32
1

If you want to use the git version within your running container, you can use the environment variable DEP_VERSION. E.g.:

<?php
echo 'This container is running git commit ' .$_ENV["DEP_VERSION"] . '.';
?>
Stefan Friesel
  • 823
  • 5
  • 19