Browse Source

Separate the logic and data (move data to a new rc file) for the build. Rename variables correctly.

master
poikilos 3 years ago
parent
commit
dc03752c8d
  1. 58
      docker/libraries-devuan-chimera/build-lmk.sh
  2. 7
      docker/libraries-devuan-chimera/lmk.rc
  3. 12
      docker/lmk.devuan-chimaera.rc
  4. 113
      docker/lmk.devuan-chimaera.sh
  5. 3
      docker/server-finetest-devuan-chimera/Dockerfile
  6. 11
      docker/server-finetest-devuan-chimera/build-and-check.sh

58
docker/libraries-devuan-chimera/build-lmk.sh

@ -1,58 +0,0 @@
#!/bin/bash
cd /opt
if [ $? -ne 0 ]; then
exit 1
fi
source lmk.rc
me=build-lmk.sh
if [ $? -ne 0 ]; then
exit 1
fi
if [ "@$contained_repo" = "@" ]; then
echo "Error: contained_repo can't be blank or checking for its files in the container won't work."
exit 1
fi
# ls $contained_repo
echo "* checking for $contained_good_repo_flag_path on the destination..."
ls $contained_good_repo_flag_path > /dev/null
if [ $? -ne 0 ]; then
echo "NOT FOUND"
exit 1
else
echo "FOUND (already extracted)"
fi
# ls $contained_repo > /dev/null
ls $contained_good_repo_flag_path > /dev/null
if [ $? -ne 0 ]; then
echo "Error: extracting linux-minetest-kit.zip in the container didn't work. Extract linux-minetest-kit.zip to $contained_repos such that $contained_good_repo_flag_path exists in the container and try again."
exit 1
else
echo "* detected $contained_good_repo_flag_path (So the source directory is assumed to be ok)"
fi
if [ ! -d "$contained_repo" ]; then
echo "Error: \"$contained_repo\" doesn't exist."
exit 1
fi
echo "* building libraries using $repo_build_libs_cmd..."
cd "$contained_repo"
if [ $? -ne 0 ]; then exit 1; fi
# $repo_build_libs_cmd
# if [ $? -ne 0 ]; then exit 1; fi
echo
echo "* building program using $build_finetest_server_cmd..."
$build_finetest_server_cmd
code=$?
if [ $code -ne 0 ]; then
echo "$build_finetest_server_cmd FAILED (code $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

7
docker/libraries-devuan-chimera/lmk.rc

@ -8,7 +8,9 @@ contained_user=minebest
# ^ must match the useradd command in Dockerfile # ^ 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 # client_bin_path=/opt/linux-minetest-kit/minetest/bin/minetest
server_bin_path=/opt/linux-minetest-kit/finetest/bin/minetestserver server_bin_path=/opt/linux-minetest-kit/finetest/bin/multicraftserver
# ^ since ./mtcompile-program.pl --build --finetest --server says:
# "Built target multicraftserver"
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
@ -22,8 +24,9 @@ repo_build_assumptions_cmd="/opt/install-minetest-build-deps.sh"
# ^ moved to the Dockerfile for the libraries image # ^ moved to the Dockerfile for the libraries image
# build_finetest_server_cmd="./mtcompile-program.pl --build --classic --client" # build_finetest_server_cmd="./mtcompile-program.pl --build --classic --client"
# build_finetest_server_cmd="./mtcompile-program.pl --build --finetest --server" # build_finetest_server_cmd="./mtcompile-program.pl --build --finetest --server"
# ^ moved to server-finetest-devuan-chimera/Dockerfile # ^ moved to server-finetest-devuan-chimaera/Dockerfile
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
# ^ deprecated: Now the library Dockerfile builds libraries, and the server Dockerfile builds the server.
echo "lmk.rc finished loading." echo "lmk.rc finished loading."

12
docker/lmk.devuan-chimaera.rc

@ -0,0 +1,12 @@
container_name="finetest-devuan-chimaera-lmk"
library_image="linux-minetest-kit/libraries-devuan-chimaera"
docker_finetest_server_image_name="linux-minetest-kit/server-finetest-devuan-chimaera"
# ^ This must match the one used in the "FROM" statement in server-finetest-devuan-chimaera/Dockerfile
# client_classic_image=linux-minetest-kit/client-classic
server_finetest_image="linux-minetest-kit/server-finetest-devuan-chimaera"
# client_classic_container="minetest-client-classic"
server_container="minetestserver-finetest"
docker_libraries_image_dir="libraries-devuan-chimaera"
docker_finetest_server_image_dir="server-finetest-devuan-chimaera"
container_build_blob=$docker_libraries_image_dir/linux-minetest-kit.zip
prerelease_path=~/Downloads/minetest.org/insider-prerelease/linux-minetest-kit-220509.zip

113
docker/lmk.devuan-chimaera.sh

@ -1,14 +1,12 @@
#!/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 ENABLE_CLASSIC=false
for var in "$@" for var in "$@"
do do
if [ "@$var" = "@--run-client" ]; then if [ "@$var" = "@--classic" ]; then
ENABLE_RUN_CLIENT=true ENABLE_CLASSIC=true
fi fi
done done
@ -20,30 +18,25 @@ or Docker's own documentation at
<https://docs.docker.com/engine/install/>. <https://docs.docker.com/engine/install/>.
END END
fi fi
container_name="linux-minetest-kit-build-libraries-devuan-chimaera" # container_name="linux-minetest-kit-build-libraries-devuan-chimaera"
image_name="linux-minetest-kit/libraries-devuan-chimaera" # ^ This is no longer necessary since the IMAGE does the building (build was moved to Dockerfile)
# ^ This must match the one used in the "FROM" statement in server-finetest-devuan-chimera/Dockerfile source lmk.devuan-chimaera.rc
# client_classic_image=linux-minetest-kit/client-classic if [ $? -ne 0 ]; then exit 1; fi
server_finetest_image="linux-minetest-kit/server-finetest-devuan-chimera" if [ ! -d "$docker_libraries_image_dir" ]; then
# client_classic_container="minetest-client-classic" echo "* $0 must run from the directory containing the container image directory: $docker_libraries_image_dir"
server_container="minetestserver-finetest"
docker_image_dir="lmk-libraries.devuan-chimaera"
if [ ! -d "$docker_image_dir" ]; then
echo "* $0 must run from the directory containing the container image directory: $docker_image_dir"
exit 1 exit 1
fi fi
container_build_blob=$docker_image_dir/linux-minetest-kit.zip # ^ docker_libraries_image_dir has to be in the same directory as Dockerfile or
# ^ docker_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_image_dir/lmk.rc source $docker_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_image_dir" DL_SRC_PATH="$docker_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
@ -51,17 +44,18 @@ if [ "@$DL_SRC_PATH" = "@" ]; then
fi fi
# sudo docker image inspect $image_name > /dev/null # sudo docker image inspect $library_image > /dev/null
sudo docker image inspect $image_name --format "* docker is looking for the image..." sudo docker image inspect $library_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_image_dir" ]; then if [ ! -d "$docker_libraries_image_dir" ]; then
echo "Error: \"$docker_image_dir\" (docker_image_dir for storing $SRC_URL) doesn't exist in \"`pwd`\"." echo "Error: \"$docker_libraries_image_dir\" (docker_libraries_image_dir for storing $SRC_URL) doesn't exist in \"`pwd`\"."
exit 1 exit 1
fi fi
echo "* building image $library_image..."
if [ ! -f "$container_build_blob" ]; then if [ ! -f "$container_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"
@ -75,14 +69,13 @@ if [ $? -ne 0 ]; then
else else
echo "* using existing \"$container_build_blob\" to build the container image" echo "* using existing \"$container_build_blob\" to build the container image"
fi fi
cp ../install-minetest-build-deps.sh $docker_image_dir/ cp ../install-minetest-build-deps.sh $docker_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_image_dir/' failed." echo "Error: 'cp ../install-minetest-build-deps.sh $docker_libraries_image_dir/' failed."
exit 1 exit 1
fi fi
move_back="false" move_back="false"
prerelease_path=~/Downloads/minetest.org/insider-prerelease/linux-minetest-kit-220509.zip
if [ ! -f $container_build_blob ]; then if [ ! -f $container_build_blob ]; then
if [ -f "$prerelease_path" ]; then if [ -f "$prerelease_path" ]; then
move_back="true" move_back="true"
@ -94,7 +87,7 @@ if [ $? -ne 0 ]; then
fi fi
fi fi
fi fi
sudo docker build -t $image_name $docker_image_dir sudo docker build -t $library_image $docker_libraries_image_dir
code=$? code=$?
if [ "@move_back" = "@true" ]; then if [ "@move_back" = "@true" ]; then
echo "mv \"$prerelease_path\" \"$container_build_blob\"" echo "mv \"$prerelease_path\" \"$container_build_blob\""
@ -107,7 +100,7 @@ if [ $? -ne 0 ]; then
exit 1 exit 1
fi fi
else else
echo "* The container will be built using the existing docker image $image_name" echo "* The container will be built using the existing docker image $library_image"
fi fi
cat <<END cat <<END
@ -119,7 +112,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 $image_name sudo docker rmi $library_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 sudo docker image prune
@ -138,9 +131,9 @@ How to use the image:
# ^ "run" is merely a combination of "create" and "start" # ^ "run" is merely a combination of "create" and "start"
sudo docker -w $contained_repo exec $container_name ls -l $contained_repos sudo docker -w $contained_repo exec $container_name ls -l $contained_repos
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)!
# That is because the Dockerfile ENTRYPOINT (or if customized on a per-container basis, the "docker run" command) specifies the entry point (permanently) for the container.
# 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. # 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
@ -148,7 +141,7 @@ 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 $image_name /bin/bash sudo docker container run -it $library_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>)
@ -168,14 +161,14 @@ How to use the image:
END END
# sudo docker container run -d --name $image_name unzip xvf $contained_arc -C $contained_repos # sudo docker container run -d --name $library_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 image_name # ^ ONLY works with container_name not library_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 $image_name sudo docker create --name=$container_name $library_image
# ^ output is the Id # ^ output is the Id
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "FAILED" echo "FAILED"
@ -189,15 +182,37 @@ if [ "@$container_Id" = "@" ]; then
fi fi
END END
echo "container_Id=$container_Id"
# echo "building within the container..." # 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
echo "* The container already appears to be set up."
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_name --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
else
echo "* using existing $docker_finetest_server_image_name"
fi
if [ "@$container_Id" = "@" ]; then if [ "@$container_Id" = "@" ]; then
sudo docker run --name $container_name $image_name $run_all_build_commands_script # sudo docker run --name $container_name $library_image $run_all_build_commands_script
# ^ build was moved to the Dockerfile
echo "* creating container $container_name from image $docker_finetest_server_image_name"
sudo docker run --name $container_name $docker_finetest_server_image_name /opt/linux-minetest-kit/minetest/minetestserver
code=$? code=$?
if [ $code -ne 0 ]; then if [ $code -ne 0 ]; then
cat <<END cat <<END
@ -207,7 +222,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 $image_name sudo docker rmi $docker_finetest_server_image_name
sudo docker image prune --force sudo docker image prune --force
# --force: Don't prompt for confirmation. # --force: Don't prompt for confirmation.
@ -220,7 +235,8 @@ END
echo "* building within the container completed OK" echo "* building within the container completed OK"
fi fi
else else
echo "* The build container already appears to be set up." echo "* The container already appears to be set up."
exit 0
fi fi
echo echo
# echo "If the build output appeared successful, ignore the error above and create the minetest client image as follows:" # echo "If the build output appeared successful, ignore the error above and create the minetest client image as follows:"
@ -244,16 +260,17 @@ 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 server image..." # echo "* Creating image \"$server_finetest_image\"..."
sudo docker commit $container_Id $server_finetest_image # sudo docker commit $container_Id $server_finetest_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_finetest_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_finetest_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_finetest_image $server_bin_path)"
fi # fi
# ^ Build the server as a separate step instead (see further up)
# 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
docker/server-finetest-devuan-chimera/Dockerfile

@ -1,3 +1,6 @@
FROM linux-minetest-kit/libraries-devuan-chimaera FROM linux-minetest-kit/libraries-devuan-chimaera
COPY build-and-check.sh /opt/
WORKDIR /opt/linux-minetest-kit WORKDIR /opt/linux-minetest-kit
RUN ./mtcompile-program.pl --build --finetest --server RUN ./mtcompile-program.pl --build --finetest --server
# ^ Always returns 1, so:
# RUN build-and-check.sh

11
docker/server-finetest-devuan-chimera/build-and-check.sh

@ -0,0 +1,11 @@
#!/bin/bash
./mtcompile-program.pl --build --finetest --server
echo "Returned $1"
good_flag_file=minetest/bin/multicraftserver
if [ -f "$good_flag_file" ]; then
echo "* forcing OK return since found \"$good_flag_file\""
exit 0
else
echo "* forcing OK return since \"$good_flag_file\" doesn't exist"
exit 1
fi
Loading…
Cancel
Save