Skip to content

Commit e7975d0

Browse files
committed
devtool: fix and simplify build_devctr
The previous way of building the container did not work in cases where we restricted a previous dependency in the pyproject.toml to a specific version. There is no need to run `poetry update`. It's sufficient to not provide a lockfile. Also adds some simplifications. Signed-off-by: alindima <[email protected]>
1 parent 64c9745 commit e7975d0

File tree

3 files changed

+18
-28
lines changed

3 files changed

+18
-28
lines changed

tools/devctr/Dockerfile.aarch64

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ FROM ubuntu:18.04
77
ARG RUST_TOOLCHAIN="1.52.1"
88
ARG TINI_VERSION_TAG="v0.18.0"
99
ARG TMP_BUILD_DIR=/tmp/build
10-
ARG TMP_POETRY_DIR=/tmp/poetry
10+
ARG TMP_POETRY_DIR
1111
ARG FIRECRACKER_SRC_DIR="/firecracker"
1212
ARG FIRECRACKER_BUILD_DIR="$FIRECRACKER_SRC_DIR/build"
1313
ARG CARGO_REGISTRY_DIR="$FIRECRACKER_BUILD_DIR/cargo_registry"

tools/devctr/Dockerfile.x86_64

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ FROM ubuntu:18.04
77
ARG RUST_TOOLCHAIN="1.52.1"
88
ARG TINI_VERSION_TAG="v0.18.0"
99
ARG TMP_BUILD_DIR=/tmp/build
10-
ARG TMP_POETRY_DIR=/tmp/poetry
10+
ARG TMP_POETRY_DIR
1111
ARG FIRECRACKER_SRC_DIR="/firecracker"
1212
ARG FIRECRACKER_BUILD_DIR="$FIRECRACKER_SRC_DIR/build"
1313
ARG CARGO_REGISTRY_DIR="$FIRECRACKER_BUILD_DIR/cargo_registry"

tools/devtool

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ CTR_CARGO_SECCOMPILER_TARGET_DIR="$CTR_FC_BUILD_DIR/seccompiler"
129129
# Full path to the microVM images cache dir
130130
CTR_MICROVM_IMAGES_DIR="$CTR_FC_BUILD_DIR/img"
131131

132+
# Full path to the poetry tmp directory on the container, used for holding
133+
# the lock and toml files.
134+
CTR_POETRY_TMP_DIR="/tmp/poetry"
135+
132136
# Full path to the public key mapping on the guest
133137
PUB_KEY_PATH=/root/.ssh/id_rsa.pub
134138

@@ -337,16 +341,14 @@ cmd_fix_perms() {
337341
cmd_build_devctr() {
338342
arch=$(uname -m)
339343
docker_file_name="Dockerfile.$arch"
340-
should_update_python_packages=true
341-
build_args=""
344+
build_args="--build-arg TMP_POETRY_DIR=$CTR_POETRY_TMP_DIR"
342345

343346
while [ $# -gt 0 ]; do
344347
case "$1" in
345348
"-h"|"--help") { cmd_help; exit 1; } ;;
346-
"-n"|"--no-python-package-update")
349+
"-n"|"--no-python-package-upgrade")
347350
shift
348-
should_update_python_packages=false
349-
build_args="--build-arg POETRY_LOCK_PATH=tools/devctr/poetry.lock"
351+
build_args="$build_args --build-arg POETRY_LOCK_PATH=tools/devctr/poetry.lock"
350352
;;
351353
"--") { shift; break; } ;;
352354
*)
@@ -358,9 +360,9 @@ cmd_build_devctr() {
358360

359361
docker build -t "$DEVCTR_IMAGE_NO_TAG" -f "$FC_DEVCTR_DIR/$docker_file_name" $build_args .
360362

361-
if [ "$should_update_python_packages" = true ]; then
362-
update_python_package_version
363-
fi
363+
# Copy back the lockfile, since a new dependency or version would have
364+
# updated it.
365+
copy_poetry_lockfile
364366
}
365367

366368
# Prompt the user for confirmation before proceeding.
@@ -611,32 +613,20 @@ test_key() {
611613
[ $ret -ne 0 ] && die "$1 is not a valid key file."
612614
}
613615

614-
# Tries to update any outdated python packages on the container,
615-
# locks the new versions and copies back the ```poetry.lock```
616-
# file to the host.
616+
# Copies the ```poetry.lock``` file to the host, upgrading the versions if
617+
# requested.
617618
#
618-
update_python_package_version() {
619-
say "Updating python packages..."
620-
619+
copy_poetry_lockfile() {
621620
# defined in Dockerfile
622-
poetry_dir_on_container="/tmp/poetry"
623621
lock_file_location_on_host="$FC_DEVCTR_DIR/poetry.lock"
624622
image_id=$(docker images -q "$DEVCTR_IMAGE_NO_TAG" | head -n 1)
625623
dummy_container_name=$(uuidgen)
626-
dummy_container_id=$(docker create -ti --name \
627-
"$dummy_container_name" \
628-
"$image_id" \
629-
bash)
630-
631-
docker start "$dummy_container_id"
632-
cmd="cd "$poetry_dir_on_container"; poetry update"
633-
docker exec -ti "$dummy_container_id" /bin/bash -c "${cmd}"
624+
dummy_container_id=$(docker create --name "$dummy_container_name" "$image_id" bash)
625+
634626
docker cp \
635-
"$dummy_container_id":/tmp/poetry/poetry.lock \
627+
"$dummy_container_id":"$CTR_POETRY_TMP_DIR"/poetry.lock \
636628
"$lock_file_location_on_host"
637-
docker commit "$dummy_container_id" "$DEVCTR_IMAGE_NO_TAG"
638629

639-
docker stop "$dummy_container_id"
640630
docker rm -f "$dummy_container_name"
641631
}
642632

0 commit comments

Comments
 (0)