From 5745ab4cac4850692b07dcb52ac8ab2944eae798 Mon Sep 17 00:00:00 2001
From: jurgenhaas <juergen@paragon-es.de>
Date: Fri, 8 Dec 2017 11:33:35 +0100
Subject: [PATCH] #15 Make SSH auth socket optional

---
 README.md                         | 2 ++
 src/Handler.php                   | 4 ++++
 templates/docker-compose.yml.twig | 4 ++++
 3 files changed, 10 insertions(+)

diff --git a/README.md b/README.md
index 73ab1fd..dc957a1 100644
--- a/README.md
+++ b/README.md
@@ -143,6 +143,8 @@ There are potentially more options possible, for details please refer to the Dru
 
 #### Configure SSH access from the PHP container
 
+This feature is only available if SSH agent forwarding is enabled on your host. There is a [good tutorial](https://developer.github.com/v3/guides/using-ssh-agent-forwarding/#your-local-ssh-agent-must-be-running) available if you need any help.
+
 Your host SSH configuration is automatically forwarded to the PHP docker container using sockets and you don't have to do anything to make it work, as long as your host is configured correctly to access your live site via SSH - in this case the PHP container can too. This works by mounting and forwarding your `SSH_AUTH_SOCK` environment variable to `/ssh-agent` inside the PHP container, so that the user inside that container can utilize your SSH settings like your user outside the contain who built them.
 
 Typical issues that may cause trouble in this context are:
diff --git a/src/Handler.php b/src/Handler.php
index d0bf2a7..ea249e7 100644
--- a/src/Handler.php
+++ b/src/Handler.php
@@ -129,6 +129,10 @@ class Handler {
       $settingsPath = 'settings/default';
     }
 
+    // Check if SSH auth sockets are supported.
+    $ssh_auth_sock = getenv('SSH_AUTH_SOCK');
+    $options['php']['ssh'] = !empty($ssh_auth_sock);
+
     // Provide all the required files.
     $twig_loader = new \Twig_Loader_Array([]);
     $twig = new \Twig_Environment($twig_loader);
diff --git a/templates/docker-compose.yml.twig b/templates/docker-compose.yml.twig
index 1e11da3..d0598f3 100644
--- a/templates/docker-compose.yml.twig
+++ b/templates/docker-compose.yml.twig
@@ -36,11 +36,15 @@ services:
 {% if blackfire.enable %}
       PHP_BLACKFIRE: 1
 {% endif %}
+{% if php.ssh %}
       SSH_AUTH_SOCK: /ssh-agent
+{% endif %}
     volumes:
       - ./:/var/www/html
       - ./drush:/etc/drush
+{% if php.ssh %}
       - $SSH_AUTH_SOCK:/ssh-agent
+{% endif %}
 {% if webgrind.enable %}
       - files:/mnt/files
 {% endif %}
-- 
GitLab