diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..38e0b704 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +FROM ubuntu:18.04 +RUN apt-get update && apt-get install \ + -y build-essential git python3-dev python3-virtualenv + +ENV VIRTUAL_ENV=/opt/venv +RUN python3 -m virtualenv --python=/usr/bin/python3 $VIRTUAL_ENV +ENV PATH="$VIRTUAL_ENV/bin:$PATH" + +# Install dependencies: +COPY setup.py marge-bot/setup.py +COPY requirements.txt marge-bot/requirements.txt +COPY requirements_frozen.txt marge-bot/requirements_frozen.txt +COPY version marge-bot/version +COPY marge marge-bot/marge +COPY marge.app marge-bot/marge.app + +WORKDIR /marge-bot + +RUN python3 setup.py install +RUN pip3 install -r requirements.txt + +ENTRYPOINT ["./marge.app"] diff --git a/marge/app.py b/marge/app.py index 07486431..e0d31887 100644 --- a/marge/app.py +++ b/marge/app.py @@ -76,7 +76,7 @@ def regexp(str_regex): metavar='URL', help='Your GitLab instance, e.g. "https://gitlab.example.com".\n', ) - ssh_key_group = parser.add_mutually_exclusive_group(required=True) + ssh_key_group = parser.add_mutually_exclusive_group(required=False) ssh_key_group.add_argument( '--ssh-key', type=str, @@ -89,8 +89,9 @@ def regexp(str_regex): ) ssh_key_group.add_argument( '--ssh-key-file', - type=str, # because we want a file location, not the content + # type=str, # because we want a file location, not the content metavar='FILE', + default='marge-bot-ssh-key', # give it a default to stop complaining help='Path to the private ssh key for marge so it can clone/push.\n', ) parser.add_argument( @@ -229,9 +230,9 @@ def regexp(str_regex): # pylint: disable=protected-access for _, (_, value) in parser._source_to_settings.get(configargparse._COMMAND_LINE_SOURCE_KEY, {}).items(): cli_args.extend(value) - for bad_arg in ['--auth-token', '--ssh-key']: - if bad_arg in cli_args: - raise MargeBotCliArgError('"%s" can only be set via ENV var or config file.' % bad_arg) + # for bad_arg in ['--auth-token', '--ssh-key']: + # if bad_arg in cli_args: + # raise MargeBotCliArgError('"%s" can only be set via ENV var or config file.' % bad_arg) return config @@ -290,6 +291,7 @@ def main(args=None): config = bot.BotConfig( user=user, + auth_token=auth_token, ssh_key_file=ssh_key_file, project_regexp=options.project_regexp, git_timeout=options.git_timeout, diff --git a/marge/bot.py b/marge/bot.py index 398dde46..be0cb5ce 100644 --- a/marge/bot.py +++ b/marge/bot.py @@ -34,6 +34,7 @@ def start(self): with TemporaryDirectory() as root_dir: repo_manager = store.RepoManager( user=self.user, + auth_token=self._config.auth_token, root_dir=root_dir, ssh_key_file=self._config.ssh_key_file, timeout=self._config.git_timeout, @@ -186,7 +187,7 @@ def _get_single_job(self, project, merge_request, repo, options): class BotConfig(namedtuple('BotConfig', - 'user ssh_key_file project_regexp merge_order merge_opts git_timeout ' + + 'user auth_token ssh_key_file project_regexp merge_order merge_opts git_timeout ' + 'git_reference_repo branch_regexp source_branch_regexp batch')): pass diff --git a/marge/store.py b/marge/store.py index 5f819673..0ed313d2 100644 --- a/marge/store.py +++ b/marge/store.py @@ -1,14 +1,16 @@ import tempfile +import re from . import git class RepoManager: - def __init__(self, user, root_dir, ssh_key_file=None, timeout=None, reference=None): + def __init__(self, user, auth_token, root_dir, ssh_key_file=None, timeout=None, reference=None): self._root_dir = root_dir self._user = user self._ssh_key_file = ssh_key_file + self._auth_token = auth_token self._repos = {} self._timeout = timeout self._reference = reference @@ -16,7 +18,10 @@ def __init__(self, user, root_dir, ssh_key_file=None, timeout=None, reference=No def repo_for_project(self, project): repo = self._repos.get(project.id) if not repo or repo.remote_url != project.ssh_url_to_repo: - repo_url = project.ssh_url_to_repo + credentials = self._user.username + ":" + self._auth_token + repo_url = re.sub(":", "/", project.ssh_url_to_repo, 1) + repo_url = re.sub("git", "https://" + credentials, repo_url, 1) + local_repo_dir = tempfile.mkdtemp(dir=self._root_dir) repo = git.Repo(repo_url, local_repo_dir, ssh_key_file=self._ssh_key_file,