Commit 95e78fd0 authored by Adrian DC's avatar Adrian DC
Browse files

feat: implement #216: implement SSH and SSH agent binds

parent 3e8747e2
Loading
Loading
Loading
Loading
Loading
+2 −1
Changes for README.md: 2 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -71,6 +71,7 @@ is the common and unique interface between GitLab CI and gitlabci-local.
| -H, --host         | Run all jobs on the host rather than containers                                                              |
| -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                                                          |
| -v VOLUME          | Mount VOLUME or HOST:TARGET in containers                                                                    |
| -w WORKDIR         | Override the container's working path                                                                        |

@@ -124,7 +125,7 @@ inside the `.local` to ease default parameters definitions.

Supported local values include `after`, `all`, `bash`, `before`, `configurations`,  
`debug`, `defaults`, `engine`, `env`, `image`, `manual`, `names`, `network`,  
`pipeline`, `quiet`, `real_paths`, `sockets`, `tags`, `volumes`, `workdir`.
`pipeline`, `quiet`, `real_paths`, `sockets`, `ssh`, `tags`, `volumes`, `workdir`.

Examples for each of these can be found in the `local` unit tests: [tests/local](https://gitlab.com/AdrianDC/gitlabci-local/blob/master/tests/local/.gitlab-ci.yml)

+2 −0
Changes for gitlabci_local/cli/main.py: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -87,6 +87,8 @@ def main():
        '-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 continer')
    group.add_argument('-v', dest='volume', action='append',
                       help='Mount VOLUME or HOST:TARGET in containers')
    group.add_argument('-w', dest='workdir',
+13 −0
Changes for gitlabci_local/jobs/runner.py: 13 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -96,6 +96,19 @@ class Jobs:
                f"Missing image for \"{job_data['stage']} / {job_data['name']}\"")
        self.__engine.get(image)

        # SSH option
        if self.__options.ssh:

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

            # Bind SSH agent
            if Platform.ENV_SSH_AUTH_SOCK in environ:
                volumes.add(Paths.expand(environ[Platform.ENV_SSH_AUTH_SOCK]),
                            Paths.expand(environ[Platform.ENV_SSH_AUTH_SOCK]), 'ro', True)
                variables[Platform.ENV_SSH_AUTH_SOCK] = environ[
                    Platform.ENV_SSH_AUTH_SOCK]

        # Launch container
        self.__engine.run(
            image=image,
+10 −0
Changes for gitlabci_local/parsers/gitlab.py: 10 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -366,6 +366,11 @@ class GitLab:
                if not self.__options.sockets:
                    self.__options.sockets = local['sockets']

            # Parse local ssh
            if 'ssh' in local:
                if not self.__options.ssh:
                    self.__options.ssh = local['ssh']

            # Parse local tags
            if 'tags' in local:
                if self.__options.tags_default:
@@ -603,6 +608,7 @@ class GitLab:
        job['options']['quiet'] = False
        job['options']['silent'] = False
        job['options']['sockets'] = False
        job['options']['ssh'] = False
        job['options']['env_job_name'] = self.ENV_JOB_NAME
        job['options']['env_job_path'] = self.ENV_PROJECT_DIR

@@ -806,5 +812,9 @@ class GitLab:
        if not job['options']['sockets']:
            job['options']['sockets'] = self.__options.sockets

        # Apply ssh option
        if not job['options']['ssh']:
            job['options']['ssh'] = self.__options.ssh

        # Result
        return job
+1 −0
Changes for gitlabci_local/system/platform.py: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@ class Platform:
    ENV_ANDROID = 'ANDROID_ROOT'
    ENV_EXPERIMENTAL = 'EXPERIMENTAL'
    ENV_SIMULATE_MAC_OS = 'SIMULATE_MAC_OS'
    ENV_SSH_AUTH_SOCK = 'SSH_AUTH_SOCK'
    ENV_SUDO_USER = 'SUDO_USER'

    # Constants
Loading