Skip to content

Commit

Permalink
refactor!: move files to /tmp/containerbase
Browse files Browse the repository at this point in the history
  • Loading branch information
viceice committed Aug 1, 2024
1 parent 4ad4359 commit 12f05c8
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 53 deletions.
2 changes: 1 addition & 1 deletion src/usr/local/containerbase/tools/v2/golang.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function prepare_tool() {
# go suggests: git svn bzr mercurial
apt_install bzr mercurial

go_path=$(get_home_path)/go
go_path=$(get_cache_path)/go

ln -sf "${go_path}" "${USER_HOME}/go"

Expand Down
2 changes: 1 addition & 1 deletion src/usr/local/containerbase/tools/v2/nix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ function link_tool() {
local versioned_tool_path
versioned_tool_path=$(find_versioned_tool_path)

shell_wrapper "${TOOL_NAME}" "${versioned_tool_path}/bin" "NIX_STORE_DIR=$(get_home_path)/nix/store NIX_DATA_DIR=$(get_home_path)/nix/data NIX_LOG_DIR=$(get_cache_path)/nix/log NIX_STATE_DIR=$(get_home_path)/nix/state NIX_CONF_DIR=$(get_home_path)/nix/conf"
shell_wrapper "${TOOL_NAME}" "${versioned_tool_path}/bin" "NIX_STORE_DIR=$(get_cache_path)/nix/store NIX_DATA_DIR=$(get_cache_path)/nix/data NIX_LOG_DIR=$(get_cache_path)/nix/log NIX_STATE_DIR=$(get_cache_path)/nix/state NIX_CONF_DIR=$(get_cache_path)/nix/conf"
[[ -n $SKIP_VERSION ]] || nix --version
}
8 changes: 4 additions & 4 deletions src/usr/local/containerbase/tools/v2/ruby.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function prepare_tool() {
tool_path=$(find_tool_path)

# Redirect gemrc
path="$(get_home_path)/.gemrc"
path="$(get_cache_path)/.gemrc"
{
printf -- "gem: --no-document\n"
} > "${path}"
Expand All @@ -35,21 +35,21 @@ function prepare_tool() {
ln -sf "${path}" "${USER_HOME}/.gemrc"

# Redirect gem home
path="$(get_home_path)/.gem"
path="$(get_cache_path)/.gem"
create_folder "${path}" 775
chown "${USER_ID}" "${path}"
chmod g+w "${path}"
ln -sf "${path}" "${USER_HOME}/.gem"

# Redirect cocoapods home
path="$(get_home_path)/.cocoapods"
path="$(get_cache_path)/.cocoapods"
create_folder "${path}" 775
chown "${USER_ID}" "${path}"
chmod g+w "${path}"
ln -sf "${path}" "${USER_HOME}/.cocoapods"

# Redirect Library home
path="$(get_home_path)/Library"
path="$(get_cache_path)/Library"
create_folder "${path}" 775
chown "${USER_ID}" "${path}"
chmod g+w "${path}"
Expand Down
2 changes: 1 addition & 1 deletion src/usr/local/containerbase/tools/v2/rust.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export NEEDS_PREPARE=1
function prepare_tool() {
local cargo_home

cargo_home=$(get_home_path)/.cargo
cargo_home=$(get_cache_path)/.cargo

ln -sf "${cargo_home}" "${USER_HOME}/.cargo"
mkdir "${cargo_home}"
Expand Down
1 change: 1 addition & 0 deletions src/usr/local/containerbase/utils/constants.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export TEMP_DIR=/tmp
export CONTAINERBASE_DIR=/usr/local/containerbase

export CONTAINERBASE_VAR_DIR=/var/lib/containerbase
export CONTAINERBASE_TMP_DIR=/tmp/containerbase

# Used to find matching tool downloads
ARCHITECTURE=$(uname -p)
Expand Down
77 changes: 46 additions & 31 deletions src/usr/local/containerbase/utils/filesystem.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ function create_versioned_tool_path () {
# Will set up the general folder structure for the whole containerbase installation
function setup_directories () {
local install_dir
local home_path
local cache_path
install_dir=$(get_install_dir)
home_path=$(get_home_path)
cache_path=$(get_cache_path)

mkdir -p "${install_dir}"
# shellcheck disable=SC2174
mkdir -p -m 775 "${install_dir}"
# contains the installed tools
# shellcheck disable=SC2174
mkdir -p -m 775 "$(get_tools_path)"
Expand All @@ -67,46 +68,40 @@ function setup_directories () {
# contains the certificates for the tools
# shellcheck disable=SC2174
mkdir -p -m 775 "$(get_ssl_path)"
# contains the caches for the tools
# shellcheck disable=SC2174
mkdir -p -m 775 "$(get_cache_path)"
# contains the home for the tools
# shellcheck disable=SC2174
mkdir -p -m 775 "${home_path}"
# shellcheck disable=SC2174
mkdir -p -m 775 "${home_path}"/{.cache,.config,.local}

create_folder "$(get_tool_init_path)" 775

create_folder "$(get_tool_prep_path)" 755

create_folder "$(get_containerbase_tmp_path)" 775

# 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}"

# symlink known user folders
ln -sf "${home_path}/.config" "${USER_HOME}/.config"
ln -sf "${home_path}/.local" "${USER_HOME}/.local"
ln -sf "$(get_cache_path)" "${USER_HOME}/.cache"
ln -sf "${cache_path}/.config" "${USER_HOME}/.config"
ln -sf "${cache_path}/.local" "${USER_HOME}/.local"
ln -sf "${cache_path}/.cache" "${USER_HOME}/.cache"
}

# Creates the given folder path with root and user umask depending on the caller
# Will also create intermediate folders with correct umask
# The umask can be provided with the second argument
function create_folder () {
local folder=${1}
local parent

check folder

local umask=${2:-"$(get_umask)"}

local parent
parent=$(dirname "${folder}")

if [ -d "${folder}" ]; then
return
fi

parent=$(dirname "${folder}")
if [ ! -d "${parent}" ]; then
create_folder "$parent"
fi
Expand Down Expand Up @@ -149,16 +144,15 @@ function get_ssl_path () {

# Gets the path to the cache folder
function get_cache_path () {
local install_dir
install_dir=$(get_install_dir)
echo "${install_dir}/cache"
}

# Gets the path to the home folder
function get_home_path () {
local install_dir
install_dir=$(get_install_dir)
echo "${install_dir}/home"
local cache_path
cache_path="$(get_containerbase_tmp_path)/cache"
if [[ ! -d "${cache_path}" ]]; then
create_folder "$(get_containerbase_tmp_path)/cache" 775
create_folder "${cache_path}/.cache" 775
create_folder "${cache_path}/.config" 775
create_folder "${cache_path}/.local" 775
fi
echo "${cache_path}/cache"
}

# will get the correct umask based on the caller id
Expand All @@ -181,6 +175,12 @@ function get_containerbase_var_path () {
echo "${CONTAINERBASE_VAR_DIR}"
}

# Gets the path to the tmp folder to persist tool files
function get_containerbase_tmp_path () {
create_folder "${CONTAINERBASE_TMP_DIR}" 775
echo "${CONTAINERBASE_TMP_DIR}"
}

# Gets the path to the tool prep state folder
function get_tool_prep_path () {
echo "$(get_containerbase_var_path)/tool.prep.d"
Expand All @@ -192,14 +192,29 @@ function set_tool_prep () {
fi
}

function get_tool_prep () {
if [[ -f "$(get_tool_prep_path)/${TOOL_NAME}" ]]; then
echo "$(get_tool_prep_path)/${TOOL_NAME}"
fi
}

# Gets the path to the tool init state folder
function get_tool_init_path () {
echo "$(get_install_dir)/tool.init.d"
if [[ ! -d "$(get_containerbase_tmp_path)/tool.init.d" ]]; then
create_folder "$(get_containerbase_tmp_path)/tool.init.d" 775
fi
echo "$(get_containerbase_tmp_path)/tool.init.d"
}

function get_tool_prep () {
if [[ -f "$(get_tool_prep_path)/${TOOL_NAME}" ]]; then
echo "$(get_tool_prep_path)/${TOOL_NAME}"
function set_tool_init () {
if [[ ! -f "$(get_tool_init_path)/${TOOL_NAME}" ]]; then
touch "$(get_tool_init_path)/${TOOL_NAME}"
fi
}

function get_tool_init () {
if [[ -f "$(get_tool_init_path)/${TOOL_NAME}" ]]; then
echo "$(get_tool_init_path)/${TOOL_NAME}"
fi
}

Expand Down
10 changes: 2 additions & 8 deletions src/usr/local/containerbase/utils/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,17 @@ function init_tools () {
}

function init_tool_wrapper () {
local init_path
init_path=$(get_tool_init_path)

if [[ -f "${init_path}/${TOOL_NAME}" ]]; then
if [[ -f "$(get_tool_init)" ]]; then
# tool already initialized
return
fi

if [[ ! -d "${init_path}" ]]; then
create_folder "${init_path}" 775
fi

# ensure tool path exists
create_tool_path > /dev/null

# init tool
init_tool

touch "${init_path}/${TOOL_NAME}"
set_tool_init
}
5 changes: 5 additions & 0 deletions src/usr/local/containerbase/utils/prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ function prepare_tool_wrapper () {
# force root check
require_root

if [[ -f "$(get_tool_prep)" ]]; then
# tool already prepared
return
fi

# ensure tool path exists
create_tool_path > /dev/null

Expand Down
13 changes: 6 additions & 7 deletions test/java/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,22 @@ RUN set -ex; \
[ $(stat --format '%a' "${USER_HOME}/.m2") -eq 777 ]; \
true

RUN [ "$(find /tmp -type f | wc -l)" -eq 0 ]

RUN set -ex; \
ls -la /tmp; \
find /tmp -type f; \
exit 0
find /tmp -mindepth 1 -maxdepth 1; \
true

RUN [ "$(find /tmp -mindepth 1 -maxdepth 1 | wc -l)" -eq 1 ]

# renovate: datasource=java-version packageName=java-jre
RUN install-tool java 21.0.4+7.0.LTS

RUN set -ex; \
ls -la /tmp; \
find /tmp -type f; \
exit 0
true


RUN [ "$(find /tmp -type f | wc -l)" -eq 0 ]
RUN [ "$(find /tmp -mindepth 1 -maxdepth 1 | wc -l)" -eq 1 ]

#--------------------------------------
# test: Java 11 LTS + Gradle 6
Expand Down

0 comments on commit 12f05c8

Please sign in to comment.