Skip to content

Commit a2ef3cc

Browse files
authored
Merge pull request #57 from itk-dev/feature/nfs
Added nfs support and version command
2 parents d6565c1 + 827140b commit a2ef3cc

File tree

12 files changed

+180
-39
lines changed

12 files changed

+180
-39
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@ docker preferences in the via the dock icon.
2020
* Disk (Ensure the file has type `raw`)
2121
* Advanced (CPU's, Memory)
2222

23+
From version 2.x this tool supports the usage of NFS mounted name-volumes, which
24+
gives faster file synchronisation during composer install and cache clear etc.
25+
26+
It comes with a command `nfs:enable` that exports the Users directory through
27+
NFS to localhost, so docker can map directories into the containers. It also
28+
requires some changes to the docker-compose.yml files which have been updated
29+
to support NFS.
30+
31+
If your project don't want to use NFS mounts you simply can remove the `nfsapp`
32+
volume and change the mappings back to `./` in the docker-compose.yml files.
33+
2334
## Usage
2435

2536
### Requirement for all commands to work

completion/bash/itkdev-docker-compose-completion.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ _idc_completions()
99
fi
1010

1111
# Keep the suggestions in a local variable
12-
local suggestions=($(compgen -W "url open drush template:install traefik:start traefik:stop traefik:open traefik:url mailhog:open mailhog:url sql:connect sql:port sql:open xdebug xdebug2 xdebug3 hosts:insert sync sync:db sync:files images:pull composer" -- "${COMP_WORDS[1]}"))
12+
local suggestions=($(compgen -W "url open drush nfs:enable template:install traefik:start traefik:stop traefik:open traefik:url mailhog:open mailhog:url sql:connect sql:port sql:open xdebug xdebug2 xdebug3 hosts:insert sync sync:db sync:files images:pull composer version bin/console" -- "${COMP_WORDS[1]}"))
1313

1414
COMPREPLY=("${suggestions[@]}")
1515

completion/zsh/_itkdev-docker-compose

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ _itkdev-docker-compose() {
3030
'url[Print url to site.]' \
3131
'open[Open url in default browser.]' \
3232
'drush[Run drush command.]' \
33+
'nfs\:enable[Enable NFS volume sharing.]' \
3334
'sync[Sync both database and files.]' \
3435
'sync\:db[Sync database base.]' \
3536
'sync\:files[Sync files base.]' \
@@ -49,6 +50,7 @@ _itkdev-docker-compose() {
4950
'hosts\:insert[Insert the docker site url into the hosts file.]' \
5051
'images\:pull[Update/pull all docker images.]' \
5152
'composer[Run composer command inside phpfpm container.]' \
53+
'version[Display this tool'\''s current version.]' \
5254
&& ret=0
5355

5456
# 'bin'{bin/*,vendor/bin/*}'[Run command command inside phpfpm container]' \

scripts/itkdev-docker-compose

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env bash
2+
VERSION=2.0.0
23
set -o errexit -o errtrace -o noclobber -o nounset -o pipefail
34
IFS=$'\n\t'
45

@@ -104,6 +105,26 @@ EOF
104105
fi
105106
}
106107

108+
function enableNFS {
109+
echo "Setting up NFS..."
110+
U=`id -u`
111+
G=`id -g`
112+
113+
LINE="/System/Volumes/Data/Users -alldirs -mapall=$U:$G localhost"
114+
FILE=/etc/exports
115+
sudo touch $FILE
116+
grep -qF -- "$LINE" "$FILE" || sudo echo "$LINE" | sudo tee -a $FILE > /dev/null
117+
118+
LINE="nfs.server.mount.require_resv_port = 0"
119+
FILE=/etc/nfs.conf
120+
grep -qF -- "$LINE" "$FILE" || sudo echo "$LINE" | sudo tee -a $FILE > /dev/null
121+
122+
echo "Restarting nfsd..."
123+
sudo nfsd restart
124+
125+
echo "You should restart docker to ensure NFS mounts works..."
126+
}
127+
107128
bold=$(tput bold)
108129
normal=$(tput sgr0)
109130

@@ -125,6 +146,9 @@ Commands:
125146
container. Otherwise, the drush container is used to
126147
run the command.
127148
149+
nfs:enable
150+
Enable support for NFS shares (performance boost on Macs)
151+
128152
sync
129153
Sync both database and files.
130154
@@ -196,6 +220,9 @@ Commands:
196220
down
197221
Stop and remove containers, networks, images, and volumes
198222
223+
version
224+
Display this tool's current version
225+
199226
*
200227
Pass command and arguments to `docker-compose` and
201228
hope for the best.
@@ -239,6 +266,24 @@ if [[ "$#" -gt "0" && "$1" == "template:install" ]]; then
239266
exit
240267
fi
241268

269+
# Allow nfs:enable without existence of docker-compose.yml.
270+
if [[ "$#" -gt "0" && "$1" == "nfs:enable" ]]; then
271+
enableNFS
272+
exit
273+
fi
274+
275+
# Allow version without existence of docker-compose.yml.
276+
if [[ "$#" -gt "0" && "$1" == "version" ]]; then
277+
echo Version: ${VERSION}
278+
exit
279+
fi
280+
281+
# Allow help without existence of docker-compose.yml.
282+
if [[ "$#" -gt "0" && "$1" == "--help" ]]; then
283+
usage
284+
exit
285+
fi
286+
242287
# @see https://unix.stackexchange.com/questions/13464/is-there-a-way-to-find-a-file-in-an-inverse-recursive-search/13474
243288
upsearch () {
244289
slashes=${PWD//[^\/]/}
@@ -551,11 +596,6 @@ EOF
551596
docker_compose exec "$@" /usr/bin/env sh
552597
;;
553598

554-
--help)
555-
usage
556-
exit
557-
;;
558-
559599
*)
560600
docker_compose "$cmd" "$@"
561601
;;

templates/aakbcms/docker-compose.yml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ services:
3737
depends_on:
3838
- mariadb
3939
volumes:
40-
- .:/app:delegated
40+
- nfsApp:/app:delegated
4141
- drush-cache:/root/.drush
4242

4343
nginx:
@@ -52,7 +52,7 @@ services:
5252
- '80'
5353
volumes:
5454
- ${PWD}/.docker/vhost.conf:/etc/nginx/conf.d/default.conf:ro
55-
- ./:/app:delegated
55+
- nfsApp:/app:delegated
5656
labels:
5757
- "traefik.enable=true"
5858
- "traefik.docker.network=frontend"
@@ -91,15 +91,25 @@ services:
9191
- drush
9292
volumes:
9393
- drush-cache:/root/.drush
94-
- ./:/app
94+
- nfsApp:/app
9595

9696
node:
9797
image: node:6
9898
networks:
9999
- app
100100
volumes:
101-
- .:/app:delegated
101+
- nfsApp:/app:delegated
102102

103-
# Drush cache volume to persist cache between runs.
104103
volumes:
104+
# Drush cache volume to persist cache between runs.
105105
drush-cache:
106+
# Named volume requires that you have NFS shares enabled (performance boost on Macs).
107+
# Use `itkdev-docker-compose nfs:enable` to enable NFS shares. If you don't want to use it remove it from here and
108+
# change the volume mapping to use normal shares in the containers. See
109+
# https://sean-handley.medium.com/how-to-set-up-docker-for-mac-with-native-nfs-145151458adc
110+
nfsApp:
111+
driver: local
112+
driver_opts:
113+
type: nfs
114+
o: addr=host.docker.internal,rw,nolock,hard,nointr,nfsvers=3
115+
device: ":$PWD"

templates/ddbcms/docker-compose.yml

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ networks:
1010

1111
services:
1212
mariadb:
13-
image: ding2/ding2-mysql
13+
image: ding2/ding2-mysql:master
1414
networks:
1515
- app
1616
- frontend
@@ -37,7 +37,7 @@ services:
3737
depends_on:
3838
- mariadb
3939
volumes:
40-
- .:/app:delegated
40+
- nfsApp:/app:delegated
4141
- drush-cache:/root/.drush
4242

4343
nginx:
@@ -52,7 +52,7 @@ services:
5252
- '80'
5353
volumes:
5454
- ${PWD}/.docker/vhost.conf:/etc/nginx/conf.d/default.conf:ro
55-
- ./:/app:delegated
55+
- nfsApp:/app:delegated
5656
labels:
5757
- "traefik.enable=true"
5858
- "traefik.docker.network=frontend"
@@ -91,15 +91,25 @@ services:
9191
- drush
9292
volumes:
9393
- drush-cache:/root/.drush
94-
- ./:/app
94+
- nfsApp:/app
9595

9696
node:
9797
image: node:6
9898
networks:
9999
- app
100100
volumes:
101-
- .:/app:delegated
101+
- nfsApp:/app:delegated
102102

103-
# Drush cache volume to persist cache between runs.
104103
volumes:
104+
# Drush cache volume to persist cache between runs.
105105
drush-cache:
106+
# Named volume requires that you have NFS shares enabled (performance boost on Macs).
107+
# Use `itkdev-docker-compose nfs:enable` to enable NFS shares. If you don't want to use it remove it from here and
108+
# change the volume mapping to use normal shares in the containers. See
109+
# https://sean-handley.medium.com/how-to-set-up-docker-for-mac-with-native-nfs-145151458adc
110+
nfsApp:
111+
driver: local
112+
driver_opts:
113+
type: nfs
114+
o: addr=host.docker.internal,rw,nolock,hard,nointr,nfsvers=3
115+
device: ":$PWD"

templates/drupal-7/docker-compose.yml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# itk-version: 1.0.1
1+
# itk-version: 2.0.0
22
version: "3"
33

44
networks:
@@ -37,7 +37,7 @@ services:
3737
- mariadb
3838
- memcached
3939
volumes:
40-
- .:/app:delegated
40+
- nfsApp:/app:delegated
4141

4242
nginx:
4343
image: nginx:latest
@@ -50,7 +50,7 @@ services:
5050
- '80'
5151
volumes:
5252
- ${PWD}/.docker/vhost.conf:/etc/nginx/conf.d/default.conf:ro
53-
- ./:/app:delegated
53+
- nfsApp:/app:delegated
5454
labels:
5555
- "traefik.enable=true"
5656
- "traefik.docker.network=frontend"
@@ -89,8 +89,18 @@ services:
8989
- drush
9090
volumes:
9191
- drush-cache:/root/.drush
92-
- ./:/app
92+
- nfsApp:/app
9393

94-
# Drush cache volume to persist cache between runs.
9594
volumes:
95+
# Drush cache volume to persist cache between runs.
9696
drush-cache:
97+
# Named volume requires that you have NFS shares enabled (performance boost on Macs).
98+
# Use `itkdev-docker-compose nfs:enable` to enable NFS shares. If you don't want to use it remove it from here and
99+
# change the volume mapping to use normal shares in the containers. See
100+
# https://sean-handley.medium.com/how-to-set-up-docker-for-mac-with-native-nfs-145151458adc
101+
nfsApp:
102+
driver: local
103+
driver_opts:
104+
type: nfs
105+
o: addr=host.docker.internal,rw,nolock,hard,nointr,nfsvers=3
106+
device: ":$PWD"

templates/drupal-8/docker-compose.yml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# itk-version: 1.0.1
1+
# itk-version: 2.0.0
22
version: "3"
33

44
networks:
@@ -38,7 +38,7 @@ services:
3838
- mariadb
3939
- memcached
4040
volumes:
41-
- .:/app:delegated
41+
- nfsApp:/app:delegated
4242
- drush-cache:/root/.drush
4343

4444
nginx:
@@ -52,7 +52,7 @@ services:
5252
- '80'
5353
volumes:
5454
- ${PWD}/.docker/vhost.conf:/etc/nginx/conf.d/default.conf:ro
55-
- ./:/app:delegated
55+
- nfsApp:/app:delegated
5656
labels:
5757
- "traefik.enable=true"
5858
- "traefik.docker.network=frontend"
@@ -80,3 +80,15 @@ services:
8080
- "traefik.docker.network=frontend"
8181
- "traefik.http.routers.${COMPOSE_PROJECT_NAME}Mailhog.rule=Host(`mailhog-${COMPOSE_DOMAIN}`)"
8282
- "traefik.http.services.${COMPOSE_PROJECT_NAME}Mailhog.loadbalancer.server.port=8025"
83+
84+
volumes:
85+
# Named volume requires that you have NFS shares enabled (performance boost on Macs).
86+
# Use `itkdev-docker-compose nfs:enable` to enable NFS shares. If you don't want to use it remove it from here and
87+
# change the volume mapping to use normal shares in the containers. See
88+
# https://sean-handley.medium.com/how-to-set-up-docker-for-mac-with-native-nfs-145151458adc
89+
nfsApp:
90+
driver: local
91+
driver_opts:
92+
type: nfs
93+
o: addr=host.docker.internal,rw,nolock,hard,nointr,nfsvers=3
94+
device: ":$PWD"

templates/drupal-9/docker-compose.yml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# itk-version: 1.0.1
1+
# itk-version: 2.0.0
22
version: "3"
33

44
networks:
@@ -38,7 +38,7 @@ services:
3838
- mariadb
3939
- memcached
4040
volumes:
41-
- .:/app:delegated
41+
- nfsApp:/app:delegated
4242
- drush-cache:/root/.drush
4343

4444
nginx:
@@ -52,7 +52,7 @@ services:
5252
- '80'
5353
volumes:
5454
- ${PWD}/.docker/vhost.conf:/etc/nginx/conf.d/default.conf:ro
55-
- ./:/app:delegated
55+
- nfsApp:/app:delegated
5656
labels:
5757
- "traefik.enable=true"
5858
- "traefik.docker.network=frontend"
@@ -80,3 +80,15 @@ services:
8080
- "traefik.docker.network=frontend"
8181
- "traefik.http.routers.${COMPOSE_PROJECT_NAME}Mailhog.rule=Host(`mailhog-${COMPOSE_DOMAIN}`)"
8282
- "traefik.http.services.${COMPOSE_PROJECT_NAME}Mailhog.loadbalancer.server.port=8025"
83+
84+
volumes:
85+
# Named volume requires that you have NFS shares enabled (performance boost on Macs).
86+
# Use `itkdev-docker-compose nfs:enable` to enable NFS shares. If you don't want to use it remove it from here and
87+
# change the volume mapping to use normal shares in the containers. See
88+
# https://sean-handley.medium.com/how-to-set-up-docker-for-mac-with-native-nfs-145151458adc
89+
nfsApp:
90+
driver: local
91+
driver_opts:
92+
type: nfs
93+
o: addr=host.docker.internal,rw,nolock,hard,nointr,nfsvers=3
94+
device: ":$PWD"

0 commit comments

Comments
 (0)