node container permissions fixes

This commit is contained in:
David Kennedy 2024-12-02 12:42:45 -05:00
parent 28b964cc47
commit 9cbd6d0223
No known key found for this signature in database
GPG key ID: 6528A5386E66B96B
3 changed files with 20 additions and 3 deletions

View file

@ -85,6 +85,7 @@ services:
volumes: volumes:
- .:/app - .:/app
working_dir: /app working_dir: /app
entrypoint: /app/node_entrypoint.sh
stdin_open: true stdin_open: true
tty: true tty: true
command: ./run_node_watch.sh command: ./run_node_watch.sh

View file

@ -1,9 +1,13 @@
FROM docker.io/cimg/node:current-browsers FROM docker.io/cimg/node:current-browsers
WORKDIR /app WORKDIR /app
# Install gosu
USER root
RUN apt-get update && \
apt-get install -y gosu && \
rm -rf /var/lib/apt/lists/*
# Install app dependencies # Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied # A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+) # where available (npm@5+)
COPY --chown=circleci:circleci package*.json ./ COPY --chown=circleci:circleci package*.json ./
RUN npm install

12
src/node_entrypoint.sh Executable file
View file

@ -0,0 +1,12 @@
#!/bin/bash
# Get UID and GID of the /app directory owner
HOST_UID=$(stat -c '%u' /app)
HOST_GID=$(stat -c '%g' /app)
# Update circleci user's UID and GID to match the host
echo "Updating circleci user and group to match host UID:GID ($HOST_UID:$HOST_GID)"
sudo groupmod -g "$HOST_GID" circleci
sudo usermod -u "$HOST_UID" circleci
exec gosu circleci "$@"