Skip to content
This repository has been archived by the owner on Mar 23, 2019. It is now read-only.

Added support for override command directive when conductor is building image #719

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions container/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,13 @@ def conductorcmd_build(engine_name, project_name, services, cache=True, local_py
environment=dict(ANSIBLE_CONTAINER=1)
)

if service.get('build_overrides'):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this actually belongs in config.py, and it should be handled as part of the set_env method on the host side. That method would then accept a new env value of build, and return the appropriate configuration.

for key in service['build_overrides']:
if key in ['user', 'working_dir', 'command', 'privileged']:
run_kwargs[key] = service['build_overrides'][key]

run_kwargs['environment'].update(service['build_overrides']['environment'])

if service.get('volumes'):
for volume in service['volumes']:
pieces = volume.split(':')
Expand Down
35 changes: 35 additions & 0 deletions docs/rst/container_yml/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ with a checkmark in the *Supported* column can be used.
Directive Definition Supported?
===================== ======================================================== ============
build Run Dockerfile based build
:ref:`build_over` Service level directives that apply only in container
build time |checkmark|
cap_add Add container capabilities
cap_drop Drop container capabilities
command Command executed by the container at startup |checkmark|
Expand Down Expand Up @@ -290,6 +292,39 @@ Implementation

The following provides details about how specific directives are implemented.

.. _build_over:

build_overrides
.............

Use for directives that should only be applied during the execution of the ``build`` command. For example,
consider the following ``container.yml`` file:

.. code-block:: yaml

version: '2'
services:
web:
from: centos:7
command: [nginx]
entrypoint: [/usr/bin/entrypoint.sh]
ports:
- 8000:8000
build_overrides:
command: /usr/sbin/init
user: root
working_dir: /somepath
environment:
- container: docker


In this example, when ``ansible-container build`` is executed, the options found in *build_overrides* will
take effect, and the building container will run command ``/usr/sbin/init`` rather than default ``sh -c "while true; do sleep 1; done``, have extra environment variables ``container=docker`` mapped to the container's environment and the container's working directory will be ``/somepath``.

The ``run`` and ``deploy`` commands ignore *build_overrides*. When ``run`` or ``deploy`` executes, the container will not run the command or use environment variables specified in ``build_overrides`` directive.

Supported directives in ``build_overrides`` are ``command``, ``user``, ``working_dir``, ``privileged`` and ``environment``

.. _depends_on:

depends_on
Expand Down