Browse Source

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

master
poikilos 2 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
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
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
SRC_URL="https://downloads.minetest.org/linux-minetest-kit.zip"
fi
@ -22,8 +24,9 @@ repo_build_assumptions_cmd="/opt/install-minetest-build-deps.sh"
# ^ 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 --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"
# 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."

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
# See https://nextbreakpoint.com/posts/article-compile-code-with-docker.html
# 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'`"
ENABLE_RUN_CLIENT=false
ENABLE_CLASSIC=false
for var in "$@"
do
if [ "@$var" = "@--run-client" ]; then
ENABLE_RUN_CLIENT=true
if [ "@$var" = "@--classic" ]; then
ENABLE_CLASSIC=true
fi
done
@ -20,30 +18,25 @@ or Docker's own documentation at
<https://docs.docker.com/engine/install/>.
END
fi
container_name="linux-minetest-kit-build-libraries-devuan-chimaera"
image_name="linux-minetest-kit/libraries-devuan-chimaera"
# ^ This must match the one used in the "FROM" statement in server-finetest-devuan-chimera/Dockerfile
# client_classic_image=linux-minetest-kit/client-classic
server_finetest_image="linux-minetest-kit/server-finetest-devuan-chimera"
# client_classic_container="minetest-client-classic"
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"
# 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
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"
exit 1
fi
container_build_blob=$docker_image_dir/linux-minetest-kit.zip
# ^ docker_image_dir has to be in the same directory as Dockerfile or
# ^ docker_libraries_image_dir has to be in the same directory as Dockerfile or
# 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
exit 1
fi
if [ "@$DL_SRC_PATH" = "@" ]; then
# 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
# the COPY command in the Dockerfile won't work.
# The file should be added to .gitignore for the reason that it
@ -51,17 +44,18 @@ if [ "@$DL_SRC_PATH" = "@" ]; then
fi
# sudo docker image inspect $image_name > /dev/null
sudo docker image inspect $image_name --format "* docker is looking for the image..."
# sudo docker image inspect $library_image > /dev/null
sudo docker image inspect $library_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_image_dir" ]; then
echo "Error: \"$docker_image_dir\" (docker_image_dir for storing $SRC_URL) doesn't exist in \"`pwd`\"."
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`\"."
exit 1
fi
echo "* building image $library_image..."
if [ ! -f "$container_build_blob" ]; then
echo "* downloading $SRC_URL to $DL_SRC_PATH..."
curl "$SRC_URL" --progress-bar --output "$DL_SRC_PATH"
@ -75,14 +69,13 @@ if [ $? -ne 0 ]; then
else
echo "* using existing \"$container_build_blob\" to build the container image"
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.
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
fi
move_back="false"
prerelease_path=~/Downloads/minetest.org/insider-prerelease/linux-minetest-kit-220509.zip
if [ ! -f $container_build_blob ]; then
if [ -f "$prerelease_path" ]; then
move_back="true"
@ -94,7 +87,7 @@ if [ $? -ne 0 ]; then
fi
fi
fi
sudo docker build -t $image_name $docker_image_dir
sudo docker build -t $library_image $docker_libraries_image_dir
code=$?
if [ "@move_back" = "@true" ]; then
echo "mv \"$prerelease_path\" \"$container_build_blob\""
@ -107,7 +100,7 @@ if [ $? -ne 0 ]; then
exit 1
fi
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
cat <<END
@ -119,7 +112,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 $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).
sudo docker image prune
@ -138,9 +131,9 @@ How to use the image:
# ^ "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 $run_all_build_commands_script
# ^ 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)!
# 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.
# 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/>)
# 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)
# (based on <https://phoenixnap.com/kb/docker-run-command-with-examples>)
@ -168,14 +161,14 @@ How to use the image:
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"`
# ^ ONLY works with container_name not image_name
# ^ ONLY works with container_name not library_image
cat > /dev/null <<END
if [ "@$container_Id" = "@" ]; then
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
if [ $? -ne 0 ]; then
echo "FAILED"
@ -189,15 +182,37 @@ if [ "@$container_Id" = "@" ]; then
fi
END
echo "container_Id=$container_Id"
# echo "building within the container..."
# sudo docker start $container_name
# ^ NOTE: start is useless here since it won't stay open unless the
# command is set to "bash" or something, which isn't desirable.
# Therefore, use run instead of exec below.
# ^ 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
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=$?
if [ $code -ne 0 ]; then
cat <<END
@ -207,7 +222,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 $image_name
sudo docker rmi $docker_finetest_server_image_name
sudo docker image prune --force
# --force: Don't prompt for confirmation.
@ -220,7 +235,8 @@ END
echo "* building within the container completed OK"
fi
else
echo "* The build container already appears to be set up."
echo "* The container already appears to be set up."
exit 0
fi
echo
# 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/>.
# 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
# echo "* Creating image \"$server_finetest_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
# ^ Build the server as a separate step instead (see further up)
# 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."

3
docker/server-finetest-devuan-chimera/Dockerfile

@ -1,3 +1,6 @@
FROM linux-minetest-kit/libraries-devuan-chimaera
COPY build-and-check.sh /opt/
WORKDIR /opt/linux-minetest-kit
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