pitrou commented on a change in pull request #7021: URL: https://github.com/apache/arrow/pull/7021#discussion_r420000011
########## File path: dev/archery/archery/cli.py ########## @@ -650,11 +651,130 @@ def integration(with_all=False, random_seed=12345, **args): @click.option('--crossbow-token', '-ct', envvar='CROSSBOW_GITHUB_TOKEN', help='OAuth token for pushing to the crossow repository') def trigger_bot(event_name, event_payload, arrow_token, crossbow_token): + from .bot import CommentBot, actions + event_payload = json.loads(event_payload.read()) bot = CommentBot(name='github-actions', handler=actions, token=arrow_token) bot.handle(event_name, event_payload) +@archery.group('docker') +@click.option("--src", metavar="<arrow_src>", default=None, + callback=validate_arrow_sources, + help="Specify Arrow source directory.") +@click.pass_obj +def docker_compose(obj, src): + """Interact with docker-compose based builds.""" + from .docker import DockerCompose + + config_path = src.path / 'docker-compose.yml' + if not config_path.exists(): + raise click.ClickException( + "Docker compose configuration cannot be found in directory {}, " + "try to pass the arrow source directory explicitly.".format(src) + ) + + # take the docker-compose parameters like PYTHON, PANDAS, UBUNTU from the + # environment variables to keep the usage similar to docker-compose + obj['compose'] = DockerCompose(config_path, params=os.environ) + obj['compose'].validate() + + +@docker_compose.command('run') +@click.argument('image') +@click.argument('command', required=False, default=None) +@click.option('--env', '-e', multiple=True, + help='Set environment variable within the container') +@click.option('--build/--no-build', default=True, + help='Force build the image and its parents') +@click.option('--cache/--no-cache', default=True, + help='Try to pull the image and its parents') +@click.option('--cache-leaf/--no-cache-leaf', default=True, + help='Force build the image and its parents') +@click.option('--dry-run/--execute', default=False, + help='Display the docker-compose commands instead of executing ' + 'them') +@click.pass_obj +def docker_compose_run(obj, image, command, env, build, cache, cache_leaf, + dry_run): + """Execute docker-compose builds. + + To see the available builds run `archery docker list`. + + Examples: + + # execute a single build + archery docker run conda-python + + # execute the builds but disable the image pulling + archery docker run --no-cache conda-python + + # pass a docker-compose parameter, like the python version + PYTHON=3.8 archery docker run conda-python + + # disable the cache only for the leaf image + PANDAS=master archery docker run --no-cache-leaf conda-python-pandas + + # entirely skip building the image + archery docker run --no-build conda-python + + # pass runtime parameters via docker environment variables + archery docker run -e CMAKE_BUILD_TYPE=release ubuntu-cpp + + # starting an interactive bash session for debugging + archery docker run ubuntu-cpp bash + """ + from .docker import UndefinedImage + + compose = obj['compose'] + + if dry_run: + from types import MethodType + + def _print_command(self, *args, **kwargs): + params = ['{}={}'.format(k, v) for k, v in self.params.items()] + command = ' '.join(params + ['docker-compose'] + list(args)) + click.echo(command) + + compose._execute = MethodType(_print_command, compose) + + try: + if build: + compose.build(image, cache=cache, cache_leaf=cache_leaf) + compose.run(image, command=command) + except UndefinedImage as e: + raise click.ClickException( + "There is no service/image defined in docker-compose.yml with " + "name: {}".format(str(e)) + ) + except RuntimeError as e: + raise click.ClickException(str(e)) + + +@docker_compose.command('push') +@click.argument('image') +@click.option('--user', '-u', required=True, envvar='ARCHERY_DOCKER_USER', + help='Docker login user') +@click.option('--password', '-p', required=True, + envvar='ARCHERY_DOCKER_PASSWORD', + help='Docker login user') +@click.pass_obj +def docker_compose_push(obj, image, user, password): + """Push the generated docker-compose image.""" + compose = obj['compose'] + compose.push(image, user=user, password=password) + + +@docker_compose.command('images') +@click.pass_obj +def docker_compose_images(obj): + """Push the generated docker-compose image.""" Review comment: This docstring seems off. ########## File path: dev/archery/archery/cli.py ########## @@ -650,11 +651,130 @@ def integration(with_all=False, random_seed=12345, **args): @click.option('--crossbow-token', '-ct', envvar='CROSSBOW_GITHUB_TOKEN', help='OAuth token for pushing to the crossow repository') def trigger_bot(event_name, event_payload, arrow_token, crossbow_token): + from .bot import CommentBot, actions + event_payload = json.loads(event_payload.read()) bot = CommentBot(name='github-actions', handler=actions, token=arrow_token) bot.handle(event_name, event_payload) +@archery.group('docker') +@click.option("--src", metavar="<arrow_src>", default=None, + callback=validate_arrow_sources, + help="Specify Arrow source directory.") +@click.pass_obj +def docker_compose(obj, src): + """Interact with docker-compose based builds.""" + from .docker import DockerCompose + + config_path = src.path / 'docker-compose.yml' + if not config_path.exists(): + raise click.ClickException( + "Docker compose configuration cannot be found in directory {}, " + "try to pass the arrow source directory explicitly.".format(src) + ) + + # take the docker-compose parameters like PYTHON, PANDAS, UBUNTU from the + # environment variables to keep the usage similar to docker-compose + obj['compose'] = DockerCompose(config_path, params=os.environ) + obj['compose'].validate() + + +@docker_compose.command('run') +@click.argument('image') +@click.argument('command', required=False, default=None) +@click.option('--env', '-e', multiple=True, + help='Set environment variable within the container') +@click.option('--build/--no-build', default=True, + help='Force build the image and its parents') +@click.option('--cache/--no-cache', default=True, + help='Try to pull the image and its parents') +@click.option('--cache-leaf/--no-cache-leaf', default=True, + help='Force build the image and its parents') +@click.option('--dry-run/--execute', default=False, + help='Display the docker-compose commands instead of executing ' + 'them') +@click.pass_obj +def docker_compose_run(obj, image, command, env, build, cache, cache_leaf, + dry_run): + """Execute docker-compose builds. + + To see the available builds run `archery docker list`. + + Examples: + + # execute a single build + archery docker run conda-python + + # execute the builds but disable the image pulling + archery docker run --no-cache conda-python + + # pass a docker-compose parameter, like the python version + PYTHON=3.8 archery docker run conda-python + + # disable the cache only for the leaf image + PANDAS=master archery docker run --no-cache-leaf conda-python-pandas + + # entirely skip building the image + archery docker run --no-build conda-python + + # pass runtime parameters via docker environment variables + archery docker run -e CMAKE_BUILD_TYPE=release ubuntu-cpp + + # starting an interactive bash session for debugging + archery docker run ubuntu-cpp bash + """ + from .docker import UndefinedImage + + compose = obj['compose'] + + if dry_run: + from types import MethodType + + def _print_command(self, *args, **kwargs): + params = ['{}={}'.format(k, v) for k, v in self.params.items()] + command = ' '.join(params + ['docker-compose'] + list(args)) + click.echo(command) + + compose._execute = MethodType(_print_command, compose) + + try: + if build: + compose.build(image, cache=cache, cache_leaf=cache_leaf) + compose.run(image, command=command) + except UndefinedImage as e: + raise click.ClickException( + "There is no service/image defined in docker-compose.yml with " + "name: {}".format(str(e)) + ) + except RuntimeError as e: + raise click.ClickException(str(e)) + + +@docker_compose.command('push') +@click.argument('image') +@click.option('--user', '-u', required=True, envvar='ARCHERY_DOCKER_USER', + help='Docker login user') +@click.option('--password', '-p', required=True, + envvar='ARCHERY_DOCKER_PASSWORD', + help='Docker login user') Review comment: This description seems off. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org