56 lines
1.6 KiB
Bash
56 lines
1.6 KiB
Bash
DEVENV_IMAGE='localhost/toolbox-dev-env:latest'
|
|
|
|
function dev() {
|
|
if [ ${#} -lt 1 ]; then
|
|
echo "WARNING: Missing project name";
|
|
project=""
|
|
else
|
|
project="${1}"
|
|
fi
|
|
|
|
if [ -f '/run/.toolboxenv' ]; then
|
|
cd "${PROJECTS_PATH}/${project}";
|
|
|
|
if [ -f "${PWD}/ansible.cfg" ]; then
|
|
export ANSIBLE_CONFIG="${PWD}/ansible.cfg";
|
|
export ANSIBLE_COLLECTIONS_PATH="${PWD}/.ansible"
|
|
fi
|
|
|
|
if [ -f "${PWD}/pyproject.toml" ]; then
|
|
poetry_venv=$(poetry env info --path)
|
|
|
|
if [ ! -z "${poetry_venv}" ] && [ -f "${poetry_venv}/bin/activate" ]; then
|
|
source "${poetry_venv}/bin/activate";
|
|
fi
|
|
fi
|
|
else
|
|
if [ ! -d "${PROJECTS_PATH}/${project}" ]; then
|
|
echo "ERROR: Project path ${PROJECTS_PATH}/${project} does not exist";
|
|
return 1
|
|
fi
|
|
|
|
local slug=$(random 8)
|
|
local container_name="toolbox-${project:-generic}-${slug}"
|
|
|
|
toolbox create --image="${DEVENV_IMAGE}" "${container_name}" &>/dev/null || return 1
|
|
|
|
local current=$(pwd)
|
|
cd "${PROJECTS_PATH}/${project}"
|
|
echo ">>> Loading project: ${project}"
|
|
echo ">>> ${PWD}"
|
|
toolbox enter "${container_name}"
|
|
echo ">>> Exited: ${container_name}"
|
|
cd "${current}"
|
|
|
|
podman container stop "${container_name}" &>/dev/null
|
|
podman container rm --force "${container_name}" &>/dev/null
|
|
fi
|
|
}
|
|
|
|
if [ -f '/run/.toolboxenv' ]; then
|
|
if [[ "${PWD}" == $PROJECTS_PATH/* ]]; then
|
|
dev $(basename "${PWD}")
|
|
fi
|
|
fi
|
|
|