Skip to content

Commit

Permalink
[IMP] t2d: add new argument --build-extra-steps
Browse files Browse the repository at this point in the history
Similar to --run-extra-cmds, --build-extra-cmds, this new argument
allows users to add extra steps at the end of the generated Dockerfile.

Closes #209.
  • Loading branch information
antonag32 authored and luisg123v committed Nov 27, 2023
1 parent e4039cb commit 5357a7f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/travis2docker/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,13 @@ def main(return_result=False):
default=False,
help='Use the image generated from the CI and used in deployV',
)
parser.add_argument(
'--build-extra-steps',
nargs='*',
default="",
dest='build_extra_steps',
help='Append these extra steps at the end of the Dockerfile',
)

args = parser.parse_args()
revision = args.git_revision
Expand Down Expand Up @@ -250,6 +257,7 @@ def main(return_result=False):
runs_at_the_end_script=runs_at_the_end_script,
build_env_args=build_env_args,
deployv=deployv,
build_extra_steps=args.build_extra_steps,
)
t2d.build_extra_params = {
'extra_params': build_extra_args,
Expand Down
4 changes: 4 additions & 0 deletions src/travis2docker/templates/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ RUN apt-get update; apt-get install {{ ' '.join(packages) }}

RUN echo "TRAVIS_PYTHON_VERSION={{ python_version }}" >> /etc/environment

{% for step in build_extra_steps %}
RUN {{ step }}
{% endfor %}

USER {{ user }}
ENV TRAVIS_PYTHON_VERSION={{ python_version }}
ENV TRAVIS_REPO_SLUG={{ repo_owner }}/{{ repo_project }}
Expand Down
3 changes: 3 additions & 0 deletions src/travis2docker/templates/Dockerfile_deployv
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ RUN . /home/odoo/build.sh && \
mv /entry_point.py /deployv_entry_point.py && \
mkdir /run/sshd

{% for step in build_extra_steps %}
RUN {{ step }}
{% endfor %}

USER {{ user }}

Expand Down
3 changes: 3 additions & 0 deletions src/travis2docker/travis2docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def __init__(
runs_at_the_end_script=None,
build_env_args=None,
deployv=None,
build_extra_steps=None,
):
self._python_versions = []
self.curr_work_path = None
Expand All @@ -87,6 +88,7 @@ def __init__(
self.deployv = deployv
self.runs_at_the_end_script = ["sleep 2"] if runs_at_the_end_script is None else runs_at_the_end_script
self.variables_sh_data = {}
self.build_extra_steps = build_extra_steps
if deployv:
self.variables_sh_data = {
var.lower(): value for _, _, var, value in self.re_export.findall(os_kwargs['variables_sh'])
Expand Down Expand Up @@ -316,6 +318,7 @@ def compute_dockerfile(self, skip_after_success=False):
'sources': [],
'rvm_env_path': rvm_env_relpath,
'build_env_args': self.build_env_args,
'build_extra_steps': self.build_extra_steps,
}
with open(curr_dockerfile, "w") as f_dockerfile, open(entryp_path, "w") as f_entrypoint, open(
rvm_env_path, "w"
Expand Down

0 comments on commit 5357a7f

Please sign in to comment.