Verified Commit 15ff9e20 authored by Adrian DC's avatar Adrian DC
Browse files

feat(bundle, gitlab): implement 'CI_LOCAL_PRIVILEGED' variable

Issue: #281
---

Signed-off-by: default avatarAdrian DC <radian.dc@gmail.com>
parent da150a64
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
@@ -106,7 +106,7 @@ pipeline arguments:
  -H, --host           # Run all jobs on the host rather than containers
  --notify             # Enable host notifications of pipeline and jobs results
  --privileged [BOOL]  # Give extended privileges to the containers
                       # (Defaults to 'true' on this system)
                       # (Defaults to 'true', or define CI_LOCAL_PRIVILEGED)
  --random-paths       # Mount random folder paths in the container
  -r, --real-paths     # Mount real folder paths in the container (Linux / macOS only)
  -S, --sockets        # Mount engine sockets for nested containers
@@ -183,6 +183,7 @@ using `variables:` values, either globally or specifically for each job:
variables:
  CI_LOCAL_EXTENDS_INCOMPLETE: str   # Accept incomplete `extends:` jobs for local use
  CI_LOCAL_NETWORK: 'str'            # Configure the network mode used (see `--network`)
  CI_LOCAL_PRIVILEGED: str           # Configure the privileged mode used (see `--privileged`)
```

<!-- prettier-ignore-end -->
+4 −0
Changes for src/cli/entrypoint.py: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -93,6 +93,10 @@ class Entrypoint:
        if options.network is None and Bundle.ENV_NETWORK in environ:
            options.network = environ[Bundle.ENV_NETWORK]

        # Prepare privileged
        if options.privileged is None and Bundle.ENV_PRIVILEGED in environ:
            options.privileged = str(environ[Bundle.ENV_PRIVILEGED]).lower()

        # Prepare paths
        options.configuration = Path(options.configuration).resolve()
        options.path = options.configuration.parent
+3 −4
Changes for src/cli/main.py: 3 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -170,13 +170,12 @@ def main() -> None:
    group.add_argument(
        '--privileged',
        dest='privileged',
        type=lambda value: value.lower() in ['true', '1'],
        action='store',
        metavar='BOOL',
        nargs='?',
        const=privileged_default(),
        default=privileged_default(),
        const='true' if privileged_default() else 'false',
        help='Give extended privileges to the containers\n'
        '(Defaults to \'%(default)s\' on this system)',
        f'(Defaults to \'%(const)s\', or define {Bundle.ENV_PRIVILEGED})',
    )
    group.add_argument(
        '--random-paths',
+3 −3
Changes for src/engines/engine.py: 3 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -64,10 +64,10 @@ class Names:
        return names

# Privileged default
def privileged_default() -> str:
def privileged_default() -> bool:
    if Platform.IS_WINDOWS:
        return 'false'
    return 'true'
        return False
    return True

# Supported engines
def supported() -> List[str]:
+20 −2
Changes for src/jobs/runner.py: 20 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@ from types import FrameType
from typing import cast, Dict, List, Optional

# Components
from ..engines.engine import Engine
from ..engines.engine import Engine, privileged_default
from ..models.images import Entrypoint
from ..models.jobs import Job
from ..package.bundle import Bundle
@@ -64,6 +64,7 @@ class Runner:
        script_file: ScriptsFile,
        entrypoint: Entrypoint,
        network: str,
        privileged: bool,
        target_workdir: str,
        last_result: bool,
        result: bool,
@@ -185,7 +186,7 @@ class Runner:
            entrypoint=entrypoint,
            variables=variables,
            network=network,
            option_privileged=job.options.privileged,
            option_privileged=privileged,
            option_sockets=job.options.sockets,
            services=bool(job.services),
            volumes=volumes,
@@ -342,6 +343,8 @@ class Runner:

        # Variables
        host: bool = False
        network: str
        privileged: bool
        quiet: bool = self.__options.quiet
        random_paths: bool = False
        real_paths: bool = False
@@ -720,6 +723,20 @@ class Runner:
            network = variables[Bundle.ENV_NETWORK]
            variables[Bundle.ENV_NETWORK] = network

        # Prepare privileged
        privileged = privileged_default()
        if self.__options.privileged:
            privileged = str(self.__options.privileged).lower() in [
                'true',
                '1',
            ]
        elif Bundle.ENV_PRIVILEGED in variables:
            privileged = str(variables[Bundle.ENV_PRIVILEGED]).lower() in [
                'true',
                '1',
            ]
        variables[Bundle.ENV_PRIVILEGED] = 'true' if privileged else 'false'

        # Prepare user variables
        environ[Bundle.ENV_USER_HOST_GID] = str(Platform.getgid())
        environ[Bundle.ENV_USER_HOST_UID] = str(Platform.getuid())
@@ -775,6 +792,7 @@ class Runner:
                script_file=script_file,
                entrypoint=job.entrypoint,
                network=network,
                privileged=privileged,
                target_workdir=target_workdir,
                last_result=last_result,
                result=result,
Loading