diff --git a/docker-compose.osx.yml b/docker-compose.osx.yml index 446cb79..95b5207 100644 --- a/docker-compose.osx.yml +++ b/docker-compose.osx.yml @@ -27,7 +27,7 @@ services: XDEBUG_CONFIG: "remote_host=docker.for.mac.localhost" PHP_IDE_CONFIG: serverName=localhost volumes: - - .:/code + - nfsmount:/code - ./shared:/shared - $HOME/.ssh/id_rsa:/root/.ssh/id_rsa @@ -53,3 +53,11 @@ services: redis: image: redis:alpine network_mode: service:web + +volumes: + nfsmount: + driver: local + driver_opts: + type: nfs + o: addr=host.docker.internal,rw,nolock,hard,nointr,nfsvers=3 + device: ":${PWD}" diff --git a/dsh b/dsh index f6782fa..df7ab00 100755 --- a/dsh +++ b/dsh @@ -108,6 +108,96 @@ dsh_pull() { docker-compose -f ${DOCKER_COMPOSE_FILE} pull } +# Command: ./dsh nfs +# Sets up NFS integration for OSX. +NFS_FILE=/etc/exports +NFS_LINE="/Users -alldirs -mapall=$(id -u):$(id -g) localhost" +dsh_setup_nfs() { + if [ ${HOST_TYPE} != "mac" ]; then + echo "This script is OSX-only. Please do not run it on any other Unix." + exit 1 + fi + + if [[ $EUID -eq 0 ]]; then + echo "This script must NOT be run with sudo/root. Please re-run without sudo." 1>&2 + exit 1 + fi + + echo "" + echo " +-----------------------------+" + echo " | Setup native NFS for Docker |" + echo " +-----------------------------+" + echo "" + + echo "WARNING: This script will shut down running containers." + echo "" + echo -n "Do you wish to proceed? [y]: " + read decision + + if [ "$decision" != "y" ]; then + echo "Exiting. No changes made." + exit 1 + fi + + echo "" + + if ! docker ps > /dev/null 2>&1 ; then + echo "== Waiting for docker to start..." + fi + + open -a Docker + + while ! docker ps > /dev/null 2>&1 ; do sleep 2; done + + echo "== Stopping running docker containers..." + docker-compose -f ${DOCKER_COMPOSE_FILE} down > /dev/null 2>&1 + docker volume prune -f > /dev/null + + osascript -e 'quit app "Docker"' + + echo "== Resetting folder permissions..." + sudo chown -R "$(id -u)":"$(id -g)" . + + echo "== Setting up nfs..." + sudo cp /dev/null "$NFS_FILE" + grep -qF -- "$NFS_LINE" "$NFS_FILE" || sudo echo "$NFS_LINE" | sudo tee -a "$NFS_FILE" > /dev/null + + LINE="nfs.server.mount.require_resv_port = 0" + FILE=/etc/nfs.conf + grep -qF -- "$LINE" "$FILE" || sudo echo "$LINE" | sudo tee -a "$FILE" > /dev/null + + echo "== Restarting nfsd..." + sudo nfsd restart + + echo "== Restarting docker..." + open -a Docker + + while ! docker ps > /dev/null 2>&1 ; do sleep 2; done + + echo "" + echo "SUCCESS! Now go run your containers 🐳" +} + +# Command: ./dsh rnfs +# Removes nfs setup. +dsh_remove_nfs() { + if [ ${HOST_TYPE} != "mac" ]; then + echo "This script is OSX-only. Please do not run it on any other Unix." + exit 1 + fi + + if [[ $EUID -eq 0 ]]; then + echo "This script must NOT be run with sudo/root. Please re-run without sudo." 1>&2 + exit 1 + fi + + echo "== Removing nfsd exports..." + sudo sed -i '' "/$(echo "$NFS_LINE" | sed 's/\//\\\//g')/d" ${NFS_FILE} + echo "== Restarting nfsd..." + sudo nfsd restart + echo "== Done" +} + dsh_help() { printf "\nUsage: dsh COMMAND\n\n Commands:\n @@ -134,6 +224,12 @@ case ${COMMAND} in l*) dsh_logs ;; + nfs) + dsh_setup_nfs + ;; + rnfs) + dsh_remove_nfs + ;; pul*) dsh_pull ;;