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.
This commit is contained in:
parent
43a0aa7975
commit
67113e897a
@ -9,5 +9,7 @@
|
||||
],
|
||||
"minetest_add_conf": "",
|
||||
"client_nb": 1,
|
||||
"additional_mods": ""
|
||||
"additional_mods": "",
|
||||
"additional_files": [
|
||||
]
|
||||
}
|
||||
|
@ -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 <<EOF
|
||||
echo "ADDITIONAL_FILES"
|
||||
while read file_def; do
|
||||
content_type=$(echo "$file_def" | jq -r ".content|type")
|
||||
if [ "$content_type" = "object" ]; then
|
||||
content=$(echo "$file_def" | jq -r ".content")
|
||||
else
|
||||
content=$(echo "$file_def" | jq -c ".content")
|
||||
fi
|
||||
dep_path=$(echo "$file_def" | jq -r ".path")
|
||||
if ! [ -z "$dep_path" ]; then
|
||||
echo "Creating file $dep_path"
|
||||
mkdir -p $(dirname "$dep_path")
|
||||
echo "$content" > "$dep_path"
|
||||
fi
|
||||
done < <(echo "$ADDITIONAL_FILES" | jq -c '.[]')
|
||||
EOF
|
||||
|
||||
COPY <<"EOF" /usr/local/sbin/run_minetest
|
||||
#!/usr/bin/env bash
|
||||
|
||||
|
@ -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:
|
||||
|
@ -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 <<EOF >> "$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
|
Loading…
x
Reference in New Issue
Block a user