-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: get host uid:gid and use in docker
- Grab the uid:gid of the repo root in docker - Use that for the node user we run as in the container - Check owner of all volume mounts, if not OK, fix them - this should avoid permission errors on linux - provide bin/fix-volumes to fix owner issues ad hoc Signed-off-by: Peter Lyons <pete@reactioncommerce.com>
- Loading branch information
1 parent
8ac29e4
commit 4b8b9fc
Showing
5 changed files
with
93 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Please Use Google Shell Style: https://google.github.io/styleguide/shell.xml | ||
|
||
# ---- Start unofficial bash strict mode boilerplate | ||
# http://redsymbol.net/articles/unofficial-bash-strict-mode/ | ||
set -o errexit # always exit on error | ||
set -o errtrace # trap errors in functions as well | ||
set -o pipefail # don't ignore exit codes when piping output | ||
set -o posix # more strict failures in subshells | ||
# set -x # enable debugging | ||
|
||
IFS=$'\n\t' | ||
# ---- End unofficial bash strict mode boilerplate | ||
|
||
cd "$(dirname "${BASH_SOURCE[0]}")/.." | ||
# change the node user's uid:gid to match the repo root directory's | ||
usermod --uid "$(stat -c "%u" .)" --non-unique node |& grep -v "no changes" || true | ||
./.reaction/fix-volumes.sh | ||
command=("./bin/start") | ||
if [[ $# -gt 0 ]]; then | ||
command=($@) | ||
fi | ||
unset IFS | ||
exec su-exec node ${command[*]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Please Use Google Shell Style: https://google.github.io/styleguide/shell.xml | ||
|
||
# ---- Start unofficial bash strict mode boilerplate | ||
# http://redsymbol.net/articles/unofficial-bash-strict-mode/ | ||
set -o errexit # always exit on error | ||
set -o errtrace # trap errors in functions as well | ||
set -o pipefail # don't ignore exit codes when piping output | ||
set -o posix # more strict failures in subshells | ||
# set -x # enable debugging | ||
|
||
IFS=$'\n\t' | ||
# ---- End unofficial bash strict mode boilerplate | ||
|
||
cd "$(dirname "${BASH_SOURCE[0]}")/.." | ||
owner=$(stat -c "%u:%g" .) | ||
volumes=( | ||
../node_modules | ||
./node_modules | ||
./build | ||
/home/node/.cache/yarn | ||
/home/node/.cache/yarn-offline-mirror | ||
) | ||
for dir in ${volumes[*]}; do | ||
mkdir -p "${dir}" | ||
old_owner=$(stat -c "%u:%g" "${dir}") | ||
if [[ "$1" != "--force" && "${old_owner}" == "${owner}" ]]; then | ||
continue | ||
fi | ||
printf "Fixing volume ${dir} (before=${old_owner} after=${owner})…" | ||
chown -R "${owner}" "${dir}" | ||
chmod -R a+r,u+rw "${dir}" | ||
echo "✓" | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Please Use Google Shell Style: https://google.github.io/styleguide/shell.xml | ||
|
||
# ---- Start unofficial bash strict mode boilerplate | ||
# http://redsymbol.net/articles/unofficial-bash-strict-mode/ | ||
set -o errexit # always exit on error | ||
set -o errtrace # trap errors in functions as well | ||
set -o pipefail # don't ignore exit codes when piping output | ||
set -o posix # more strict failures in subshells | ||
# set -x # enable debugging | ||
|
||
IFS=$'\n\t' | ||
# ---- End unofficial bash strict mode boilerplate | ||
cd "$(dirname "${BASH_SOURCE[0]}")/.." | ||
docker-compose run --entrypoint=./.reaction/fix-volumes.sh web --force |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters