Commit 3ffdba49 authored by Adrian DC's avatar Adrian DC
Browse files

fix: resolve #179: expand home paths for volumes and workdir

parent ed155287
Loading
Loading
Loading
Loading
Loading
+9 −9
Changes for gitlabci_local/jobs/runner.py: 9 added lines, 9 removed lines.
Original line number Diff line number Diff line
@@ -2,7 +2,6 @@

# Standard libraries
from os import chmod, environ, stat, system
from os.path import expandvars
from pathlib import Path, PurePosixPath
from signal import getsignal, SIGINT, signal, SIGTERM
from stat import S_IRGRP, S_IROTH, S_IXGRP, S_IXOTH, S_IXUSR
@@ -69,20 +68,20 @@ class Jobs:

                # Parse HOST:TARGET:MODE
                if len(volume_nodes) == 3:
                    volume_host = Paths.resolve(cwd / expandvars(volume_nodes[0]))
                    volume_target = expandvars(volume_nodes[1])
                    volume_host = Paths.resolve(cwd / Paths.expand(volume_nodes[0]))
                    volume_target = Paths.expand(volume_nodes[1], home=False)
                    volume_mode = volume_nodes[2]

                # Parse HOST:TARGET
                elif len(volume_nodes) == 2:
                    volume_host = Paths.resolve(cwd / expandvars(volume_nodes[0]))
                    volume_target = expandvars(volume_nodes[1])
                    volume_host = Paths.resolve(cwd / Paths.expand(volume_nodes[0]))
                    volume_target = Paths.expand(volume_nodes[1], home=False)
                    volume_mode = 'rw'

                # Parse VOLUME
                else:
                    volume_host = Paths.resolve(cwd / expandvars(volume_nodes[0]))
                    volume_target = Paths.resolve(cwd / expandvars(volume_nodes[0]))
                    volume_host = Paths.resolve(cwd / Paths.expand(volume_nodes[0]))
                    volume_target = Paths.resolve(cwd / Paths.expand(volume_nodes[0]))
                    volume_mode = 'rw'

                # Append volume mounts
@@ -292,7 +291,7 @@ class Jobs:
        # Prepare working directory
        if self.__options.workdir:
            if self.__options.workdir.startswith('.local:'):
                workdir = expandvars(self.__options.workdir[len('.local:'):])
                workdir = Paths.expand(self.__options.workdir[len('.local:'):])
                if host or real_paths:
                    target_workdir = Paths.get((self.__options.path / workdir).resolve())
                else:
@@ -429,7 +428,8 @@ class Jobs:

        # Prepare job variables
        for variable in job_data['variables']:
            variables[variable] = expandvars(str(job_data['variables'][variable]))
            variables[variable] = Paths.expand(str(job_data['variables'][variable]),
                                               home=False)

        # Restore environment
        environ.clear()
+16 −0
Changes for gitlabci_local/types/paths.py: 16 added lines, 0 removed lines.
Original line number Diff line number Diff line
#!/usr/bin/env python3

# Standard libraries
from os.path import expanduser, expandvars
from pathlib import Path, PurePosixPath

# Components
@@ -9,6 +10,21 @@ from ..system.platform import Platform
# Paths class
class Paths:

    # Expand
    @staticmethod
    def expand(path, env=True, home=True):

        # Expand environment
        if env:
            path = expandvars(path)

        # Expand home
        if home:
            path = expanduser(path)

        # Result
        return path

    # Getter
    @staticmethod
    def get(data):
+12 −0
Changes for tests/home/.gitlab-ci.cli.yml: 12 added lines, 0 removed lines.
Original line number Diff line number Diff line
image: alpine:3

stages:
  - home_cli

'Job 1':
  stage: home_cli
  script:
    - pwd
    - ls -la ./
    - ls -la /mnt/
    - test "${PWD}" = "${USERHOME?}"
+16 −0
Changes for tests/home/.gitlab-ci.env.yml: 16 added lines, 0 removed lines.
Original line number Diff line number Diff line
image: alpine:3

stages:
  - home_env

.local:
  volumes:
    - ${HOME}:/mnt
  workdir: /mnt

'Job 1':
  stage: home_env
  script:
    - pwd
    - ls -la ./
    - test "${PWD}" = '/mnt'
+16 −0
Changes for tests/home/.gitlab-ci.relative.yml: 16 added lines, 0 removed lines.
Original line number Diff line number Diff line
image: alpine:3

stages:
  - home_relative

.local:
  volumes:
    - .:/mnt
  workdir: /mnt

'Job 1':
  stage: home_relative
  script:
    - pwd
    - ls -la ./
    - test "${PWD}" = '/mnt'
Loading