From 67113e897a4c0bb573abcf3777f74ded157e3cd7 Mon Sep 17 00:00:00 2001 From: Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com> Date: Thu, 10 Oct 2024 18:45:58 +0200 Subject: [PATCH] feat(docker): add support for additional files in Dockerfile Explanatory body: This commit extends the Dockerfile and related scripts to support the inclusion of additional files during image build. The Dockerfile now accepts an `ADDITIONAL_FILES` argument, which can be passed during the build process. These additional files are copied into the container at specified paths. The changes also include updates to the `docker-compose.yaml` file and related scripts to handle the new `ADDITIONAL_FILES` argument appropriately during composition and execution. --- .util/.mod_env.json.tmpl | 4 +++- .util/Dockerfile | 19 +++++++++++++++++++ .util/docker-compose.yaml | 3 ++- .util/run_tests.sh | 26 ++++++++++++++------------ 4 files changed, 38 insertions(+), 14 deletions(-) diff --git a/.util/.mod_env.json.tmpl b/.util/.mod_env.json.tmpl index 6263052..3e05f6a 100644 --- a/.util/.mod_env.json.tmpl +++ b/.util/.mod_env.json.tmpl @@ -9,5 +9,7 @@ ], "minetest_add_conf": "", "client_nb": 1, - "additional_mods": "" + "additional_mods": "", + "additional_files": [ + ] } diff --git a/.util/Dockerfile b/.util/Dockerfile index 3591258..9373ff1 100644 --- a/.util/Dockerfile +++ b/.util/Dockerfile @@ -1,6 +1,7 @@ # FROM ghcr.io/minetest/minetest:latest as builder ARG DEPENDENCIES +ARG ADDITIONAL_FILES="" ARG MINETEST_ADD_CONF="" ENV STOP_SERVER=true @@ -27,6 +28,24 @@ while read dep; do done < <(echo "$DEPENDENCIES" | jq -c '.[]') EOF +RUN < "$dep_path" + fi +done < <(echo "$ADDITIONAL_FILES" | jq -c '.[]') +EOF + COPY <<"EOF" /usr/local/sbin/run_minetest #!/usr/bin/env bash diff --git a/.util/docker-compose.yaml b/.util/docker-compose.yaml index 2ae1c4b..cc2f5ce 100644 --- a/.util/docker-compose.yaml +++ b/.util/docker-compose.yaml @@ -6,7 +6,8 @@ services: dockerfile: Dockerfile args: DEPENDENCIES: "${DEPENDENCIES}" - MINETEST_ADD_CONF: "${MINETEST_ADD_CONF:-}" + MINETEST_ADD_CONF: "${MINETEST_ADD_CONF}" + ADDITIONAL_FILES: "${ADDITIONAL_FILES}" ports: - "30000:30000/udp" volumes: diff --git a/.util/run_tests.sh b/.util/run_tests.sh index 3584e21..3532b28 100755 --- a/.util/run_tests.sh +++ b/.util/run_tests.sh @@ -132,19 +132,19 @@ parse_params() { docker_cmd=$2 shift 2 ;; - -p | --port) + -p|--port) server_port=$2 shift 2 ;; - -t | --tests) + -t|--tests) run_tests=$2 shift 2 ;; - -i | --client-image) + -i|--client-image) client_image=$2 shift 2 ;; - -c | --clients) + -c|--clients) client_nb=$2 shift 2 ;; @@ -215,23 +215,25 @@ export STOP_SERVER="${stop_server:-true}" export FAILFAST="${failfast:-false}" export DEPENDENCIES="${dependencies}" export CLIENT_IMAGE="${client_image:-registry.apps.education.fr/iri/minetest/docker_test_harness/client:latest}" -if ($docker_cmd manifest inspect $CLIENT_IMAGE 2>&1 /dev/null); then +if ! $docker_cmd manifest inspect $CLIENT_IMAGE > /dev/null 2>&1 ; then die "CLIENT IMAGE $CLIENT_IMAGE does not exists" fi -export ENV_FILE="" + export CURRENT_MOD="" export ADDITIONAL_MODS="" +export ADDITIONAL_FILES="" if [ -f "$PWD/.mod_env.json" ]; then DEPENDENCIES="$(cat "$PWD/.mod_env.json" | jq -c ".dependencies//\"\"")" CURRENT_MOD="$(cat "$PWD/.mod_env.json" | jq -r ".current_mod//\"\"")" - CLIENT_NB="$(cat "$PWD/.mod_env.json" | jq -r ".client_nb//0")" + CLIENT_NB="$(cat "$PWD/.mod_env.json" | jq -r ".client_nb//$client_nb")" ADDITIONAL_MODS="$(cat "$PWD/.mod_env.json" | jq -r ".additional_mods//\"\"")" + ADDITIONAL_FILES="$(cat "$PWD/.mod_env.json" | jq -c ".additional_files//[]")" fi docker_compose_file=`mktemp --suffix=.yaml docker-composeXXXXXX --tmpdir=.util` cat "${script_dir}/docker-compose.yaml" > "$PWD/$docker_compose_file" -for (( clienti=1; clienti<=$client_nb; clienti++ )); do +for (( clienti=1; clienti<=$CLIENT_NB; clienti++ )); do cat <> "$PWD/$docker_compose_file" client${clienti}: image: \${CLIENT_IMAGE} @@ -254,10 +256,10 @@ if [ "$debug" = "true" ]; then echo -e "$GREEN--------------------------------------------------------------------------$NOFORMAT" fi -eval $docker_cmd compose $ENV_FILE -f "$PWD/${docker_compose_file}" down -eval $docker_cmd compose $ENV_FILE -f "$PWD/${docker_compose_file}" pull -eval $docker_cmd compose $ENV_FILE -f "$PWD/${docker_compose_file}" build --pull -eval $docker_cmd compose $ENV_FILE -f "$PWD/${docker_compose_file}" up --force-recreate --exit-code-from server --abort-on-container-exit +eval $docker_cmd compose -f "$PWD/${docker_compose_file}" down +eval $docker_cmd compose -f "$PWD/${docker_compose_file}" pull +eval $docker_cmd compose -f "$PWD/${docker_compose_file}" build --pull +eval $docker_cmd compose -f "$PWD/${docker_compose_file}" up --force-recreate --exit-code-from server --abort-on-container-exit exit_code=$? exit $exit_code \ No newline at end of file