diff --git a/src/Handler.php b/src/Handler.php index dcb870ba150fa973dd5582c64f48bb5dae27ff69..d86d5c5e6f8933d3bd884289e2364f3d968100b0 100644 --- a/src/Handler.php +++ b/src/Handler.php @@ -199,6 +199,7 @@ class Handler extends BaseHandler { $extra = $this->composer->getPackage()->getExtra() + ['docker4drupal' => []]; $options = NestedArray::mergeDeep([ 'projectname' => $projectname, + 'ci_home' => '/home/gitlab-runner', 'docker0' => [ 'ip' => $this->getLocalIpv4('docker0'), ], @@ -275,6 +276,16 @@ class Handler extends BaseHandler { 'enable' => 0, ], ], $extra['docker4drupal']); + + $projectRoot = getenv('CI_PROJECT_DIR'); + if (empty($projectRoot)) { + $projectRoot = '.'; + } + else { + $projectRoot = $options['ci_home'] . $projectRoot; + } + $options['projectroot'] = $projectRoot; + return $env->replaceEnvironmentVariables($options); } diff --git a/templates/docker-compose.yml.twig b/templates/docker-compose.yml.twig index 061764fd26b4e4d6d258b275299c0cc57c864cf0..1a94c19b53940e6493e3ae33a238c4c836f6c204 100644 --- a/templates/docker-compose.yml.twig +++ b/templates/docker-compose.yml.twig @@ -42,8 +42,8 @@ services: SSH_AUTH_SOCK: /ssh-agent {% endif %} volumes: - - ./:/var/www/html - - ./drush:/etc/drush + - {{ projectroot }}/:/var/www/html + - {{ projectroot }}/drush:/etc/drush {% if php.ssh %} - $SSH_AUTH_SOCK:/ssh-agent {% endif %} @@ -78,7 +78,7 @@ services: {{ webserver.type|upper }}_BACKEND_HOST: php {{ webserver.type|upper }}_SERVER_ROOT: /var/www/html/{{ webRoot }} volumes: - - ./:/var/www/html + - {{ projectroot }}/:/var/www/html labels: traefik.backend: '{{ projectname }}_{{ webserver.type }}_1' traefik.port: '80' @@ -154,7 +154,7 @@ services: traefik.port: '8080' traefik.frontend.rule: 'Host:nodejs.{{ projectname }}.docker.localhost' volumes: - - ./{{ node.path }}:/app + - {{ projectroot }}/{{ node.path }}:/app command: sh -c 'npm install && npm run start' node: @@ -167,7 +167,7 @@ services: expose: - '3000' volumes: - - ./{{ node.path }}:/app + - {{ projectroot }}/{{ node.path }}:/app command: sh -c 'npm install && npm run start' {% endif %} {% if memcached.enable %} @@ -212,7 +212,7 @@ services: traefik.port: '8080' traefik.frontend.rule: 'Host:webgrind.{{ projectname }}.docker.localhost' volumes: - - files:/mnt/files + - {{ projectroot }}/files:/mnt/files {% endif %} hub: