Skip to content

Commit 4bec917

Browse files
Modify uid/gid at run-time
1 parent d421224 commit 4bec917

File tree

5 files changed

+25
-7
lines changed

5 files changed

+25
-7
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ jobs:
163163
run: rake ${{ matrix.entry.prerelease }}[${{ inputs.prerel_name }}]
164164
if: ${{ inputs.prerel_name != '' && matrix.entry.prerelease != '' }}
165165
- name: rake ${{ matrix.entry.task }}
166-
run: docker run -v "$GITHUB_WORKSPACE:/home/me/build" -w /home/me/build -e "GNUMAKEFLAGS=-j$((1 + $(nproc --all)))" sha256:$BUILDER_IMAGE_ID rake ${{ matrix.entry.task }}
166+
run: docker run -v "$GITHUB_WORKSPACE:/home/me/build" -w /home/me/build -e "RUBYWASM_UID=$(id -u)" -e "RUBYWASM_GID=$(id -g)" -e "GNUMAKEFLAGS=-j$((1 + $(nproc --all)))" sha256:$BUILDER_IMAGE_ID rake ${{ matrix.entry.task }}
167167
- name: rake ${{ matrix.entry.test }}
168168
run: rake ${{ matrix.entry.test }}
169169
if: ${{ matrix.entry.test != '' }}

builders/wasm32-unknown-emscripten/Dockerfile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ FROM emscripten/emsdk:2.0.13
22

33
RUN set -eux; \
44
apt-get update; \
5-
apt-get install ruby bison make autoconf git curl build-essential libyaml-dev zlib1g-dev -y; \
5+
apt-get install ruby bison make autoconf git curl build-essential libyaml-dev zlib1g-dev gosu -y; \
66
curl -fsSL https://deb.nodesource.com/setup_16.x | bash -; \
77
apt-get install nodejs -y; \
88
apt-get clean; \
99
rm -r /var/lib/apt/lists/*
1010

11+
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
12+
RUN chmod +x /usr/local/bin/entrypoint.sh
13+
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
1114
# Build with non-root user because `@npmcli/promise-spawn` sets `uid` and `gid` to cwd owner when the current user is root.
1215
# This permission demotion results in EACCES error at reading `$HOME/.node_modules` in `resolve` package, which is used by `@rollup/plugin-node-resolve`.
1316
# * https://github.com/npm/cli/blob/32336f6efe06bd52de1dc67c0f812d4705533ef2/node_modules/%40npmcli/promise-spawn/lib/index.js#L13
14-
RUN groupadd -r me && useradd -g me me && mkdir -p /home/me && chown me:me /home/me
15-
USER me
17+
RUN adduser --disabled-password --gecos '' me
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
[ ! -z "${RUBYWASM_UID+x}" ] && usermod --uid "$RUBYWASM_UID" --non-unique me
6+
[ ! -z "${RUBYWASM_GID+x}" ] && groupmod --gid "$RUBYWASM_GID" me
7+
exec gosu me "$@"

builders/wasm32-unknown-wasi/Dockerfile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ ENV WASI_SDK_PATH="/opt/wasi-sdk"
1010

1111
RUN set -eux; \
1212
apt-get update; \
13-
apt-get install ruby bison make autoconf git curl build-essential libyaml-dev zlib1g-dev -y; \
13+
apt-get install ruby bison make autoconf git curl build-essential libyaml-dev zlib1g-dev gosu -y; \
1414
curl -fsSL https://deb.nodesource.com/setup_16.x | bash -; \
1515
apt-get install nodejs -y; \
1616
apt-get clean; \
@@ -47,8 +47,10 @@ RUN set -eux pipefail; \
4747
unzip wasi-preset-args-x86_64-unknown-linux-gnu.zip; \
4848
mv wasi-preset-args /usr/local/bin/wasi-preset-args
4949

50+
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
51+
RUN chmod +x /usr/local/bin/entrypoint.sh
52+
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
5053
# Build with non-root user because `@npmcli/promise-spawn` sets `uid` and `gid` to cwd owner when the current user is root.
5154
# This permission demotion results in EACCES error at reading `$HOME/.node_modules` in `resolve` package, which is used by `@rollup/plugin-node-resolve`.
5255
# * https://github.com/npm/cli/blob/32336f6efe06bd52de1dc67c0f812d4705533ef2/node_modules/%40npmcli/promise-spawn/lib/index.js#L13
53-
RUN groupadd -r me && useradd -g me me && mkdir -p /home/me && chown me:me /home/me
54-
USER me
56+
RUN adduser --disabled-password --gecos '' me
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
[ ! -z "${RUBYWASM_UID+x}" ] && usermod --uid "$RUBYWASM_UID" --non-unique me
6+
[ ! -z "${RUBYWASM_GID+x}" ] && groupmod --gid "$RUBYWASM_GID" me
7+
exec gosu me "$@"

0 commit comments

Comments
 (0)