Commit 5d2b716d authored by Adrian DC's avatar Adrian DC
Browse files

feat: implement #227: allow mounting SSH keys as a specific user

parent e7c350a9
Loading
Loading
Loading
Loading
+1 −1
Changes for README.md: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -72,7 +72,7 @@ is the common and unique interface between GitLab CI and gitlabci-local.
| --notify           | Enable host notifications of pipeline and jobs results                                                       |
| -r, --real-paths   | Mount real folder paths in the container (Linux / macOS only)                                                |
| -S, --sockets      | Mount engine sockets for nested containers<br>(Enabled by default with services: docker:\*dind)              |
| --ssh              | Bind SSH credentials automatically in the container                                                          |
| --ssh [SSH_USER]   | Bind SSH credentials to a container's user                                                                   |
| -v VOLUME          | Mount VOLUME or HOST:TARGET in containers                                                                    |
| -w WORKDIR         | Override the container's working path                                                                        |

+3 −2
Changes for gitlabci_local/cli/main.py: 3 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -88,8 +88,9 @@ def main() -> None:
        '-S', '--sockets', dest='sockets', action='store_true',
        help='Mount engine sockets for nested containers\n'
        '(Enabled by default with services: docker:*dind)')
    group.add_argument('--ssh', dest='ssh', action='store_true',
                       help='Bind SSH credentials automatically in the container')
    group.add_argument('--ssh', dest='ssh', action='store', metavar='SSH_USER', nargs='?',
                       const=Bundle.ARGUMENT_SSH_USER_DEFAULT,
                       help='Bind SSH credentials to a container\'s user')
    group.add_argument('-v', dest='volume', action='append',
                       help='Mount VOLUME or HOST:TARGET in containers')
    group.add_argument('-w', dest='workdir', action='store',
+2 −1
Changes for gitlabci_local/jobs/runner.py: 2 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -117,7 +117,8 @@ class Runner:
        if self.__options.ssh:

            # Bind SSH credentials
            volumes.add(Paths.expand('~/.ssh'), '/root/.ssh', 'ro', False)
            volumes.add(Paths.expand('~/.ssh'),
                        Paths.home(self.__options.ssh) + '/.ssh', 'ro', False)

            # Bind SSH agent
            if Platform.ENV_SSH_AUTH_SOCK in environ:
+1 −0
Changes for gitlabci_local/package/bundle.py: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ class Bundle:

    # Arguments
    ARGUMENT_NETWORKS_ENUM: List[str] = ['bridge', 'host', 'none']
    ARGUMENT_SSH_USER_DEFAULT: str = 'root'
    ARGUMENT_TAGS_DEFAULT: List[str] = ['deploy', 'local', 'publish']

    # Names
+4 −0
Changes for gitlabci_local/parsers/gitlab.py: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@ from oyaml import safe_load as yaml_safe_load
from ..containers.images import Images
from ..features.menus import MenusFeature
from ..jobs.options import Options
from ..package.bundle import Bundle
from ..types.environment import Environment
from ..types.parsers import ParsersData
from ..types.paths import Paths
@@ -383,6 +384,9 @@ class GitLab:
            # Parse local ssh
            if 'ssh' in local:
                if not self.__options.ssh:
                    if isinstance(local['ssh'], bool) and local['ssh']:
                        self.__options.ssh = Bundle.ARGUMENT_SSH_USER_DEFAULT
                    elif isinstance(local['ssh'], str):
                        self.__options.ssh = local['ssh']

            # Parse local tags
Loading