From cb7edfdc3734db04e2b8f57d7c80bbde2cdd007e Mon Sep 17 00:00:00 2001 From: Michael Kriese Date: Mon, 5 Feb 2024 11:57:57 +0100 Subject: [PATCH] refactor: rename and move files (#2134) --- .../install-legacy-tool.service.ts | 12 +- .../prepare-legacy-tools.service.ts | 2 +- src/usr/local/bin/install-containerbase | 110 +---------------- .../bin/docker-entrypoint.sh | 0 .../bin/install-apt.sh} | 0 .../bin/install-containerbase.sh | 112 ++++++++++++++++++ .../bin/{install-tool => install-tool.sh} | 0 .../bin/{prepare-tool => prepare-tool.sh} | 0 8 files changed, 123 insertions(+), 113 deletions(-) rename src/usr/local/{ => containerbase}/bin/docker-entrypoint.sh (100%) rename src/usr/local/{bin/install-apt => containerbase/bin/install-apt.sh} (100%) create mode 100755 src/usr/local/containerbase/bin/install-containerbase.sh rename src/usr/local/containerbase/bin/{install-tool => install-tool.sh} (100%) rename src/usr/local/containerbase/bin/{prepare-tool => prepare-tool.sh} (100%) diff --git a/src/cli/install-tool/install-legacy-tool.service.ts b/src/cli/install-tool/install-legacy-tool.service.ts index ffe7290d8..e1d51022b 100644 --- a/src/cli/install-tool/install-legacy-tool.service.ts +++ b/src/cli/install-tool/install-legacy-tool.service.ts @@ -18,9 +18,13 @@ export class InstallLegacyToolService { env.PIP_INDEX_URL = pipIndex; } - await execa('/usr/local/containerbase/bin/install-tool', [tool, version], { - stdio: ['inherit', 'inherit', 1], - env, - }); + await execa( + '/usr/local/containerbase/bin/install-tool.sh', + [tool, version], + { + stdio: ['inherit', 'inherit', 1], + env, + }, + ); } } diff --git a/src/cli/prepare-tool/prepare-legacy-tools.service.ts b/src/cli/prepare-tool/prepare-legacy-tools.service.ts index 3900b2090..6691a62c8 100644 --- a/src/cli/prepare-tool/prepare-legacy-tools.service.ts +++ b/src/cli/prepare-tool/prepare-legacy-tools.service.ts @@ -6,7 +6,7 @@ import { logger } from '../utils'; export class PrepareLegacyToolsService { async execute(tools: string[]): Promise { logger.debug(`Preparing legacy tools ${tools.join(', ')} ...`); - await execa('/usr/local/containerbase/bin/prepare-tool', tools, { + await execa('/usr/local/containerbase/bin/prepare-tool.sh', tools, { stdio: ['inherit', 'inherit', 1], }); } diff --git a/src/usr/local/bin/install-containerbase b/src/usr/local/bin/install-containerbase index 9f14eb495..c65b8c330 100755 --- a/src/usr/local/bin/install-containerbase +++ b/src/usr/local/bin/install-containerbase @@ -1,110 +1,4 @@ #!/bin/bash -set -e - -# USER_NAME and USER_ID need to be defined as the -# decision which paths are used are based on this information -if [[ -z "${USER_NAME}" ]]; then - export USER_NAME=ubuntu - echo "No USER_NAME defined - using: ${USER_NAME}" -fi - -if [[ -z "${USER_ID}" ]]; then - export USER_ID=1000 - echo "No USER_ID defined - using: ${USER_ID}" -fi - -if [[ -z "${PRIMARY_GROUP_ID}" ]]; then - export PRIMARY_GROUP_ID=0 - echo "No PRIMARY_GROUP_ID defined - using: ${PRIMARY_GROUP_ID}" -fi - -# shellcheck source=/dev/null -. /usr/local/containerbase/util.sh - -if [[ -n "${BASH_ENV}" && "${BASH_ENV}" != "${ENV_FILE}" ]]; then - echo "Wrong BASH_ENV defined - skipping: ${BASH_ENV}" - exit 1; -fi - -# no duplicate installs -if [[ -n "${CONTAINERBASE_ENV+x}" ]]; then - echo "CONTAINERBASE_ENV defined - skipping: ${CONTAINERBASE_ENV}" - exit 1; -fi - -require_arch -require_distro -require_root - -setup_env_files - -echo "APT::Install-Recommends \"false\";" | tee -a /etc/apt/apt.conf.d/containerbase.conf -echo "APT::Get::Install-Suggests \"false\";" | tee -a /etc/apt/apt.conf.d/containerbase.conf - -# Set up user and home directory -createUser - -# create env helper paths -mkdir /usr/local/env.d -su "${USER_NAME}" -c "mkdir -p \"/home/${USER_NAME}/\"{env.d,bin}" - -if [[ "$PATH" =~ (^|:)"/home/${USER_NAME}/bin"(:|$) ]]; then - echo "export PATH=\"/home/${USER_NAME}/bin:\${PATH}\"" >> "$ENV_FILE" -fi - -# OpenShift -chmod -R g+w "/home/${USER_NAME}" - -export_env DEBIAN_FRONTEND "noninteractive" -export_env LC_ALL "C.UTF-8" -export_env LANG "C.UTF-8" - -# upgrade base packages -apt_upgrade - -# install basic required packages -apt_install \ - ca-certificates \ - curl \ - dumb-init \ - gnupg \ - jq \ - libarchive-tools \ - openssh-client \ - unzip \ - xz-utils \ - zstd \ - ; - -# check for /usr/local/share/ca-certificates/*.crt - -if [[ "$(find /usr/local/share/ca-certificates/ -name "*.crt" -type f -printf '.' | wc -c)" -gt 0 ]]; then - echo "Found user certs, calling update-ca-certificates" - update-ca-certificates -fi - -function link_tool () { - ln -sf /usr/local/containerbase/bin/containerbase-cli /usr/local/bin/containerbase-cli - ln -sf /usr/local/containerbase/bin/containerbase-cli /usr/local/bin/install-gem - ln -sf /usr/local/containerbase/bin/containerbase-cli /usr/local/bin/install-npm - ln -sf /usr/local/containerbase/bin/containerbase-cli /usr/local/bin/install-tool - ln -sf /usr/local/containerbase/bin/containerbase-cli /usr/local/bin/prepare-tool - - containerbase-cli --version -} -link_tool - - -# do this at the end as we are overwriting certain env vars and functions -function prepare_v2_tools () { - # setup directories for v2 tools - # shellcheck source=/dev/null - . /usr/local/containerbase/utils/v2/overrides.sh - - setup_directories -} -prepare_v2_tools - -# cleanup -rm -rf /var/lib/apt/lists/* /var/log/dpkg.* /var/log/apt +# simple wrapper to install containerbase +/usr/local/containerbase/bin/install-containerbase.sh "$@" diff --git a/src/usr/local/bin/docker-entrypoint.sh b/src/usr/local/containerbase/bin/docker-entrypoint.sh similarity index 100% rename from src/usr/local/bin/docker-entrypoint.sh rename to src/usr/local/containerbase/bin/docker-entrypoint.sh diff --git a/src/usr/local/bin/install-apt b/src/usr/local/containerbase/bin/install-apt.sh similarity index 100% rename from src/usr/local/bin/install-apt rename to src/usr/local/containerbase/bin/install-apt.sh diff --git a/src/usr/local/containerbase/bin/install-containerbase.sh b/src/usr/local/containerbase/bin/install-containerbase.sh new file mode 100755 index 000000000..eb7bde3df --- /dev/null +++ b/src/usr/local/containerbase/bin/install-containerbase.sh @@ -0,0 +1,112 @@ +#!/bin/bash + +set -e + +# USER_NAME and USER_ID need to be defined as the +# decision which paths are used are based on this information +if [[ -z "${USER_NAME}" ]]; then + export USER_NAME=ubuntu + echo "No USER_NAME defined - using: ${USER_NAME}" +fi + +if [[ -z "${USER_ID}" ]]; then + export USER_ID=1000 + echo "No USER_ID defined - using: ${USER_ID}" +fi + +if [[ -z "${PRIMARY_GROUP_ID}" ]]; then + export PRIMARY_GROUP_ID=0 + echo "No PRIMARY_GROUP_ID defined - using: ${PRIMARY_GROUP_ID}" +fi + +# shellcheck source=/dev/null +. /usr/local/containerbase/util.sh + +if [[ -n "${BASH_ENV}" && "${BASH_ENV}" != "${ENV_FILE}" ]]; then + echo "Wrong BASH_ENV defined - skipping: ${BASH_ENV}" + exit 1; +fi + +# no duplicate installs +if [[ -n "${CONTAINERBASE_ENV+x}" ]]; then + echo "CONTAINERBASE_ENV defined - skipping: ${CONTAINERBASE_ENV}" + exit 1; +fi + +require_arch +require_distro +require_root + +setup_env_files + +echo "APT::Install-Recommends \"false\";" | tee -a /etc/apt/apt.conf.d/containerbase.conf +echo "APT::Get::Install-Suggests \"false\";" | tee -a /etc/apt/apt.conf.d/containerbase.conf + +# Set up user and home directory +createUser + +# create env helper paths +mkdir /usr/local/env.d +su "${USER_NAME}" -c "mkdir -p \"/home/${USER_NAME}/\"{env.d,bin}" + +if [[ "$PATH" =~ (^|:)"/home/${USER_NAME}/bin"(:|$) ]]; then + echo "export PATH=\"/home/${USER_NAME}/bin:\${PATH}\"" >> "$ENV_FILE" +fi + +# OpenShift +chmod -R g+w "/home/${USER_NAME}" + +export_env DEBIAN_FRONTEND "noninteractive" +export_env LC_ALL "C.UTF-8" +export_env LANG "C.UTF-8" + +# upgrade base packages +apt_upgrade + +# install basic required packages +apt_install \ + ca-certificates \ + curl \ + dumb-init \ + gnupg \ + jq \ + libarchive-tools \ + openssh-client \ + unzip \ + xz-utils \ + zstd \ + ; + +# check for /usr/local/share/ca-certificates/*.crt + +if [[ "$(find /usr/local/share/ca-certificates/ -name "*.crt" -type f -printf '.' | wc -c)" -gt 0 ]]; then + echo "Found user certs, calling update-ca-certificates" + update-ca-certificates +fi + +function link_tools () { + ln -sf /usr/local/containerbase/bin/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh + ln -sf /usr/local/containerbase/bin/install-apt.sh /usr/local/bin/install-apt + ln -sf /usr/local/containerbase/bin/containerbase-cli /usr/local/bin/containerbase-cli + ln -sf /usr/local/containerbase/bin/containerbase-cli /usr/local/bin/install-gem + ln -sf /usr/local/containerbase/bin/containerbase-cli /usr/local/bin/install-npm + ln -sf /usr/local/containerbase/bin/containerbase-cli /usr/local/bin/install-tool + ln -sf /usr/local/containerbase/bin/containerbase-cli /usr/local/bin/prepare-tool + + containerbase-cli --version +} +link_tools + + +# do this at the end as we are overwriting certain env vars and functions +function prepare_v2_tools () { + # setup directories for v2 tools + # shellcheck source=/dev/null + . /usr/local/containerbase/utils/v2/overrides.sh + + setup_directories +} +prepare_v2_tools + +# cleanup +rm -rf /var/lib/apt/lists/* /var/log/dpkg.* /var/log/apt diff --git a/src/usr/local/containerbase/bin/install-tool b/src/usr/local/containerbase/bin/install-tool.sh similarity index 100% rename from src/usr/local/containerbase/bin/install-tool rename to src/usr/local/containerbase/bin/install-tool.sh diff --git a/src/usr/local/containerbase/bin/prepare-tool b/src/usr/local/containerbase/bin/prepare-tool.sh similarity index 100% rename from src/usr/local/containerbase/bin/prepare-tool rename to src/usr/local/containerbase/bin/prepare-tool.sh