Skip to content

Commit 77c8385

Browse files
committed
fix: run docker/podman container once
Instead of running multiple containers, it is enough to use just one. Signed-off-by: Evgeny Semenov <[email protected]>
1 parent 246914d commit 77c8385

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

bin/setup

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ CONTAINER_TAG=`cat ${ROOT}/bin/.container-tag`
99
# Parse command line arguments
1010
PRESERVE_CONFIG=0
1111

12+
CONTAINER_SETUP_CMD=()
13+
run() {
14+
if [ "${CONTAINER_TYPE}" == "docker" -o "${CONTAINER_TYPE}" == "podman" ]; then
15+
CONTAINER_SETUP_CMD+=( "$*" )
16+
else
17+
${RUN} "$@"
18+
fi
19+
}
20+
1221
# Only parse arguments if this script is being run directly (not sourced)
1322
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
1423
for arg in "$@"; do
@@ -159,10 +168,8 @@ if [ -f $ROOT/.git ]; then
159168
HOME_OPT="${HOME_OPT} --bind ${GIT_PATH}:${GIT_PATH}"
160169
fi
161170

162-
if [ "${CONTAINER_TYPE}" == "devcontainer" ]; then
171+
if [ "${CONTAINER_TYPE}" == "devcontainer" -o "${CONTAINER_TYPE}" == "docker" -o "${CONTAINER_TYPE}" == "podman" ]; then
163172
RUN=""
164-
elif [ "${CONTAINER_TYPE}" == "docker" -o "${CONTAINER_TYPE}" == "podman" ]; then
165-
RUN="${CONTAINER_BASE}"
166173
elif [ "${CONTAINER_TYPE}" == "singularity" ]; then
167174
RUN="singularity run ${HOME_OPT} ${CONTAINER_PATH}"
168175
else
@@ -180,16 +187,16 @@ if [ $PRESERVE_CONFIG -eq 0 ] || [ ! -f $ROOT/.bundle/config ]; then
180187
fi
181188
OLDDIR=$PWD
182189
cd $ROOT
183-
${RUN} bundle config set --local path ${ROOT}/.home/.gems
184-
${RUN} bundle config set --local cache_path ${ROOT}/.home/.cache
185-
${RUN} bundle config set --local with development
190+
run bundle config set --local path ${ROOT}/.home/.gems
191+
run bundle config set --local cache_path ${ROOT}/.home/.cache
192+
run bundle config set --local with development
186193
cd $OLDDIR
187194
fi
188195

189196
if [ ! -d $ROOT/.home/.gems ]; then
190197
OLDDIR=$PWD
191198
cd $ROOT
192-
${RUN} bundle install
199+
run bundle install
193200
cd $OLDDIR
194201
fi
195202

@@ -198,13 +205,13 @@ if [ ! -f $ROOT/ext/rbi-central/README.md ]; then
198205
fi
199206

200207
if [ ! -d $ROOT/.home/.venv ]; then
201-
${RUN} /usr/bin/python3 -m venv ${ROOT}/.home/.venv
208+
run /usr/bin/python3 -m venv ${ROOT}/.home/.venv
202209
fi
203210

204-
source ${ROOT}/.home/.venv/bin/activate
211+
run source ${ROOT}/.home/.venv/bin/activate
205212

206213
if [ ! -f ${ROOT}/.home/.venv/bin/pre-commit ]; then
207-
${RUN} ${ROOT}/.home/.venv/bin/pip install -r requirements.txt
214+
run ${ROOT}/.home/.venv/bin/pip install -r requirements.txt
208215
fi
209216

210217
# if [ ! -f $ROOT/ext/riscv-opcodes/README.md ]; then
@@ -213,14 +220,14 @@ fi
213220

214221
if [[ ! -z "$DEVELOPMENT" && $DEVELOPMENT -eq 1 ]]; then
215222
if [ ! -d "${ROOT}/.home/.yard/gem_index" ]; then
216-
${RUN} bundle exec --gemfile ${ROOT}/Gemfile yard config --gem-install-yri
217-
${RUN} bundle exec --gemfile ${ROOT}/Gemfile yard gems
223+
run bundle exec --gemfile ${ROOT}/Gemfile yard config --gem-install-yri
224+
run bundle exec --gemfile ${ROOT}/Gemfile yard gems
218225
touch ${ROOT}/.stamps/dev_gems
219226
fi
220227
fi
221228

222229
if [ ! -d ${ROOT}/node_modules ]; then
223-
${RUN} npm i
230+
run npm i
224231
fi
225232

226233
if [ "${CONTAINER_TYPE}" == "devcontainer" ]; then

do

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,9 @@ fi
1818
source $ROOT/bin/setup
1919

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

0 commit comments

Comments
 (0)