From e3e96fa75e31de1c46f1634951a7b4c5e1b2454b Mon Sep 17 00:00:00 2001 From: David Boreham Date: Thu, 23 Feb 2023 20:50:20 -0700 Subject: [PATCH] Work around docker uid/gid insanity Former-commit-id: b84a28592df56104fc25ab6337ab5c53bfd658bd --- app/build_npms.py | 6 +++++- .../container-build/cerc-builder-js/Dockerfile | 1 + .../cerc-builder-js/entrypoint.sh | 1 + .../cerc-builder-js/fixup-for-uid.sh | 18 ++++++++++++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100755 app/data/container-build/cerc-builder-js/fixup-for-uid.sh diff --git a/app/build_npms.py b/app/build_npms.py index 83f87ede..877916be 100644 --- a/app/build_npms.py +++ b/app/build_npms.py @@ -116,7 +116,11 @@ def command(ctx, include, exclude): if not dry_run: if verbose: print(f"Executing: {build_command}") - envs = {"CERC_NPM_AUTH_TOKEN": npm_registry_url_token} | ({"CERC_SCRIPT_DEBUG": "true"} if debug else {}) + # Originally we used the PEP 584 merge operator: + # envs = {"CERC_NPM_AUTH_TOKEN": npm_registry_url_token} | ({"CERC_SCRIPT_DEBUG": "true"} if debug else {}) + # but that isn't available in Python 3.8 (default in Ubuntu 20) so for now we use dict.update: + envs = {"CERC_NPM_AUTH_TOKEN": npm_registry_url_token} + envs.update({"CERC_SCRIPT_DEBUG": "true"} if debug else {}) try: docker.run(builder_js_image_name, remove=True, diff --git a/app/data/container-build/cerc-builder-js/Dockerfile b/app/data/container-build/cerc-builder-js/Dockerfile index 9f460375..9a1cf680 100644 --- a/app/data/container-build/cerc-builder-js/Dockerfile +++ b/app/data/container-build/cerc-builder-js/Dockerfile @@ -39,6 +39,7 @@ RUN mkdir /scripts COPY build-npm-package.sh /scripts COPY yarn-local-registry-fixup.sh /scripts COPY build-npm-package-local-dependencies.sh /scripts +COPY fixup-for-uid.sh /scripts ENV PATH="${PATH}:/scripts" COPY entrypoint.sh . diff --git a/app/data/container-build/cerc-builder-js/entrypoint.sh b/app/data/container-build/cerc-builder-js/entrypoint.sh index 311cb8cb..cfbce454 100755 --- a/app/data/container-build/cerc-builder-js/entrypoint.sh +++ b/app/data/container-build/cerc-builder-js/entrypoint.sh @@ -1,2 +1,3 @@ #!/bin/sh +/scripts/fixup-for-uid.sh exec "$@" diff --git a/app/data/container-build/cerc-builder-js/fixup-for-uid.sh b/app/data/container-build/cerc-builder-js/fixup-for-uid.sh new file mode 100755 index 00000000..04089d08 --- /dev/null +++ b/app/data/container-build/cerc-builder-js/fixup-for-uid.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# Make the container usable for uid/gid != 1000 +if [[ -n "$CERC_SCRIPT_DEBUG" ]]; then + set -x +fi +current_uid=$(id -u) +current_gid=$(id -g) +user_name="hostuser" +# First check the current uid. If == 1000 then exit, nothing needed because that uid already exists +if [[ ${current_uid} == 1000 ]]; then + exit 0 +fi +# Also exit for root +if [[ ${current_uid} == 0 ]]; then + exit 0 +fi +# Create the user with home dir +useradd -m -d /home/${user_name} -s /bin/bash -g ${current_gid} -u ${current_uid} ${user_name}