Skip to content
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
17 changes: 11 additions & 6 deletions src/ansible_builder/_target_scripts/assemble
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,19 @@ RELEASE=$(source /etc/os-release; echo $ID)
# NOTE(pabelanger): Allow users to force either microdnf or dnf as a package
# manager.
PKGMGR="${PKGMGR:-}"
PKGMGR_CLEAN_ALL_COMMAND="${PKGMGR_CLEAN_ALL_COMMAND:-clean all}"
PKGMGR_CACHE_LOCATION="${PKGMGR_CACHE_LOCATION:-/var/cache/{dnf,yum\}}"
PKGMGR_CLEANUP_LOCATIONS="${PKGMGR_CLEANUP_LOCATIONS:-/var/lib/dnf/history.* /var/log/{dnf.*,hawkey.log\}}"
PKGMGR_INSTALL_COMMAND="${PKGMGR_INSTALL_COMMAND:-install -y}"
PKGMGR_OPTS="${PKGMGR_OPTS:-}"
PKGMGR_PRESERVE_CACHE="${PKGMGR_PRESERVE_CACHE:-}"

PYCMD="${PYCMD:=/usr/bin/python3}"
PIPCMD="${PIPCMD:=$PYCMD -m pip}"

$PYCMD -m ensurepip
if [ $PY_DISABLE_ENSUREPIP != "true" ]; then
$PYCMD -m ensurepip
fi

if [ -z $PKGMGR ]; then
# Expect dnf to be installed, however if we find microdnf default to it.
Expand Down Expand Up @@ -72,7 +78,7 @@ function install_bindep {
fi
compile_packages=$(bindep -b compile || true)
if [ ! -z "$compile_packages" ] ; then
$PKGMGR install -y $PKGMGR_OPTS ${compile_packages}
$PKGMGR $PKGMGR_INSTALL_COMMAND $PKGMGR_OPTS ${compile_packages}
fi
fi
}
Expand Down Expand Up @@ -162,10 +168,9 @@ for sibling in ${ZUUL_SIBLINGS:-}; do
done

if [ -z $PKGMGR_PRESERVE_CACHE ]; then
$PKGMGR clean all
rm -rf /var/cache/{dnf,yum}
$PKGMGR $PKGMGR_CLEAN_ALL_COMMAND
rm -rf $PKGMGR_CACHE_LOCATION
fi

rm -rf /var/lib/dnf/history.*
rm -rf /var/log/{dnf.*,hawkey.log}
rm -rf $PKGMGR_CLEANUP_LOCATIONS
rm -rf /tmp/venv
19 changes: 12 additions & 7 deletions src/ansible_builder/_target_scripts/install-from-bindep
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,20 @@ set -ex
# NOTE(pabelanger): Allow users to force either microdnf or dnf as a package
# manager.
PKGMGR="${PKGMGR:-}"
PKGMGR_CLEAN_ALL_COMMAND="${PKGMGR_CLEAN_ALL_COMMAND:-clean all}"
PKGMGR_CACHE_LOCATION="${PKGMGR_CACHE_LOCATION:-/var/cache/{dnf,yum\}}"
PKGMGR_CLEANUP_LOCATIONS="${PKGMGR_CLEANUP_LOCATIONS:-/var/lib/dnf/history.* /var/log/{dnf.*,hawkey.log\}}"
PKGMGR_INSTALL_COMMAND="${PKGMGR_INSTALL_COMMAND:-install -y}"
PKGMGR_OPTS="${PKGMGR_OPTS:-}"
PKGMGR_PRESERVE_CACHE="${PKGMGR_PRESERVE_CACHE:-}"

PYCMD="${PYCMD:=/usr/bin/python3}"
PIPCMD="${PIPCMD:=$PYCMD -m pip}"
PIP_OPTS="${PIP_OPTS-}"

$PYCMD -m ensurepip
if [ $PY_DISABLE_ENSUREPIP != "true" ]; then
$PYCMD -m ensurepip
fi

if [ -z $PKGMGR ]; then
# Expect dnf to be installed, however if we find microdnf default to it.
Expand All @@ -48,14 +54,14 @@ fi
if [ -f /output/bindep/run.txt ] ; then
PACKAGES=$(cat /output/bindep/run.txt)
if [ ! -z "$PACKAGES" ]; then
$PKGMGR install -y $PKGMGR_OPTS $PACKAGES
$PKGMGR $PKGMGR_INSTALL_COMMAND $PKGMGR_OPTS $PACKAGES
fi
fi

if [ -f /output/bindep/epel.txt ] ; then
EPEL_PACKAGES=$(cat /output/bindep/epel.txt)
if [ ! -z "$EPEL_PACKAGES" ]; then
$PKGMGR install -y $PKGMGR_OPTS --enablerepo epel $EPEL_PACKAGES
$PKGMGR $PKGMGR_INSTALL_COMMAND $PKGMGR_OPTS --enablerepo epel $EPEL_PACKAGES
fi
fi

Expand Down Expand Up @@ -99,9 +105,8 @@ fi

# clean up after ourselves, unless requested to keep the cache
if [[ "$PKGMGR_PRESERVE_CACHE" != always ]]; then
$PKGMGR clean all
rm -rf /var/cache/{dnf,yum}
$PKGMGR $PKGMGR_CLEAN_ALL_COMMAND
rm -rf $PKGMGR_CACHE_LOCATION
fi

rm -rf /var/lib/dnf/history.*
rm -rf /var/log/{dnf.*,hawkey.log}
rm -rf $PKGMGR_CLEANUP_LOCATIONS
4 changes: 4 additions & 0 deletions src/ansible_builder/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
# this value is removed elsewhere for v3+ schemas
EE_BUILDER_IMAGE='quay.io/ansible/ansible-builder:latest',
PKGMGR_PRESERVE_CACHE='',
PKGMGR_CLEAN_ALL_COMMAND='clean all',
PKGMGR_CACHE_LOCATION='/var/cache/{dnf,yum}',
PKGMGR_CLEANUP_LOCATIONS='/var/lib/dnf/history.* /var/log/{dnf.*,hawkey.log}',
PKGMGR_INSTALL_COMMAND='install -y',
)

user_content_subfolder = '_build'
Expand Down
8 changes: 7 additions & 1 deletion src/ansible_builder/containerfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ def prepare(self):
self.steps.append('RUN $PKGMGR install $PYPKG -y ; if [ -z $PKGMGR_PRESERVE_CACHE ]; then $PKGMGR clean all; fi')

# We should always make sure pip is available for later stages.
self.steps.append('RUN $PYCMD -m ensurepip')
if not self.definition.options.get('disable_ensurepip'):
self.steps.append('RUN $PYCMD -m ensurepip')

if self.definition.ansible_ref_install_list:
self.steps.append('RUN $PYCMD -m pip install --no-cache-dir $ANSIBLE_INSTALL_REFS')
Expand Down Expand Up @@ -208,10 +209,15 @@ def _insert_global_args(self, include_values: bool = False):
'ANSIBLE_GALAXY_CLI_COLLECTION_OPTS': self.definition.build_arg_defaults['ANSIBLE_GALAXY_CLI_COLLECTION_OPTS'],
'ANSIBLE_GALAXY_CLI_ROLE_OPTS': self.definition.build_arg_defaults['ANSIBLE_GALAXY_CLI_ROLE_OPTS'],
'ANSIBLE_INSTALL_REFS': self.definition.ansible_ref_install_list,
'PY_DISABLE_ENSUREPIP': 'true' if self.definition.options.get('disable_ensurepip') else '',
}

if self.definition.version >= 3:
global_args['PKGMGR'] = self.definition.options['package_manager_path']
global_args['PKGMGR_CLEAN_ALL_COMMAND'] = self.definition.build_arg_defaults['PKGMGR_CLEAN_ALL_COMMAND']
global_args['PKGMGR_CACHE_LOCATION'] = self.definition.build_arg_defaults['PKGMGR_CACHE_LOCATION']
global_args['PKGMGR_CLEANUP_LOCATIONS'] = self.definition.build_arg_defaults['PKGMGR_CLEANUP_LOCATIONS']
global_args['PKGMGR_INSTALL_COMMAND'] = self.definition.build_arg_defaults['PKGMGR_INSTALL_COMMAND']

for arg, value in global_args.items():
if value is None:
Expand Down
17 changes: 17 additions & 0 deletions src/ansible_builder/ee_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,18 @@
"PKGMGR_PRESERVE_CACHE": {
"type": "string",
},
"PKGMGR_CLEAN_ALL_COMMAND": {
"type": "string",
},
"PKGMGR_CACHE_LOCATION": {
"type": "string",
},
"PKGMGR_CLEANUP_LOCATIONS": {
"type": "string",
},
"PKGMGR_INSTALL_COMMAND": {
"type": "string",
},
},
},

Expand Down Expand Up @@ -353,6 +365,10 @@
"description": "Sets the username or UID",
"type": "string",
},
"disable_ensurepip": {
"description": "Disable running ensurepip",
"type": "boolean",
},
"container_init": {
"description": "Customize container startup behavior",
"type": "object",
Expand Down Expand Up @@ -435,6 +451,7 @@ def _handle_options_defaults(ee_def: dict):
entrypoint_path = os.path.join(constants.FINAL_IMAGE_BIN_PATH, "entrypoint")

options.setdefault('skip_ansible_check', False)
options.setdefault('disable_ensurepip', False)
options.setdefault('relax_passwd_permissions', True)
options.setdefault('workdir', '/runner')
options.setdefault('package_manager_path', '/usr/bin/dnf')
Expand Down