diff --git a/README.md b/README.md index 64162b1..e5776c9 100644 --- a/README.md +++ b/README.md @@ -343,6 +343,7 @@ This section describes the config.json as currently specified. The section is a - **`scripts.environment`**: JSON object describing the general environment in which the script will run. - **`scripts.environment.image`**: Docker image of the container in which the script will run. This does not need to be the same as the image of the service. - **`scripts.environment.interactive`**: When set to true, your Docker container is ran in interactive mode and can thus receive input from the user. Non-interactive scripts are easier to call by external scripts. +- **`scripts.environment.privileged`**: If the script needs to run in privileged mode (sharing the docker sock) - **`scripts.environment.join_networks`**: For scripts which run in a project, this will make the script container join the default network. Set to `true` to activate this option. - **`scripts.environment.script`**: The script which will be ran. Make sure this script is executable (`chmod a+x your-script.sh`). If the script can be ran by your container as a script, it's fine. You could use a shebang like `#!/usr/bin/ruby` as the first line of your script to run a ruby script, or you could have a standard shell script which launches something totally different. - **`scripts.mounts.app`**: For scripts which run in a project, this is the place where the full project folder will be mounted. It allows you to do things like create new files for the project. diff --git a/mu b/mu index ed35ae7..0766a12 100755 --- a/mu +++ b/mu @@ -359,12 +359,7 @@ then fi elif [[ "script" == $1 ]] then - # Check if we are in a project or in a service - if [[ -f ./docker-compose.yml && -f Dockerfile ]] - then - echo "mu script is not supported in folders which have a Dockerfile and a docker-compose.yml" - exit 1 - elif [[ -f ./docker-compose.yml ]] + if [[ -f ./docker-compose.yml ]] then service=$2 command=$3 @@ -455,6 +450,43 @@ then fi echo -n "." + privileged_mode=`echo "$command_spec" | $interactive_cli jq -r '.environment.privileged // false'` + echo -n "." + privileged="" + if [[ true == "$privileged_mode" ]]; + then + entrypoint_script=/tmp/mu/cache/$container_id/scripts/$script_path + echo + read -p "The script you're about to run needs privileged mode. Are you sure? (Y/N) " -n 1 -r + if [[ $REPLY =~ ^[Yy]$ ]] + then + suspicious_patterns=( + "wget" + ) + suspicious_found=false + suspicious_pat='' + for pat in "${suspicious_patterns[@]}"; do + if grep -qi "$pat" "$entrypoint_script"; then + suspicious_found=true + suspicious_pat=$pat + break + fi + done + + if $suspicious_found; then + echo + read -p "The script you're about to run has at least one suspicious pattern ('$suspicious_pat'), are you sure(Y/N)? " -n 1 -r + if [[ ! $REPLY =~ ^[Yy]$ ]]; then + exit 2 + fi + fi + privileged=" --privileged " + else + exit 0 + fi + echo + fi + echo -n "." network_options=$() join_networks=`echo "$command_spec" | $interactive_cli jq -r '.environment.join_networks // false'` echo -n "." @@ -470,7 +502,7 @@ then then volume_mounts+=(--volume $PWD:$app_mount_point) fi - docker run ${network_options[@]} ${volume_mounts[@]} $it -w $working_directory --rm --entrypoint ./$entry_point $image_name "${arguments[@]}" + docker run ${network_options[@]} ${volume_mounts[@]} $privileged $it -w $working_directory --rm --entrypoint ./$entry_point $image_name "${arguments[@]}" elif [[ -f "Dockerfile" ]] then # A script for developing a microservice @@ -608,11 +640,25 @@ then status_step # 21 + privileged_mode=`echo "$command_spec" | $interactive_cli jq -r '.environment.privileged // false'` + privileged="" + if [[ true == "$privileged_mode" ]]; + then + echo + read -p "The script you're about to run needs privileged mode. Are you sure? " -n 1 -r + if [[ $REPLY =~ ^[Yy]$ ]] + then + privileged=" --privileged " + fi + echo + fi + status_step # 22 + echo " DONE" echo "Executing script $command ${arguments[@]}" - docker run ${docker_volumes[@]} ${docker_environment_variables[@]} $it -w $working_directory --rm --entrypoint ./$entry_point $image_name "${arguments[@]}" + docker run ${docker_volumes[@]} ${docker_environment_variables[@]} $privileged $it -w $working_directory --rm --entrypoint ./$entry_point $image_name "${arguments[@]}" exit 0 else echo "Did not recognise location"