Skip to content
Open
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
25 changes: 16 additions & 9 deletions bin/setup
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ CONTAINER_TAG=`cat ${ROOT}/bin/.container-tag`
# Parse command line arguments
PRESERVE_CONFIG=0

CONTAINER_SETUP_CMD=()
run() {
if [ "${CONTAINER_TYPE}" == "docker" -o "${CONTAINER_TYPE}" == "podman" ]; then
CONTAINER_SETUP_CMD+=( "$*" )
else
${RUN} "$@"
fi
}

# Only parse arguments if this script is being run directly (not sourced)
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
for arg in "$@"; do
Expand Down Expand Up @@ -159,10 +168,8 @@ if [ -f $ROOT/.git ]; then
HOME_OPT="${HOME_OPT} --bind ${GIT_PATH}:${GIT_PATH}"
fi

if [ "${CONTAINER_TYPE}" == "devcontainer" ]; then
if [ "${CONTAINER_TYPE}" == "devcontainer" -o "${CONTAINER_TYPE}" == "docker" -o "${CONTAINER_TYPE}" == "podman" ]; then
RUN=""
elif [ "${CONTAINER_TYPE}" == "docker" -o "${CONTAINER_TYPE}" == "podman" ]; then
RUN="${CONTAINER_BASE}"
elif [ "${CONTAINER_TYPE}" == "singularity" ]; then
RUN="singularity run ${HOME_OPT} ${CONTAINER_PATH}"
else
Expand All @@ -180,16 +187,16 @@ if [ $PRESERVE_CONFIG -eq 0 ] || [ ! -f $ROOT/.bundle/config ]; then
fi
OLDDIR=$PWD
cd $ROOT
${RUN} bundle config set --local path ${ROOT}/.home/.gems
${RUN} bundle config set --local cache_path ${ROOT}/.home/.cache
${RUN} bundle config set --local with development
run bundle config set --local path ${ROOT}/.home/.gems
run bundle config set --local cache_path ${ROOT}/.home/.cache
run bundle config set --local with development
cd $OLDDIR
fi

if [ ! -d $ROOT/.home/.gems ]; then
OLDDIR=$PWD
cd $ROOT
${RUN} bundle install
run bundle install
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this (and other) setup commands already run just once since they are conditioned on the existence of file ($ROOT/.home/.gems) in this case. Are you seeing them run multiple times anyway?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change doesn't refuse existence checks. If we shouldn't do something based on checks then this command won't be accumulated to CONTAINER_SETUP_CMD and won't be executed. It does full build inside only one container instead of multiple needless creation and removing of containers.

cd $OLDDIR
fi

Expand All @@ -203,8 +210,8 @@ fi

if [[ ! -z "$DEVELOPMENT" && $DEVELOPMENT -eq 1 ]]; then
if [ ! -d "${ROOT}/.home/.yard/gem_index" ]; then
${RUN} bundle exec --gemfile ${ROOT}/Gemfile yard config --gem-install-yri
${RUN} bundle exec --gemfile ${ROOT}/Gemfile yard gems
run bundle exec --gemfile ${ROOT}/Gemfile yard config --gem-install-yri
run bundle exec --gemfile ${ROOT}/Gemfile yard gems
touch ${ROOT}/.stamps/dev_gems
fi
fi
Expand Down
7 changes: 6 additions & 1 deletion do
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@ fi
source $ROOT/bin/setup

# really long way of invoking rake, but renamed to 'do'
$BUNDLE exec --gemfile $ROOT/Gemfile ruby -r rake -e "Rake.application.init('do');Rake.application.load_rakefile;Rake.application.top_level" -- "$@"
EXEC=( exec --gemfile "$ROOT/Gemfile" ruby -r rake -e '"Rake.application.init('"'do'"');Rake.application.load_rakefile;Rake.application.top_level"' -- "$@" )
if [ "${CONTAINER_TYPE}" == "docker" -o "${CONTAINER_TYPE}" == "podman" ]; then
${BASH} -c "$(printf "%s && " "${CONTAINER_SETUP_CMD[@]:-true}") bundle ${EXEC[*]}"
else
$BUNDLE "${EXEC[@]}"
fi
Loading