@ -20,23 +20,28 @@ END
fi
# container_name="linux-minetest-kit-build-libraries-devuan-chimaera"
# ^ This is no longer necessary since the IMAGE does the building (build was moved to Dockerfile)
source lmk.devuan-chimaera.rc
this_rc = "lmk.devuan-chimaera.rc"
if [ ! -f " $this_rc " ] ; then
echo " Error: $0 must run in the directory containing $this_rc . "
exit 1
fi
source $this_rc
if [ $? -ne 0 ] ; then exit 1; fi
if [ ! -d " $docker_libraries_image_dir " ] ; then
echo " * $0 must run from the directory containing the container image directory: $docker_libraries_image_dir "
if [ ! -d " $libraries_image_dir " ] ; then
echo " Error: $0 must run from the directory containing the container image directory: $libraries_image_dir "
exit 1
fi
# ^ docker_ libraries_image_dir has to be in the same directory as Dockerfile or
# ^ libraries_image_dir has to be in the same directory as Dockerfile or
# the COPY command in the Dockerfile won't work.
source $docker_ libraries_image_dir /lmk.rc
source $libraries_image_dir /lmk.rc
if [ $? -ne 0 ] ; then
exit 1
fi
if [ " @ $DL_SRC_PATH " = "@" ] ; then
# DL_SRC_PATH="$HOME/Downloads/$DL_SRC_NAME"
DL_SRC_PATH = " $docker_ libraries_image_dir "
DL_SRC_PATH = " $libraries_image_dir "
# ^ $DL_SRC_PATH has to be in the same directory as Dockerfile or
# the COPY command in the Dockerfile won't work.
# The file should be added to .gitignore for the reason that it
@ -44,54 +49,55 @@ if [ "@$DL_SRC_PATH" = "@" ]; then
fi
# sudo docker image inspect $library _image > /dev/null
sudo docker image inspect $library _image --format "* docker is looking for the image..."
# sudo docker image inspect $libraries _image > /dev/null
sudo docker image inspect $libraries _image --format "* docker is looking for the image..."
# ^ appending ":latest" to the name also works.
# ^ Get matching images as a JSON list (where each has "Id" and other
# metadata).
if [ $? -ne 0 ] ; then
if [ ! -d " $docker_ libraries_image_dir " ] ; then
echo " Error: \" $docker_ libraries_image_dir \" (docker_ libraries_image_dir for storing $SRC_URL ) doesn't exist in \"`pwd`\". "
if [ ! -d " $libraries_image_dir " ] ; then
echo " Error: \" $libraries_image_dir \" (libraries_image_dir for storing $SRC_URL ) doesn't exist in \"`pwd`\". "
exit 1
fi
echo " * building image $library _image ... "
if [ ! -f " $container _build_blob " ] ; then
echo " * building image $libraries _image ... "
if [ ! -f " $libraries_image _build_blob " ] ; then
echo " * downloading $SRC_URL to $DL_SRC_PATH ... "
curl " $SRC_URL " --progress-bar --output " $DL_SRC_PATH "
if [ $? -ne 0 ] ; then
exit 1
fi
if [ ! -f " $container _build_blob " ] ; then
echo " Error: This script requires \" $container _build_blob \". "
if [ ! -f " $libraries_image _build_blob " ] ; then
echo " Error: This script requires \" $libraries_image _build_blob \". "
exit 1
fi
else
echo " * using existing \" $container _build_blob \" to build the container image "
echo " * using existing \" $libraries_image _build_blob \" to build the container image "
fi
cp ../install-minetest-build-deps.sh $docker_ libraries_image_dir /
cp ../install-minetest-build-deps.sh $libraries_image_dir /
# ^ This copy of it is in .gitignore.
if [ $? -ne 0 ] ; then
echo " Error: 'cp ../install-minetest-build-deps.sh $docker_ libraries_image_dir /' failed. "
echo " Error: 'cp ../install-minetest-build-deps.sh $libraries_image_dir /' failed. "
exit 1
fi
move_back = "false"
if [ ! -f $container _build_blob ] ; then
if [ ! -f $libraries_image _build_blob ] ; then
if [ -f " $prerelease_path " ] ; then
move_back = "true"
echo " mv $prerelease_path $container _build_blob "
mv $prerelease_path $container _build_blob
echo " mv $prerelease_path $libraries_image _build_blob "
mv $prerelease_path $libraries_image _build_blob
if [ $? -ne 0 ] ; then
echo "* Error: the mv command failed."
exit 1
fi
fi
fi
sudo docker build -t $library_image $docker_libraries_image_dir
sudo docker build -t $libraries_image $libraries_image_dir
# -t: Name and optionally a tag in the 'name:tag' format
code = $?
if [ "@move_back" = "@true" ] ; then
echo " mv \" $prerelease_path \" \" $container _build_blob \" "
mv " $container _build_blob " " $prerelease_path "
echo " mv \" $prerelease_path \" \" $libraries_image _build_blob \" "
mv " $libraries_image _build_blob " " $prerelease_path "
if [ $? -ne 0 ] ; then
echo "* Warning: the mv command failed."
fi
@ -100,17 +106,17 @@ if [ $? -ne 0 ]; then
exit 1
fi
else
echo " * The container will be built using the existing docker image $library _image "
echo " * The container will be built using the existing docker image $libraries _image "
fi
# sudo docker container run -d --name $library _image unzip xvf $contained_arc -C $contained_repos
# sudo docker container run -d --name $libraries _image unzip xvf $contained_arc -C $contained_repos
container_Id = ` sudo docker ps -aqf " name= $container_name " `
# ^ ONLY works with container_name not library _image
# ^ ONLY works with container_name not libraries _image
cat > /dev/null <<END
if [ " @ $container_Id " = "@" ] ; then
echo " * creating a container named $container_name "
sudo docker create --name= $container_name $library _image
sudo docker create --name= $container_name $libraries _image
# ^ output is the Id
if [ $? -ne 0 ] ; then
echo "FAILED"
@ -137,24 +143,29 @@ if [ "@$container_Id" != "@" ]; then
exit 0
fi
echo " There is no container_Id for container_name= $container_name , so checking for image: "
sudo docker image inspect $docker_finetest_ server_image_nam e --format "* docker is looking for the image..."
sudo docker image inspect $server_image --format "* docker is looking for the image..."
if [ $? -ne 0 ] ; then
echo "NOT FOUND, so:"
echo " * building $docker_finetest_server_image_name ( $docker_finetest_server_image_dir inherits $library_image , so using built libraries from that should work)... "
sudo docker build -t $docker_finetest_server_image_name $docker_finetest_server_image_dir
# ^ always returns 1 for some reason
# if [ $? -ne 0 ]; then
# exit 1
# fi
echo " * building $server_image ( $server_image_dir inherits $libraries_image , so using built libraries from that should work)... "
if [ ! -d " $server_image_dir " ] ; then
echo " Error: \" $server_image_dir \" doesn't exist in `pwd`. "
exit 1
fi
sudo docker build -t $server_image $server_image_dir
# ^ ./mtcompile-program.pl --build --finetest --server returns 1 for some reason, so there is a custom build script used in the Dockerfile
# -t: Name and optionally a tag in the 'name:tag' format
if [ $? -ne 0 ] ; then
exit 1
fi
else
echo " * using existing $docker_finetest_server_image_name "
echo " * using existing $server_image "
fi
if [ " @ $container_Id " = "@" ] ; then
# sudo docker run --name $container_name $library _image $run_all_build_commands_script
# sudo docker run --name $container_name $libraries _image $run_all_build_commands_script
# ^ build was moved to the Dockerfile
echo " * creating container $container_name from image $docker_finetest_ server_image_nam e "
sudo docker run --name $container_name $docker_finetest_ server_image_nam e /opt/linux-minetest-kit/minetest/minetestserver
echo " * creating container $container_name from image $server_image "
sudo docker run --name $container_name $server_image /opt/linux-minetest-kit/minetest/minetestserver
code = $?
if [ $code -ne 0 ] ; then
cat <<END
@ -164,7 +175,7 @@ if [ "@$container_Id" = "@" ]; then
sudo docker rm --force $container_name
- Update the image as follows:
sudo docker rm --force $container_name
sudo docker rmi $docker_finetest_ server_image_nam e
sudo docker rmi $server_image
sudo docker image prune --force
# --force: Don't prompt for confirmation.
@ -202,15 +213,15 @@ echo
# as expected. See <https://www.howtogeek.com/devops/how-to-run-gui-applications-in-a-docker-container/>.
# Therefore:
# echo "* Creating image \"$server_finetest_ image\"..."
# sudo docker commit $container_Id $server_finetest_ image
# echo "* Creating image \"$server_image\"..."
# sudo docker commit $container_Id $server_image
# if [ $? -ne 0 ]; then
# echo "FAILED (sudo docker commit $container_Id $server_finetest_ image)"
# echo "FAILED (sudo docker commit $container_Id $server_image)"
# fi
# echo "* Running $server_bin_path in container \"$server_container\""
# sudo docker container run --name $server_container $server_finetest_ image $server_bin_path
# sudo docker container run --name $server_container $server_image $server_bin_path
# if [ $? -ne 0 ]; then
# echo "FAILED (sudo docker container run --name $server_container $server_finetest_ image $server_bin_path)"
# echo "FAILED (sudo docker container run --name $server_container $server_image $server_bin_path)"
# fi
# ^ Build the server as a separate step instead (see further up)
@ -224,7 +235,7 @@ How to use the image:
sudo docker image ls
# ^ See what images are installed (one image can be used for many containers).
sudo docker rmi $library _image
sudo docker rmi $libraries _image
# ^ Remove a docker image (This is necessary after updating the unversioned Docker image to avoid cached RUN commands from doing nothing when the script after RUN changes).
sudo docker image prune --force
@ -254,12 +265,12 @@ How to use the image:
# ^ Stop a container by name (See <https://www.tecmint.com/name-docker-containers/>)
# You must use the container name (as determined using the "ps" subcommand), not the image name.
sudo docker container run -it $library _image /bin/bash
sudo docker container run -it $libraries _image /bin/bash
# ^ Run an interactive terminal (Type 'exit' to exit)
# (based on <https://phoenixnap.com/kb/docker-run-command-with-examples>)
sudo docker commit $container_Id $server_finetest_ image
sudo docker container run --name tmp_test_im -it $server_finetest_ image /bin/bash
sudo docker commit $container_Id $server_image
sudo docker container run --name tmp_test_im -it $server_image /bin/bash
# ^ Transform the container into an image and inspect the internals manually
# (based on <https://www.thorsten-hans.com/how-to-run-commands-in-stopped-docker-containers/>).
# Then: sudo docker rm --force tmp_test_im