Repository: opsdroid/opsdroid

Issue:
[Docker] DEFAULT_ROOT_PATH should be created if it does not exist
I have tried to run opsdroid in a Docker container, in the following environment:

```
OS: Ubuntu 16.04.3 LTS
Docker version: 17.06.2-ce
Docker API version: 1.30
```

The process I followed is the following:

1. `docker pull opsdroid/opsdroid:latest`
2. Created an initial configuration in the host: `/var/tmp/configuration.yaml`
3. Ran the following command: ` docker run --rm -v /var/tmp/configuration.yaml:/etc/opsdroid/configuration.yaml:ro opsdroid/opsdroid:latest`

The configuration file contents are:
```
connectors:
  - name: shell

skills:
  - name: hello
```

But I got the following error:

```
ubuntu@ubuntu:~$ docker run --rm -v /var/tmp/configuration.yaml:/etc/opsdroid/configuration.yaml:ro opsdroid/opsdroid:latest
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/local/lib/python3.5/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/src/app/opsdroid/__main__.py", line 112, in <module>
    main()
  File "/usr/src/app/opsdroid/__main__.py", line 105, in main
    configure_logging(opsdroid.config)
  File "/usr/src/app/opsdroid/__main__.py", line 51, in configure_logging
    file_handler = logging.FileHandler(logfile_path)
  File "/usr/local/lib/python3.5/logging/__init__.py", line 1014, in __init__
    StreamHandler.__init__(self, self._open())
  File "/usr/local/lib/python3.5/logging/__init__.py", line 1043, in _open
    return open(self.baseFilename, self.mode, encoding=self.encoding)
FileNotFoundError: [Errno 2] No such file or directory: '/root/.opsdroid/output.log'
ubuntu@ubuntu:~$
```

When running the container in interactive mode to debug the issue, by issuing `docker run -it -v /var/tmp/configuration.yaml:/etc/opsdroid/configuration.yaml:ro opsdroid/opsdroid:latest /bin/sh` and executing the default command (`python -m opsdroid`), I reproduced the issue:

```
/usr/src/app # python -m opsdroid
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/local/lib/python3.5/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/src/app/opsdroid/__main__.py", line 112, in <module>
    main()
  File "/usr/src/app/opsdroid/__main__.py", line 105, in main
    configure_logging(opsdroid.config)
  File "/usr/src/app/opsdroid/__main__.py", line 51, in configure_logging
    file_handler = logging.FileHandler(logfile_path)
  File "/usr/local/lib/python3.5/logging/__init__.py", line 1014, in __init__
    StreamHandler.__init__(self, self._open())
  File "/usr/local/lib/python3.5/logging/__init__.py", line 1043, in _open
    return open(self.baseFilename, self.mode, encoding=self.encoding)
FileNotFoundError: [Errno 2] No such file or directory: '/root/.opsdroid/output.log'
/usr/src/app #
```

When checking if the `/root/.opsdroid/` directory existed, I got the following:
```
/usr/src/app # ls /root/.opsdroid
ls: /root/.opsdroid: No such file or directory
```

Concluding, opsdroid should check if that directory exists and create it if not. 
[Docker] DEFAULT_ROOT_PATH should be created if it does not exist
I have tried to run opsdroid in a Docker container, in the following environment:

```
OS: Ubuntu 16.04.3 LTS
Docker version: 17.06.2-ce
Docker API version: 1.30
```

The process I followed is the following:

1. `docker pull opsdroid/opsdroid:latest`
2. Created an initial configuration in the host: `/var/tmp/configuration.yaml`
3. Ran the following command: ` docker run --rm -v /var/tmp/configuration.yaml:/etc/opsdroid/configuration.yaml:ro opsdroid/opsdroid:latest`

The configuration file contents are:
```
connectors:
  - name: shell

skills:
  - name: hello
```

But I got the following error:

```
ubuntu@ubuntu:~$ docker run --rm -v /var/tmp/configuration.yaml:/etc/opsdroid/configuration.yaml:ro opsdroid/opsdroid:latest
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/local/lib/python3.5/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/src/app/opsdroid/__main__.py", line 112, in <module>
    main()
  File "/usr/src/app/opsdroid/__main__.py", line 105, in main
    configure_logging(opsdroid.config)
  File "/usr/src/app/opsdroid/__main__.py", line 51, in configure_logging
    file_handler = logging.FileHandler(logfile_path)
  File "/usr/local/lib/python3.5/logging/__init__.py", line 1014, in __init__
    StreamHandler.__init__(self, self._open())
  File "/usr/local/lib/python3.5/logging/__init__.py", line 1043, in _open
    return open(self.baseFilename, self.mode, encoding=self.encoding)
FileNotFoundError: [Errno 2] No such file or directory: '/root/.opsdroid/output.log'
ubuntu@ubuntu:~$
```

When running the container in interactive mode to debug the issue, by issuing `docker run -it -v /var/tmp/configuration.yaml:/etc/opsdroid/configuration.yaml:ro opsdroid/opsdroid:latest /bin/sh` and executing the default command (`python -m opsdroid`), I reproduced the issue:

```
/usr/src/app # python -m opsdroid
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/local/lib/python3.5/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/src/app/opsdroid/__main__.py", line 112, in <module>
    main()
  File "/usr/src/app/opsdroid/__main__.py", line 105, in main
    configure_logging(opsdroid.config)
  File "/usr/src/app/opsdroid/__main__.py", line 51, in configure_logging
    file_handler = logging.FileHandler(logfile_path)
  File "/usr/local/lib/python3.5/logging/__init__.py", line 1014, in __init__
    StreamHandler.__init__(self, self._open())
  File "/usr/local/lib/python3.5/logging/__init__.py", line 1043, in _open
    return open(self.baseFilename, self.mode, encoding=self.encoding)
FileNotFoundError: [Errno 2] No such file or directory: '/root/.opsdroid/output.log'
/usr/src/app #
```

When checking if the `/root/.opsdroid/` directory existed, I got the following:
```
/usr/src/app # ls /root/.opsdroid
ls: /root/.opsdroid: No such file or directory
```

Concluding, opsdroid should check if that directory exists and create it if not. 


Discussion:

Resolving patch:
diff --git a/opsdroid/__main__.py b/opsdroid/__main__.py
--- a/opsdroid/__main__.py
+++ b/opsdroid/__main__.py
@@ -48,6 +48,9 @@ def configure_logging(config):
         pass
 
     if logfile_path:
+        logdir = os.path.dirname(os.path.realpath(logfile_path))
+        if not os.path.isdir(logdir):
+            os.makedirs(logdir)
         file_handler = logging.FileHandler(logfile_path)
         file_handler.setLevel(log_level)
         file_handler.setFormatter(formatter)


Test patch:
diff --git a/tests/test_main.py b/tests/test_main.py
--- a/tests/test_main.py
+++ b/tests/test_main.py
@@ -59,6 +59,14 @@ def test_configure_file_logging(self):
         self.assertEqual(logging.FileHandler, type(rootlogger.handlers[1]))
         self.assertEqual(rootlogger.handlers[1].level, logging.INFO)
 
+    def test_configure_file_logging_directory_not_exists(self):
+        config = {"logging": {
+            "path": '/tmp/mynonexistingdirectory' + "/output.log",
+            "console": False,
+        }}
+        opsdroid.configure_logging(config)
+        self.assertEqual(os.path.isfile(config['logging']['path']), True)
+
     def test_configure_console_logging(self):
         config = {"logging": {
             "path": False,