@ -20,23 +20,28 @@ END
fi
fi
# container_name="linux-minetest-kit-build-libraries-devuan-chimaera"
# 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)
# ^ 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 [ $? -ne 0 ] ; then exit 1; fi
if [ ! -d " $docker_libraries_image_dir " ] ; then
if [ ! -d " $libraries_image_dir " ] ; then
echo " * $0 must run from the directory containing the container image directory: $docker_libraries_image_dir "
echo " Error: $0 must run from the directory containing the container image directory: $libraries_image_dir "
exit 1
exit 1
fi
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.
# 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
if [ $? -ne 0 ] ; then
exit 1
exit 1
fi
fi
if [ " @ $DL_SRC_PATH " = "@" ] ; then
if [ " @ $DL_SRC_PATH " = "@" ] ; then
# DL_SRC_PATH="$HOME/Downloads/$DL_SRC_NAME"
# 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
# ^ $DL_SRC_PATH has to be in the same directory as Dockerfile or
# the COPY command in the Dockerfile won't work.
# the COPY command in the Dockerfile won't work.
# The file should be added to .gitignore for the reason that it
# The file should be added to .gitignore for the reason that it
@ -44,54 +49,55 @@ if [ "@$DL_SRC_PATH" = "@" ]; then
fi
fi
# sudo docker image inspect $library _image > /dev/null
# sudo docker image inspect $libraries _image > /dev/null
sudo docker image inspect $library _image --format "* docker is looking for the image..."
sudo docker image inspect $libraries _image --format "* docker is looking for the image..."
# ^ appending ":latest" to the name also works.
# ^ appending ":latest" to the name also works.
# ^ Get matching images as a JSON list (where each has "Id" and other
# ^ Get matching images as a JSON list (where each has "Id" and other
# metadata).
# metadata).
if [ $? -ne 0 ] ; then
if [ $? -ne 0 ] ; then
if [ ! -d " $docker_ libraries_image_dir " ] ; then
if [ ! -d " $libraries_image_dir " ] ; then
echo " Error: \" $docker_ libraries_image_dir \" (docker_ libraries_image_dir for storing $SRC_URL ) doesn't exist in \"`pwd`\". "
echo " Error: \" $libraries_image_dir \" (libraries_image_dir for storing $SRC_URL ) doesn't exist in \"`pwd`\". "
exit 1
exit 1
fi
fi
echo " * building image $library _image ... "
echo " * building image $libraries _image ... "
if [ ! -f " $container _build_blob " ] ; then
if [ ! -f " $libraries_image _build_blob " ] ; then
echo " * downloading $SRC_URL to $DL_SRC_PATH ... "
echo " * downloading $SRC_URL to $DL_SRC_PATH ... "
curl " $SRC_URL " --progress-bar --output " $DL_SRC_PATH "
curl " $SRC_URL " --progress-bar --output " $DL_SRC_PATH "
if [ $? -ne 0 ] ; then
if [ $? -ne 0 ] ; then
exit 1
exit 1
fi
fi
if [ ! -f " $container _build_blob " ] ; then
if [ ! -f " $libraries_image _build_blob " ] ; then
echo " Error: This script requires \" $container _build_blob \". "
echo " Error: This script requires \" $libraries_image _build_blob \". "
exit 1
exit 1
fi
fi
else
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
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.
# ^ This copy of it is in .gitignore.
if [ $? -ne 0 ] ; then
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
exit 1
fi
fi
move_back = "false"
move_back = "false"
if [ ! -f $container _build_blob ] ; then
if [ ! -f $libraries_image _build_blob ] ; then
if [ -f " $prerelease_path " ] ; then
if [ -f " $prerelease_path " ] ; then
move_back = "true"
move_back = "true"
echo " mv $prerelease_path $container _build_blob "
echo " mv $prerelease_path $libraries_image _build_blob "
mv $prerelease_path $container _build_blob
mv $prerelease_path $libraries_image _build_blob
if [ $? -ne 0 ] ; then
if [ $? -ne 0 ] ; then
echo "* Error: the mv command failed."
echo "* Error: the mv command failed."
exit 1
exit 1
fi
fi
fi
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 = $?
code = $?
if [ "@move_back" = "@true" ] ; then
if [ "@move_back" = "@true" ] ; then
echo " mv \" $prerelease_path \" \" $container _build_blob \" "
echo " mv \" $prerelease_path \" \" $libraries_image _build_blob \" "
mv " $container _build_blob " " $prerelease_path "
mv " $libraries_image _build_blob " " $prerelease_path "
if [ $? -ne 0 ] ; then
if [ $? -ne 0 ] ; then
echo "* Warning: the mv command failed."
echo "* Warning: the mv command failed."
fi
fi
@ -100,17 +106,17 @@ if [ $? -ne 0 ]; then
exit 1
exit 1
fi
fi
else
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
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 " `
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
cat > /dev/null <<END
if [ " @ $container_Id " = "@" ] ; then
if [ " @ $container_Id " = "@" ] ; then
echo " * creating a container named $container_name "
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
# ^ output is the Id
if [ $? -ne 0 ] ; then
if [ $? -ne 0 ] ; then
echo "FAILED"
echo "FAILED"
@ -137,24 +143,29 @@ if [ "@$container_Id" != "@" ]; then
exit 0
exit 0
fi
fi
echo " There is no container_Id for container_name= $container_name , so checking for image: "
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
if [ $? -ne 0 ] ; then
echo "NOT FOUND, so:"
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)... "
echo " * building $server_image ( $server_image_dir inherits $libraries_image , so using built libraries from that should work)... "
sudo docker build -t $docker_finetest_server_image_name $docker_finetest_server_image_dir
if [ ! -d " $server_image_dir " ] ; then
# ^ always returns 1 for some reason
echo " Error: \" $server_image_dir \" doesn't exist in `pwd`. "
# if [ $? -ne 0 ]; then
exit 1
# exit 1
fi
# 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
else
echo " * using existing $docker_finetest_server_image_name "
echo " * using existing $server_image "
fi
fi
if [ " @ $container_Id " = "@" ] ; then
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
# ^ build was moved to the Dockerfile
echo " * creating container $container_name from image $docker_finetest_ server_image_nam e "
echo " * creating container $container_name from image $server_image "
sudo docker run --name $container_name $docker_finetest_ server_image_nam e /opt/linux-minetest-kit/minetest/minetestserver
sudo docker run --name $container_name $server_image /opt/linux-minetest-kit/minetest/minetestserver
code = $?
code = $?
if [ $code -ne 0 ] ; then
if [ $code -ne 0 ] ; then
cat <<END
cat <<END
@ -164,7 +175,7 @@ if [ "@$container_Id" = "@" ]; then
sudo docker rm --force $container_name
sudo docker rm --force $container_name
- Update the image as follows:
- Update the image as follows:
sudo docker rm --force $container_name
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
sudo docker image prune --force
# --force: Don't prompt for confirmation.
# --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/>.
# as expected. See <https://www.howtogeek.com/devops/how-to-run-gui-applications-in-a-docker-container/>.
# Therefore:
# Therefore:
# echo "* Creating image \"$server_finetest_ image\"..."
# echo "* Creating image \"$server_image\"..."
# sudo docker commit $container_Id $server_finetest_ image
# sudo docker commit $container_Id $server_image
# if [ $? -ne 0 ]; then
# if [ $? -ne 0 ]; then
# echo "FAILED (sudo docker commit $container_Id $server_finetest_ image)"
# echo "FAILED (sudo docker commit $container_Id $server_image)"
# fi
# fi
# echo "* Running $server_bin_path in container \"$server_container\""
# 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
# 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
# fi
# ^ Build the server as a separate step instead (see further up)
# ^ Build the server as a separate step instead (see further up)
@ -224,7 +235,7 @@ How to use the image:
sudo docker image ls
sudo docker image ls
# ^ See what images are installed (one image can be used for many containers).
# ^ 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).
# ^ 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
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/>)
# ^ 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.
# 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)
# ^ Run an interactive terminal (Type 'exit' to exit)
# (based on <https://phoenixnap.com/kb/docker-run-command-with-examples>)
# (based on <https://phoenixnap.com/kb/docker-run-command-with-examples>)
sudo docker commit $container_Id $server_finetest_ image
sudo docker commit $container_Id $server_image
sudo docker container run --name tmp_test_im -it $server_finetest_ image /bin/bash
sudo docker container run --name tmp_test_im -it $server_image /bin/bash
# ^ Transform the container into an image and inspect the internals manually
# ^ 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/>).
# (based on <https://www.thorsten-hans.com/how-to-run-commands-in-stopped-docker-containers/>).
# Then: sudo docker rm --force tmp_test_im
# Then: sudo docker rm --force tmp_test_im