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

feat!: redirect folders to /opt/containerbase #2090

Merged
merged 10 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from 9 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
6 changes: 3 additions & 3 deletions docs/custom-base-image.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ CMD [ "bash" ]
COPY my-root-ca.crt /usr/local/share/ca-certificates/my-root-ca.crt

# Set up containerbase
COPY --from=containerbase /usr/local/bin/ /usr/local/bin/
COPY --from=containerbase /usr/local/sbin/ /usr/local/sbin/
COPY --from=containerbase /usr/local/containerbase/ /usr/local/containerbase/
RUN install-containerbase

Expand Down Expand Up @@ -78,7 +78,7 @@ CMD [ "bash" ]
COPY my-root-ca.crt /usr/local/share/ca-certificates/my-root-ca.crt

# Set up containerbase
COPY --from=containerbase /usr/local/bin/ /usr/local/bin/
COPY --from=containerbase /usr/local/sbin/ /usr/local/sbin/
COPY --from=containerbase /usr/local/containerbase/ /usr/local/containerbase/
RUN install-containerbase

Expand Down Expand Up @@ -122,7 +122,7 @@ ENTRYPOINT [ "docker-entrypoint.sh" ]
CMD [ "bash" ]

# Set up containerbase
COPY --from=containerbase /usr/local/bin/ /usr/local/bin/
COPY --from=containerbase /usr/local/sbin/ /usr/local/sbin/
COPY --from=containerbase /usr/local/containerbase/ /usr/local/containerbase/
RUN install-containerbase

Expand Down
2 changes: 1 addition & 1 deletion src/cli/services/path.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface FileOwnerConfig {
@injectable()
export class PathService {
get binDir(): string {
return join(this.envSvc.rootDir, 'usr/local/bin');
return join(this.installDir, 'bin');
}

get envFile(): string {
Expand Down
17 changes: 10 additions & 7 deletions src/usr/local/containerbase/bin/install-containerbase.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ if [[ "$(find /usr/local/share/ca-certificates/ -name "*.crt" -type f -printf '.
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
ln -sf /usr/local/containerbase/bin/docker-entrypoint.sh /usr/local/sbin/docker-entrypoint.sh
ln -sf /usr/local/containerbase/bin/install-apt.sh /usr/local/sbin/install-apt
ln -sf /usr/local/containerbase/bin/containerbase-cli /usr/local/sbin/containerbase-cli
ln -sf /usr/local/containerbase/bin/containerbase-cli /usr/local/sbin/install-gem
ln -sf /usr/local/containerbase/bin/containerbase-cli /usr/local/sbin/install-npm
ln -sf /usr/local/containerbase/bin/containerbase-cli /usr/local/sbin/install-tool
ln -sf /usr/local/containerbase/bin/containerbase-cli /usr/local/sbin/prepare-tool

containerbase-cli --version
}
Expand All @@ -111,6 +111,9 @@ function prepare_v2_tools () {
. /usr/local/containerbase/utils/v2/overrides.sh

setup_directories

# compability with current custom images
ln -sf /usr/local/sbin/install-containerbase /usr/local/bin/install-containerbase
}
prepare_v2_tools

Expand Down
3 changes: 2 additions & 1 deletion src/usr/local/containerbase/utils/constants.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ export ENV_FILE=/usr/local/etc/env
export BASH_RC=/etc/bash.bashrc
# defines the root directory where tools will be installed
export ROOT_DIR=/usr/local
# defines the directory where symlinks to tools will be installed
# defines the directory where shims to tools will be installed
export BIN_DIR=/usr/local/bin
export LIB_DIR=/usr/local/lib
# defines the directory where user tools will be installed
# shellcheck disable=SC2153
export USER_HOME="/home/${USER_NAME}"
Expand Down
16 changes: 9 additions & 7 deletions src/usr/local/containerbase/utils/filesystem.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,18 @@ function setup_directories () {
mkdir -p -m 775 "$(get_version_path)"
# contains the wrapper and symlinks for the tools
# shellcheck disable=SC2174
mkdir -p -m 775 "$(get_bin_path)"
mkdir -p -m 775 "${install_dir}/bin"
# contains nodejs files and maybe others
# shellcheck disable=SC2174
mkdir -p -m 775 "${install_dir}/lib"
# contains the certificates for the tools
# shellcheck disable=SC2174
mkdir -p -m 775 "$(get_ssl_path)"

# if the bin path exists and does not have 775, force it
if [ "$(stat --format '%a' "$(get_bin_path)")" -ne 775 ]; then
echo "Forcing 775 on '$(get_bin_path)' ..."
chmod 775 "$(get_bin_path)"
fi
# symlink v2 tools bin and lib
rm -rf "${BIN_DIR}" "${LIB_DIR}"
ln -sf "${ROOT_DIR}/bin" "${BIN_DIR}"
ln -sf "${ROOT_DIR}/lib" "${LIB_DIR}"
}

# Creates the given folder path with root and user umask depending on the caller
Expand Down Expand Up @@ -95,7 +97,7 @@ function create_folder () {

# Gets the path to the bin folder
function get_bin_path () {
echo "${BIN_DIR}"
echo "${ROOT_DIR}/bin"
}

# Gets the path to the versions folder
Expand Down
4 changes: 2 additions & 2 deletions src/usr/local/containerbase/utils/linking.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

# use this if custom env is required, creates a shell wrapper to /usr/local/bin
# use this if custom env is required, creates a shell wrapper to /opt/containerbase/bin
function shell_wrapper () {
local TARGET
local SOURCE=$2
Expand Down Expand Up @@ -33,7 +33,7 @@ EOM
set_file_owner "${TARGET}" 775
}

# use this for simple symlink to /usr/local/bin
# use this for simple symlink to /opt/containerbase/bin
function link_wrapper () {
local TARGET
local SOURCE=$2
Expand Down
6 changes: 5 additions & 1 deletion test/bash/filesystem.bats
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ teardown() {
}

@test "setup directories with correct permissions" {
local TEST_ROOT_USER=0 # root
local install_dir=$(get_install_dir)

run setup_directories
Expand All @@ -122,8 +123,11 @@ teardown() {
assert [ "$(stat --format '%a' "${install_dir}/tools")" -eq 775 ]
assert [ -d "${install_dir}/versions" ]
assert [ "$(stat --format '%a' "${install_dir}/versions")" -eq 775 ]
assert [ -d "${install_dir}/bin" ]
assert [ "$(stat --format '%a' "${install_dir}/bin")" -eq 775 ]
assert [ -d "${BIN_DIR}" ]
assert [ "$(stat --format '%a' "${BIN_DIR}")" -eq 775 ]
assert [ -L "${BIN_DIR}" ]
assert [ "$(stat --format '%a' "${BIN_DIR}")" -eq 777 ]
assert [ -d "${install_dir}/env.d" ]
assert [ "$(stat --format '%a' "${install_dir}/env.d")" -eq 775 ]
}
Expand Down
2 changes: 2 additions & 0 deletions test/bash/linking.bats
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ setup() {
# load test overwrites
load "$TEST_DIR/util.sh"

mkdir "${ROOT_DIR}/bin"

setup_directories
}

Expand Down
8 changes: 5 additions & 3 deletions test/bash/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export REPO_DIR="${TEST_DIR}/../.."
export CONTAINERBASE_DIR="${REPO_DIR}/src/usr/local/containerbase"
export ROOT_DIR="${TEST_ROOT_DIR}/root"
export BIN_DIR="${TEST_ROOT_DIR}/bin"
export LIB_DIR="${TEST_ROOT_DIR}/lib"
export USER_HOME="${TEST_ROOT_DIR}/user"
export ENV_FILE="${TEST_ROOT_DIR}/env"

Expand All @@ -29,9 +30,10 @@ function link_cli_tool () {
if [[ "${ARCHITECTURE}" = "aarch64" ]];then
arch=arm64
fi
export PATH="${BIN_DIR}:${PATH}"
ln -sf "${REPO_DIR}/dist/cli/containerbase-cli-${arch}" "${BIN_DIR}/containerbase-cli"
export PATH="${TEST_ROOT_DIR}/sbin:${PATH}"
ln -sf "${REPO_DIR}/dist/cli/containerbase-cli-${arch}" "${TEST_ROOT_DIR}/sbin/containerbase-cli"
}

mkdir -p "${BIN_DIR}" "${ROOT_DIR}"
# ensure directories exist
mkdir -p "${TEST_ROOT_DIR}"/{sbin,root,user}
link_cli_tool
6 changes: 3 additions & 3 deletions test/latest/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ SHELL ["/bin/bash" , "-c"]
COPY --from=build /test/ca.pem /usr/local/share/ca-certificates/renovate-ca.crt

# Set up containerbase
COPY --from=build /usr/local/bin/ /usr/local/bin/
COPY --from=build /usr/local/sbin/ /usr/local/sbin/
COPY --from=build /usr/local/containerbase/ /usr/local/containerbase/
RUN install-containerbase

Expand Down Expand Up @@ -179,11 +179,11 @@ RUN install-tool node v20.14.0
RUN install-tool docker v26.1.3

#--------------------------------------
# test: bin path has 775
# test: bin path has 777
#--------------------------------------
FROM base as testd

RUN [ $(stat --format '%a' "/usr/local/bin") -eq 775 ]
RUN [ $(stat --format '%a' "/usr/local/bin") -eq 777 ]

RUN prepare-tool all

Expand Down
4 changes: 4 additions & 0 deletions test/node/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ ARG TARGETARCH
COPY dist/docker/ /
COPY dist/cli/containerbase-cli-${TARGETARCH} /usr/local/containerbase/bin/containerbase-cli

RUN set -ex; ls -la /usr/local/bin/; ls -la /usr/local/sbin;

RUN install-containerbase

RUN set -ex; ls -la /usr/local/bin/; ls -la /usr/local/sbin; ls -la /opt/containerbase/bin;

COPY --chown=1000:0 test/node/test test
RUN chmod -R 775 /test
WORKDIR /test
Expand Down