Browse Source

Move library build to the Dockerfile. Build the server not the client (Client was tested, so start making it into a usable production script).

master
poikilos 2 years ago
parent
commit
a893c85504
  1. 80
      containers/lmk.devuan-chimaera.sh
  2. 3
      containers/lmk.devuan-chimaera/Dockerfile
  3. 73
      containers/lmk.devuan-chimaera/build-lmk.sh
  4. 10
      containers/lmk.devuan-chimaera/lmk.rc

80
containers/lmk.devuan-chimaera.sh

@ -1,7 +1,17 @@
#!/bin/bash #!/bin/bash
# See https://nextbreakpoint.com/posts/article-compile-code-with-docker.html # See https://nextbreakpoint.com/posts/article-compile-code-with-docker.html
# sudo docker build -t lmk-devuan-chimaera-img dyne/devuan:chimaera # sudo docker build -t lmk-devuan-chimaera-img dyne/devuan:chimaera
echo "* This container is only for the server, not the client."
sleep 10
docker_path="`sudo bash -c 'command -v docker'`" docker_path="`sudo bash -c 'command -v docker'`"
ENABLE_RUN_CLIENT=false
for var in "$@"
do
if [ "@$var" = "@--run-client" ]; then
ENABLE_RUN_CLIENT=true
fi
done
if [ ! -f "$docker_path" ]; then if [ ! -f "$docker_path" ]; then
cat <<END cat <<END
This script requires docker. For help, see This script requires docker. For help, see
@ -12,6 +22,10 @@ END
fi fi
container_name="lmk-devuan-chimaera" container_name="lmk-devuan-chimaera"
image_name="lmk-devuan-chimaera-img" image_name="lmk-devuan-chimaera-img"
# client_classic_image=linux-minetest-kit/client-classic
server_finetest_image=linux-minetest-kit/server-finetest
# client_classic_container="minetest-client-classic"
server_container="minetestserver-finetest"
docker_image_dir="lmk.devuan-chimaera" docker_image_dir="lmk.devuan-chimaera"
if [ ! -d "$docker_image_dir" ]; then if [ ! -d "$docker_image_dir" ]; then
echo "* $me must run from the directory containing the container image directory: $docker_image_dir" echo "* $me must run from the directory containing the container image directory: $docker_image_dir"
@ -115,7 +129,10 @@ How to use the image:
# ^ List containers and show NAMES (The name is necessary for certain subcommands such as exec which operate on a running container). # ^ List containers and show NAMES (The name is necessary for certain subcommands such as exec which operate on a running container).
sudo docker start $container_name sudo docker start $container_name
# ^ Start a container. # ^ Start a container. This will merely run $run_all_build_commands_script again since that is the container's main process.
sudo docker attach $container_name
# ^ attach the current terminal to a running container.
sudo docker run $container_name sudo docker run $container_name
# ^ "run" is merely a combination of "create" and "start" # ^ "run" is merely a combination of "create" and "start"
@ -124,7 +141,7 @@ How to use the image:
sudo docker -w $contained_repo exec $container_name $run_all_build_commands_script sudo docker -w $contained_repo exec $container_name $run_all_build_commands_script
# ^ Execute a command in a running container (exec shows an error if the container isn't running). # ^ Execute a command in a running container (exec shows an error if the container isn't running).
# This will not work if the run/start command that started the container isn't a command that keeps it open (runs indefinitely)! # This will not work if the run/start command that started the container isn't a command that keeps it open (runs indefinitely)!
# If you need a container that has changes after $run_all_build_commands_script runs, you must use the "commit" subcommand. # If you need a container that has changes after $run_all_build_commands_script runs or runs a different command, you must use the "commit" subcommand to create a new image.
# w: working directory # w: working directory
sudo docker stop $container_name sudo docker stop $container_name
@ -135,11 +152,16 @@ How to use the image:
# ^ 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 container run --name tmp_test_im -it $server_finetest_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
sudo docker attach $container_name sudo docker attach $container_name
# ^ Attach your current terminal to a running container (See # ^ Attach your current terminal to a running container (See
# <https://docs.docker.com/engine/reference/commandline/attach/>). # <https://docs.docker.com/engine/reference/commandline/attach/>).
sudo docker rm --force $container_name sudo docker rm --force $container_name
# ^ Delete a container by its name. # ^ Delete a container by its name.
# --force: kill and delete running containers as well. # --force: kill and delete running containers as well.
@ -165,21 +187,24 @@ if [ "@$container_Id" = "@" ]; then
exit 1 exit 1
fi fi
fi fi
echo "container_Id=$container_Id"
END
echo "building within the container..." END
echo "container_Id=$container_Id"
# echo "building within the container..."
# sudo docker start $container_name # sudo docker start $container_name
# ^ NOTE: start is useless here since it won't stay open unless the # ^ NOTE: start is useless here since it won't stay open unless the
# command is set to "bash" or something, which isn't desirable. # command is set to "bash" or something, which isn't desirable.
# Therefore, use run instead of exec below. # Therefore, use run instead of exec below.
# ^ output is $container_name # ^ output is $container_name
if [ "@$container_Id" = "@" ]; then
sudo docker run --name $container_name $image_name $run_all_build_commands_script sudo docker run --name $container_name $image_name $run_all_build_commands_script
if [ $? -ne 0 ]; then code=$?
if [ $code -ne 0 ]; then
cat <<END cat <<END
* building within the container FAILED * building within the container FAILED
- Remove the container as follows:
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 $image_name sudo docker rmi $image_name
@ -190,18 +215,45 @@ if [ $? -ne 0 ]; then
$0 $0
END END
exit 1 # exit $code
else else
echo "* building within the container completed OK" echo "* building within the container completed OK"
fi fi
# ^ NOTE: start is useless here since it won't stay open unless the else
# command is set to "bash" or something, which isn't desirable. echo "* The build container already appears to be set up."
# Therefore, use run instead of exec below. fi
echo
# echo "If the build output appeared successful, ignore the error above and create the minetest client image as follows:"
# echo "$0 --client"
# - Run again as follows: # NOTE: The "start" subcommand is useless here since it won't stay open
# unless the command is set to "bash" or something, which wouldn't be
# an automated image. The proper way to modify a container is to make
# a new image from it
# and
# sudo docker start $container_name # sudo docker start $container_name
# ^ doesn't work (The script specified by "run" earlier doesn't run). # doesn't work (The script specified by "run" earlier doesn't run) so:
# echo "* Creating client image..."
# docker commit $container_Id $client_classic_image
# sudo docker container run --name $client_classic_container $client_classic_image $client_bin_path
# ^ This doesn't work for the client due to:
# "2022-05-13 03:59:00: ERROR[Main]: Subgame specified in default_game [Bucket_Game] is invalid.
# 2022-05-13 03:59:00: ERROR[Main]: Irrlicht: Error: Need running XServer to start Irrlicht Engine.
# 2022-05-13 03:59:00: ERROR[Main]: Irrlicht: Could not open display, set DISPLAY variable"
# as expected. See <https://www.howtogeek.com/devops/how-to-run-gui-applications-in-a-docker-container/>.
# Therefore:
echo "* Creating server image..."
sudo docker commit $container_Id $server_finetest_image
if [ $? -ne 0 ]; then
echo "FAILED (sudo docker commit $container_Id $server_finetest_image)"
fi
echo "* Running $server_bin_path in container \"$server_container\""
sudo docker container run --name $server_container $server_finetest_image $server_bin_path
if [ $? -ne 0 ]; then
echo "FAILED (sudo docker container run --name $server_container $server_finetest_image $server_bin_path)"
fi
# How to use docker-compose (See <https://docs.docker.com/compose/>): # How to use docker-compose (See <https://docs.docker.com/compose/>):
# "1. Define your app’s environment with a Dockerfile so it can be reproduced anywhere." # "1. Define your app’s environment with a Dockerfile so it can be reproduced anywhere."

3
containers/lmk.devuan-chimaera/Dockerfile

@ -8,7 +8,10 @@ RUN apt-get update
RUN apt-get install -y unzip RUN apt-get install -y unzip
RUN apt-get install -y perl RUN apt-get install -y perl
RUN unzip /opt/linux-minetest-kit.zip -d /opt RUN unzip /opt/linux-minetest-kit.zip -d /opt
# RUN adduser --disabled-password --gecos "" minebest
# RUN apt-get install -y sudo # RUN apt-get install -y sudo
# RUN curl https://raw.githubusercontent.com/poikilos/EnlivenMinetest/master/install-minetest-build-deps.sh --output /opt/install-minetest-build-deps.sh # RUN curl https://raw.githubusercontent.com/poikilos/EnlivenMinetest/master/install-minetest-build-deps.sh --output /opt/install-minetest-build-deps.sh
# RUN chmod +x /opt/install-minetest-build-deps.sh # RUN chmod +x /opt/install-minetest-build-deps.sh
RUN /opt/install-minetest-build-deps.sh RUN /opt/install-minetest-build-deps.sh
WORKDIR /opt/linux-minetest-kit
RUN bash -e ./mtcompile-libraries.sh build

73
containers/lmk.devuan-chimaera/build-lmk.sh

@ -19,33 +19,7 @@ echo "* checking for $contained_good_repo_flag_path on the destination..."
ls $contained_good_repo_flag_path > /dev/null ls $contained_good_repo_flag_path > /dev/null
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "NOT FOUND" echo "NOT FOUND"
printf "Warning: the Docker image isn't up to date. Unzipping manually..."
printf "checking for unzip..."
container_unzip="`which unzip`"
if [ "@$container_unzip" = "@" ]; then
echo "NOT FOUND. Installing..."
# This should never happen if the Dockerfile was used.
apt-get update
if [ $? -ne 0 ]; then exit 1; fi
apt-get install -y unzip
if [ $? -ne 0 ]; then exit 1; fi
container_unzip="`which unzip`"
if [ "@$container_unzip" = "@" ]; then
echo "Error: Installing unzip in the container did not succeed. Install unzip inside the container manually then try again, or extract linux-minetest-kit such that $contained_good_repo_flag_path exists."
exit 1 exit 1
fi
else
echo "FOUND"
fi
# sudo docker container run $image_name unzip xvf $contained_arc -d $contained_repos
echo "* extracting $contained_arc"
unzip $contained_arc -d $contained_repos
# -d: is destination, like -C or --directory for tar.
# -v: verbose (prevents extraction)
if [ $? -ne 0 ]; then
echo "Error: unzip failed within the container. Install unzip inside the container manually then try again, or extract linux-minetest-kit such that $contained_good_repo_flag_path exists."
exit 1
fi
else else
echo "FOUND (already extracted)" echo "FOUND (already extracted)"
fi fi
@ -59,38 +33,6 @@ else
echo "* detected $contained_good_repo_flag_path (So the source directory is assumed to be ok)" echo "* detected $contained_good_repo_flag_path (So the source directory is assumed to be ok)"
fi fi
if [ "@$contained_user" = "@" ]; then
echo "Error: contained_user can't be blank, or checking for the user within the container will not work."
exit 1
fi
id -u $contained_user
if [ $? -ne 0 ]; then
printf "* creating $contained_user in container $container_name..."
adduser --disabled-password --gecos "" $contained_user --home $contained_home
if [ $? -ne 0 ]; then
echo "FAILED"
exit 1
else
echo "OK"
fi
else
echo "* using the $container_name container's existing contained_user: $contained_user"
fi
# sudo docker container run --name $container_name $image_name ls $contained_repos
# chown -R $contained_user $contained_repos
# ^ Usually you could do this, but run as root since this script is used to test the safety of linux-minetest-kit:
# curl https://raw.githubusercontent.com/poikilos/EnlivenMinetest/master/install-minetest-build-deps.sh --output /opt/install-minetest-build-deps.sh
# chmod +x $repo_build_assumptions_cmd
# $repo_build_assumptions_cmd
# ^ moved to Dockerfile
if [ ! -d "$contained_repo" ]; then if [ ! -d "$contained_repo" ]; then
echo "Error: \"$contained_repo\" doesn't exist." echo "Error: \"$contained_repo\" doesn't exist."
exit 1 exit 1
@ -98,13 +40,8 @@ fi
echo "* building libraries using $repo_build_libs_cmd..." echo "* building libraries using $repo_build_libs_cmd..."
cd "$contained_repo" cd "$contained_repo"
if [ $? -ne 0 ]; then exit 1; fi if [ $? -ne 0 ]; then exit 1; fi
$repo_build_libs_cmd # $repo_build_libs_cmd
if [ $? -ne 0 ]; then exit 1; fi # if [ $? -ne 0 ]; then exit 1; fi
echo
echo
echo
echo
echo
echo echo
echo "* building program using $repo_build_cmd..." echo "* building program using $repo_build_cmd..."
$repo_build_cmd $repo_build_cmd
@ -112,4 +49,10 @@ code=$?
if [ $code -ne 0 ]; then if [ $code -ne 0 ]; then
echo "$repo_build_cmd FAILED (code $code)" echo "$repo_build_cmd FAILED (code $code)"
exit $code exit $code
else
echo "SUCCESS"
echo "Note that if you run this again, it will just compile again."
echo
echo "To run Minetest, follow the instructions that appear below (if you ran $docker_image_build_script_name)"
echo
fi fi

10
containers/lmk.devuan-chimaera/lmk.rc

@ -1,10 +1,14 @@
#!/bin/bash #!/bin/bash
contained_repos=/opt contained_repos=/opt
docker_image_build_script_name="lmk.devuan-chimaera.sh"
contained_arc="$contained_repos/linux-minetest-kit.zip" contained_arc="$contained_repos/linux-minetest-kit.zip"
# ^ This must always be in sync with "COPY linux-minetest-kit.zip /opt" in Dockerfile # ^ This must always be in sync with "COPY linux-minetest-kit.zip /opt" in Dockerfile
contained_repo=$contained_repos/linux-minetest-kit contained_repo=$contained_repos/linux-minetest-kit
contained_user=minebest contained_user=minebest
# ^ must match the useradd command in Dockerfile
contained_home=/home/$contained_user contained_home=/home/$contained_user
# client_bin_path=/opt/linux-minetest-kit/minetest/bin/minetest
server_bin_path=/opt/linux-minetest-kit/finetest/bin/minetestserver
if [ "@$SRC_URL" = "@" ]; then if [ "@$SRC_URL" = "@" ]; then
SRC_URL="https://downloads.minetest.org/linux-minetest-kit.zip" SRC_URL="https://downloads.minetest.org/linux-minetest-kit.zip"
fi fi
@ -14,8 +18,10 @@ DL_SRC_NAME=linux-minetest-kit.zip
good_repo_flag_name="mtcompile-program.pl" good_repo_flag_name="mtcompile-program.pl"
repo_build_assumptions_cmd="/opt/install-minetest-build-deps.sh" repo_build_assumptions_cmd="/opt/install-minetest-build-deps.sh"
repo_build_libs_cmd="bash -e ./mtcompile-libraries.sh build" # repo_build_libs_cmd="bash -e ./mtcompile-libraries.sh build"
repo_build_cmd="./mtcompile-program.pl --build --classic --client" # ^ moved to the Dockerfile for the libraries image
# repo_build_cmd="./mtcompile-program.pl --build --classic --client"
repo_build_cmd="./mtcompile-program.pl --build --finetest --server"
contained_good_repo_flag_path="$contained_repo/$good_repo_flag_name" contained_good_repo_flag_path="$contained_repo/$good_repo_flag_name"
run_all_build_commands_script=/opt/build-lmk.sh run_all_build_commands_script=/opt/build-lmk.sh

Loading…
Cancel
Save