Skip to content
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

refactor: rename and move files #2134

Merged
merged 1 commit into from
Feb 5, 2024
Merged
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
12 changes: 8 additions & 4 deletions src/cli/install-tool/install-legacy-tool.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@
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,
},
);

Check warning on line 28 in src/cli/install-tool/install-legacy-tool.service.ts

View check run for this annotation

Codecov / codecov/patch

src/cli/install-tool/install-legacy-tool.service.ts#L21-L28

Added lines #L21 - L28 were not covered by tests
}
}
2 changes: 1 addition & 1 deletion src/cli/prepare-tool/prepare-legacy-tools.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
export class PrepareLegacyToolsService {
async execute(tools: string[]): Promise<void> {
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, {

Check warning on line 9 in src/cli/prepare-tool/prepare-legacy-tools.service.ts

View check run for this annotation

Codecov / codecov/patch

src/cli/prepare-tool/prepare-legacy-tools.service.ts#L9

Added line #L9 was not covered by tests
stdio: ['inherit', 'inherit', 1],
});
}
Expand Down
110 changes: 2 additions & 108 deletions src/usr/local/bin/install-containerbase
Original file line number Diff line number Diff line change
@@ -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 "$@"
112 changes: 112 additions & 0 deletions src/usr/local/containerbase/bin/install-containerbase.sh
Original file line number Diff line number Diff line change
@@ -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
Loading