-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[wip]feat: changes to support network restricted environments when creating RHEL OS bundles #1156
base: release-2.9
Are you sure you want to change the base?
Changes from 9 commits
2e03bda
0fde978
a31ed33
6780622
2bf665e
aacf5de
a3512a5
a7e0b86
5765f64
c37a61f
8cb5c52
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ set -euo pipefail | |
|
||
# When yum operates on multiple packages, it does not, by default, return an error if a subset | ||
# of packages is not found. This makes yum return an error. | ||
echo skip_missing_names_on_install=False >> /etc/yum.conf | ||
echo skip_missing_names_on_install=False >>/etc/yum.conf | ||
|
||
sed -i 's/\(def in_container():\)/\1\n return False/g' /usr/lib64/python*/*-packages/rhsm/config.py | ||
FOUND=false | ||
|
@@ -13,57 +13,94 @@ RHSM_ACTIVATION_KEY=${RHSM_ACTIVATION_KEY:-""} | |
RHSM_USER=${RHSM_USER:-""} | ||
RHSM_PASS=${RHSM_PASS:-""} | ||
|
||
if [[ -n "${RHSM_ORG_ID}" && -n "${RHSM_ACTIVATION_KEY}" ]]; then | ||
subscription-manager register --org="${RHSM_ORG_ID}" --activationkey="${RHSM_ACTIVATION_KEY}" --force | ||
FOUND=true | ||
fi | ||
SKIP_SUBSCRIPTION_MANAGER=${SKIP_SUBSCRIPTION_MANAGER:-""} | ||
SATELLITE_SERVER_URL=${SATELLITE_SERVER_URL:-""} | ||
ENABLED_REPOS=${ENABLED_REPOS:-""} | ||
|
||
if [[ -n "${RHSM_USER}" && -n "${RHSM_PASS}" && ${FOUND} == false ]]; then | ||
subscription-manager register --username="${RHSM_USER}" --password="${RHSM_PASS}" --force | ||
FOUND=true | ||
fi | ||
if [[ -z "${SKIP_SUBSCRIPTION_MANAGER}" ]]; then | ||
if [[ -n "${SATELLITE_SERVER_URL}" ]]; then | ||
rpm -ivh "${SATELLITE_SERVER_URL}/pub/katello-ca-consumer-latest.noarch.rpm" | ||
fi | ||
|
||
if [[ ${FOUND} == false ]]; then | ||
echo "You must use subscription manager to fetch packages for redhat" | ||
exit 1 | ||
fi | ||
if [[ -n "${RHSM_ORG_ID}" && -n "${RHSM_ACTIVATION_KEY}" ]]; then | ||
subscription-manager register --org="${RHSM_ORG_ID}" --activationkey="${RHSM_ACTIVATION_KEY}" --force | ||
FOUND=true | ||
fi | ||
|
||
if [[ -n "${RHSM_USER}" && -n "${RHSM_PASS}" && ${FOUND} == false ]]; then | ||
subscription-manager register --username="${RHSM_USER}" --password="${RHSM_PASS}" --force | ||
FOUND=true | ||
fi | ||
|
||
if [[ ${FOUND} == false ]]; then | ||
echo "You must use subscription manager to fetch packages for redhat" | ||
exit 1 | ||
fi | ||
|
||
subscription::unregister() { | ||
subscription-manager unregister | ||
} | ||
subscription::unregister() { | ||
subscription-manager unregister | ||
} | ||
|
||
subscription::defer_unregister() { | ||
subscription::defer_unregister() { | ||
trap subscription::unregister ABRT | ||
trap subscription::unregister EXIT | ||
trap subscription::unregister HUP | ||
trap subscription::unregister INT | ||
trap subscription::unregister TERM | ||
trap subscription::unregister USR1 | ||
trap subscription::unregister USR2 | ||
} | ||
} | ||
|
||
subscription-manager release --set=8.6 | ||
subscription-manager refresh | ||
subscription::defer_unregister | ||
|
||
ENABLED_REPOS="kubernetes,codeready-builder-for-rhel-8-x86_64-rpms,rhel-8-for-x86_64-appstream-rpms,rhel-8-for-x86_64-baseos-rpms" | ||
EUS_REPOS=${EUS_REPOS:-""} | ||
if [[ -n "${EUS_REPOS}" ]]; then | ||
#disables the standard repositories which should not be enabled when using EUS | ||
subscription-manager repos --disable=rhel-8-for-x86_64-baseos-rpms --disable=rhel-8-for-x86_64-appstream-rpms | ||
subscription-manager repos --enable rhel-8-for-x86_64-baseos-eus-rpms | ||
subscription-manager repos --enable rhel-8-for-x86_64-appstream-eus-rpms | ||
subscription-manager repos --enable codeready-builder-for-rhel-8-x86_64-eus-rpms | ||
ENABLED_REPOS="kubernetes,codeready-builder-for-rhel-8-x86_64-eus-rpms,rhel-8-for-x86_64-appstream-eus-rpms,rhel-8-for-x86_64-baseos-eus-rpms" | ||
else | ||
subscription-manager repos --enable codeready-builder-for-rhel-8-x86_64-rpms | ||
subscription-manager repos --enable rhel-8-for-x86_64-appstream-rpms | ||
subscription-manager repos --enable rhel-8-for-x86_64-baseos-rpms | ||
fi | ||
else | ||
echo "Bypassing subscription-manager and upstream RHEL repositories due to --skip-subscription-manager being set to true." | ||
fi | ||
|
||
if [[ -f /etc/yum.repos.d/user-repos.repo ]]; then | ||
USER_REPOS="$(awk -F '[][]' '/^\[.*\]/ {print $2}' /etc/yum.repos.d/user-repos.repo | paste -sd, -)" | ||
if [[ -n "${ENABLED_REPOS}" ]] && [[ -n "${USER_REPOS}" ]]; then | ||
ENABLED_REPOS="${ENABLED_REPOS},${USER_REPOS}" | ||
elif [[ -z "${ENABLED_REPOS}" ]] && [[ -n "${USER_REPOS}" ]]; then | ||
ENABLED_REPOS="${USER_REPOS}" | ||
fi | ||
fi | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can think of another way of handling this. not a huge fan of usig awk this way There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
subscription-manager release --set=8.6 | ||
subscription-manager refresh | ||
subscription::defer_unregister | ||
subscription-manager repos --enable rhel-8-for-x86_64-baseos-eus-rpms | ||
subscription-manager repos --enable codeready-builder-for-rhel-8-x86_64-rpms | ||
subscription-manager repos --enable rhel-8-for-x86_64-appstream-rpms | ||
yum -y install gettext yum-utils createrepo dnf-utils modulemd-tools | ||
yum -y install --disablerepo=* --enablerepo="${ENABLED_REPOS}" gettext yum-utils createrepo dnf-utils modulemd-tools | ||
yum clean all | ||
TMP_DIR="$(mktemp -d repodata-XXXX)" | ||
chmod 777 -R "${TMP_DIR}" | ||
cp packages.txt "${TMP_DIR}" | ||
pushd "${TMP_DIR}" | ||
#shellcheck disable=SC2046,SC2062,SC2063,SC2035 | ||
repoquery --archlist=x86_64,noarch --resolve --requires --recursive $(< packages.txt) | grep -v *.i686 >> reqs.txt | ||
sed -i 1d reqs.txt # we need to get rid of the first line | ||
repoquery --disablerepo=* --enablerepo="${ENABLED_REPOS}" \ | ||
--archlist=x86_64,noarch --resolve --requires --recursive $(<packages.txt) \ | ||
| grep -vE '*.i686|^[[:space:]]*$|Unable to read consumer identity|This system is not registered with an entitlement server|Updating Subscription Management repositories' >>reqs.txt | ||
#shellcheck disable=SC2046 | ||
yumdownloader --archlist=x86_64,noarch --setopt=skip_missing_names_on_install=False -x \*i686 $(< reqs.txt) | ||
yumdownloader --disablerepo=* --enablerepo="${ENABLED_REPOS}" \ | ||
--setopt=skip_missing_names_on_install=False -x \*i686 --archlist=x86_64,noarch $(<reqs.txt) | ||
#shellcheck disable=SC2046 | ||
yumdownloader --setopt=skip_missing_names_on_install=False -x \*i686 --archlist=x86_64,noarch --resolve --disablerepo=* --enablerepo=kubernetes,rhel-8-for-x86_64-baseos-eus-rpms,codeready-builder-for-rhel-8-x86_64-rpms,rhel-8-for-x86_64-appstream-rpms $(< packages.txt) | ||
yumdownloader --disablerepo=* --enablerepo="${ENABLED_REPOS}" \ | ||
--setopt=skip_missing_names_on_install=False -x \*i686 --archlist=x86_64,noarch \ | ||
--resolve $(<packages.txt) | ||
rm packages.txt reqs.txt | ||
curl https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/linux_amd64/amazon-ssm-agent.rpm -o amazon-ssm-agent.rpm | ||
createrepo -v . | ||
chown -R 1000:1000 repodata/ | ||
repo2module . --module-name offline | ||
createrepo_mod . | ||
#shellcheck disable=SC1083,SC2035 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ set -euo pipefail | |
|
||
# When yum operates on multiple packages, it does not, by default, return an error if a subset | ||
# of packages is not found. This makes yum return an error. | ||
echo skip_missing_names_on_install=False >> /etc/yum.conf | ||
echo skip_missing_names_on_install=False >>/etc/yum.conf | ||
|
||
sed -i 's/\(def in_container():\)/\1\n return False/g' /usr/lib64/python*/*-packages/rhsm/config.py | ||
FOUND=false | ||
|
@@ -13,57 +13,94 @@ RHSM_ACTIVATION_KEY=${RHSM_ACTIVATION_KEY:-""} | |
RHSM_USER=${RHSM_USER:-""} | ||
RHSM_PASS=${RHSM_PASS:-""} | ||
|
||
if [[ -n "${RHSM_ORG_ID}" && -n "${RHSM_ACTIVATION_KEY}" ]]; then | ||
subscription-manager register --org="${RHSM_ORG_ID}" --activationkey="${RHSM_ACTIVATION_KEY}" --force | ||
FOUND=true | ||
fi | ||
SKIP_SUBSCRIPTION_MANAGER=${SKIP_SUBSCRIPTION_MANAGER:-""} | ||
SATELLITE_SERVER_URL=${SATELLITE_SERVER_URL:-""} | ||
ENABLED_REPOS=${ENABLED_REPOS:-""} | ||
|
||
if [[ -n "${RHSM_USER}" && -n "${RHSM_PASS}" && ${FOUND} == false ]]; then | ||
subscription-manager register --username="${RHSM_USER}" --password="${RHSM_PASS}" --force | ||
FOUND=true | ||
fi | ||
if [[ -z "${SKIP_SUBSCRIPTION_MANAGER}" ]]; then | ||
if [[ -n "${SATELLITE_SERVER_URL}" ]]; then | ||
rpm -ivh "${SATELLITE_SERVER_URL}/pub/katello-ca-consumer-latest.noarch.rpm" | ||
fi | ||
|
||
if [[ ${FOUND} == false ]]; then | ||
echo "You must use subscription manager to fetch packages for redhat" | ||
exit 1 | ||
fi | ||
if [[ -n "${RHSM_ORG_ID}" && -n "${RHSM_ACTIVATION_KEY}" ]]; then | ||
subscription-manager register --org="${RHSM_ORG_ID}" --activationkey="${RHSM_ACTIVATION_KEY}" --force | ||
FOUND=true | ||
fi | ||
|
||
if [[ -n "${RHSM_USER}" && -n "${RHSM_PASS}" && ${FOUND} == false ]]; then | ||
subscription-manager register --username="${RHSM_USER}" --password="${RHSM_PASS}" --force | ||
FOUND=true | ||
fi | ||
|
||
if [[ ${FOUND} == false ]]; then | ||
echo "You must use subscription manager to fetch packages for redhat" | ||
exit 1 | ||
fi | ||
|
||
subscription::unregister() { | ||
subscription-manager unregister | ||
} | ||
subscription::unregister() { | ||
subscription-manager unregister | ||
} | ||
|
||
subscription::defer_unregister() { | ||
subscription::defer_unregister() { | ||
trap subscription::unregister ABRT | ||
trap subscription::unregister EXIT | ||
trap subscription::unregister HUP | ||
trap subscription::unregister INT | ||
trap subscription::unregister TERM | ||
trap subscription::unregister USR1 | ||
trap subscription::unregister USR2 | ||
} | ||
} | ||
|
||
subscription-manager release --set=8.8 | ||
subscription-manager refresh | ||
subscription::defer_unregister | ||
|
||
ENABLED_REPOS="kubernetes,codeready-builder-for-rhel-8-x86_64-rpms,rhel-8-for-x86_64-appstream-rpms,rhel-8-for-x86_64-baseos-rpms" | ||
EUS_REPOS=${EUS_REPOS:-""} | ||
if [[ -n "${EUS_REPOS}" ]]; then | ||
#disables the standard repositories which should not be enabled when using EUS | ||
subscription-manager repos --disable=rhel-8-for-x86_64-baseos-rpms --disable=rhel-8-for-x86_64-appstream-rpms | ||
subscription-manager repos --enable rhel-8-for-x86_64-baseos-eus-rpms | ||
subscription-manager repos --enable rhel-8-for-x86_64-appstream-eus-rpms | ||
subscription-manager repos --enable codeready-builder-for-rhel-8-x86_64-eus-rpms | ||
ENABLED_REPOS="kubernetes,codeready-builder-for-rhel-8-x86_64-eus-rpms,rhel-8-for-x86_64-appstream-eus-rpms,rhel-8-for-x86_64-baseos-eus-rpms" | ||
else | ||
subscription-manager repos --enable codeready-builder-for-rhel-8-x86_64-rpms | ||
subscription-manager repos --enable rhel-8-for-x86_64-appstream-rpms | ||
subscription-manager repos --enable rhel-8-for-x86_64-baseos-rpms | ||
fi | ||
else | ||
echo "Bypassing subscription-manager and upstream RHEL repositories due to --skip-subscription-manager being set to true." | ||
fi | ||
|
||
if [[ -f /etc/yum.repos.d/user-repos.repo ]]; then | ||
USER_REPOS="$(awk -F '[][]' '/^\[.*\]/ {print $2}' /etc/yum.repos.d/user-repos.repo | paste -sd, -)" | ||
if [[ -n "${ENABLED_REPOS}" ]] && [[ -n "${USER_REPOS}" ]]; then | ||
ENABLED_REPOS="${ENABLED_REPOS},${USER_REPOS}" | ||
elif [[ -z "${ENABLED_REPOS}" ]] && [[ -n "${USER_REPOS}" ]]; then | ||
ENABLED_REPOS="${USER_REPOS}" | ||
fi | ||
fi | ||
|
||
subscription-manager release --set=8.8 | ||
subscription-manager refresh | ||
subscription::defer_unregister | ||
subscription-manager repos --enable rhel-8-for-x86_64-baseos-eus-rpms | ||
subscription-manager repos --enable codeready-builder-for-rhel-8-x86_64-rpms | ||
subscription-manager repos --enable rhel-8-for-x86_64-appstream-rpms | ||
yum -y install gettext yum-utils createrepo dnf-utils modulemd-tools | ||
yum -y install --disablerepo=* --enablerepo="${ENABLED_REPOS}" gettext yum-utils createrepo dnf-utils modulemd-tools | ||
yum clean all | ||
TMP_DIR="$(mktemp -d repodata-XXXX)" | ||
chmod 777 -R "${TMP_DIR}" | ||
cp packages.txt "${TMP_DIR}" | ||
pushd "${TMP_DIR}" | ||
#shellcheck disable=SC2046,SC2062,SC2063,SC2035 | ||
repoquery --archlist=x86_64,noarch --resolve --requires --recursive $(< packages.txt) | grep -v *.i686 >> reqs.txt | ||
sed -i 1d reqs.txt # we need to get rid of the first line | ||
repoquery --disablerepo=* --enablerepo="${ENABLED_REPOS}" \ | ||
--archlist=x86_64,noarch --resolve --requires --recursive $(<packages.txt) \ | ||
| grep -vE '*.i686|^[[:space:]]*$|Unable to read consumer identity|This system is not registered with an entitlement server|Updating Subscription Management repositories' >>reqs.txt | ||
#shellcheck disable=SC2046 | ||
yumdownloader --archlist=x86_64,noarch --setopt=skip_missing_names_on_install=False -x \*i686 $(< reqs.txt) | ||
yumdownloader --disablerepo=* --enablerepo="${ENABLED_REPOS}" \ | ||
--setopt=skip_missing_names_on_install=False -x \*i686 --archlist=x86_64,noarch $(<reqs.txt) | ||
#shellcheck disable=SC2046 | ||
yumdownloader --setopt=skip_missing_names_on_install=False -x \*i686 --archlist=x86_64,noarch --resolve --disablerepo=* --enablerepo=kubernetes,rhel-8-for-x86_64-baseos-eus-rpms,codeready-builder-for-rhel-8-x86_64-rpms,rhel-8-for-x86_64-appstream-rpms $(< packages.txt) | ||
yumdownloader --disablerepo=* --enablerepo="${ENABLED_REPOS}" \ | ||
--setopt=skip_missing_names_on_install=False -x \*i686 --archlist=x86_64,noarch \ | ||
--resolve $(<packages.txt) | ||
rm packages.txt reqs.txt | ||
curl https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/linux_amd64/amazon-ssm-agent.rpm -o amazon-ssm-agent.rpm | ||
createrepo -v . | ||
chown -R 1000:1000 repodata/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this removed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed from main. |
||
repo2module . --module-name offline | ||
createrepo_mod . | ||
#shellcheck disable=SC1083,SC2035 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This requires users to define their rpm repos in
repo-templates/user-repos.repo
. We will need to document this workflow.While KIB CLI automatically adds any repo files in
repo-templates/
to/etc/yum.repos.d
, we need to selectively enable/disable repos that already exist there (e.g.,/etc/yum.repos.d/ubi.repo
). We could only parse files other than the pre-existing ones, but maybe it is simpler to just have one file that users modify and we look for.Open to any feedback.