From dc03752c8d406949460bc07d27891020ee4693f3 Mon Sep 17 00:00:00 2001 From: poikilos <7557867+poikilos@users.noreply.github.com> Date: Fri, 13 May 2022 02:03:02 -0400 Subject: [PATCH] Separate the logic and data (move data to a new rc file) for the build. Rename variables correctly. --- docker/libraries-devuan-chimera/build-lmk.sh | 58 --------- docker/libraries-devuan-chimera/lmk.rc | 7 +- docker/lmk.devuan-chimaera.rc | 12 ++ docker/lmk.devuan-chimaera.sh | 113 ++++++++++-------- .../server-finetest-devuan-chimera/Dockerfile | 3 + .../build-and-check.sh | 11 ++ 6 files changed, 96 insertions(+), 108 deletions(-) delete mode 100755 docker/libraries-devuan-chimera/build-lmk.sh create mode 100644 docker/lmk.devuan-chimaera.rc create mode 100755 docker/server-finetest-devuan-chimera/build-and-check.sh diff --git a/docker/libraries-devuan-chimera/build-lmk.sh b/docker/libraries-devuan-chimera/build-lmk.sh deleted file mode 100755 index 69dfe75..0000000 --- a/docker/libraries-devuan-chimera/build-lmk.sh +++ /dev/null @@ -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 diff --git a/docker/libraries-devuan-chimera/lmk.rc b/docker/libraries-devuan-chimera/lmk.rc index 426a1ae..484d5ca 100644 --- a/docker/libraries-devuan-chimera/lmk.rc +++ b/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." diff --git a/docker/lmk.devuan-chimaera.rc b/docker/lmk.devuan-chimaera.rc new file mode 100644 index 0000000..8c876a0 --- /dev/null +++ b/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 diff --git a/docker/lmk.devuan-chimaera.sh b/docker/lmk.devuan-chimaera.sh index 798bd7c..6f4e2b5 100755 --- a/docker/lmk.devuan-chimaera.sh +++ b/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 . 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 <) # 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 ) @@ -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 <. # 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 ): # "1. Define your app’s environment with a Dockerfile so it can be reproduced anywhere." diff --git a/docker/server-finetest-devuan-chimera/Dockerfile b/docker/server-finetest-devuan-chimera/Dockerfile index 772a9a1..cbb9eb1 100644 --- a/docker/server-finetest-devuan-chimera/Dockerfile +++ b/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 diff --git a/docker/server-finetest-devuan-chimera/build-and-check.sh b/docker/server-finetest-devuan-chimera/build-and-check.sh new file mode 100755 index 0000000..2b0cb92 --- /dev/null +++ b/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