Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added GID and UID env vars to the Dockerfile #228

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,28 @@ ENV OTEL_LOGS_EXPORTER="none"
ENV STORAGE_DIR /app/data
ENV LOG_DIR /app/log

ENV UID 1001
ENV GID 1001

WORKDIR /app

RUN adduser -u 1001 --disabled-password --gecos "" appuser
RUN addgroup --gid "$GID" appgroup && \
adduser --uid "$UID" --ingroup appgroup --disabled-password --gecos "" appuser

COPY --from=builder --chown=appuser:appuser /build/ .
RUN chown -R appuser:appuser /app
COPY --from=builder --chown=appuser:appgroup /build/ .
RUN chown -R appuser:appgroup /app

COPY --chown=appuser:appuser docker-entrypoint.sh /usr/local/bin/
COPY --chown=appuser:appgroup docker-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-entrypoint.sh

RUN mkdir -p "$LOG_DIR" && \
chown -R appuser:appgroup "$LOG_DIR" && \
mkdir -p "$STORAGE_DIR" && \
chown -R appuser:appgroup "$STORAGE_DIR"

HEALTHCHECK --start-period=30s --interval=1m --timeout=3s \
CMD wget --no-verbose --spider --tries=1 http://localhost:8080/health || exit 1

EXPOSE 8080 9464

RUN mkdir -p "$LOG_DIR" && \
chown -R appuser:appuser "$LOG_DIR" && \
mkdir -p "$STORAGE_DIR" && \
chown -R appuser:appuser "$STORAGE_DIR"

ENTRYPOINT ["docker-entrypoint.sh"]
20 changes: 16 additions & 4 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,24 @@ set -Ee
if [ $# -lt 1 ]; then

# If the container is run under the root user, update the ownership of directories
# that may be mounted as volumes to ensure 'appuser' has the necessary access rights.
# that may be mounted as volumes to ensure the specified user:group
# has the necessary access rights.
if [ "$(id -u)" = '0' ]; then
find "$LOG_DIR" ! -user appuser -exec chown appuser '{}' +
find "$STORAGE_DIR" ! -user appuser -exec chown appuser '{}' +

exec su-exec appuser "/app/bin/aidial-core" "$@"
if [ -n "$PUID" ]; then
export UID="$PUID"
fi

if [ -n "$PGID" ]; then
export GID="$PGID"
fi

echo "Changing the ownership of /app, $LOG_DIR and $STORAGE_DIR to $UID:$GID"
find "/app" ! -user $UID -exec chown $UID:$GID '{}' +
find "$LOG_DIR" ! -user $UID -exec chown $UID:$GID '{}' +
find "$STORAGE_DIR" ! -user $UID -exec chown $UID:$GID '{}' +

exec su-exec $UID:$GID "/app/bin/aidial-core" "$@"
fi

exec "/app/bin/aidial-core" "$@"
Expand Down
Loading