feat(docker): add support for pgid and puid env variables (#1759)
This commit is contained in:
42
Dockerfile
42
Dockerfile
@@ -30,42 +30,36 @@ RUN apk add --no-cache redis nginx bash gettext su-exec openssl
|
|||||||
RUN mkdir /appdata
|
RUN mkdir /appdata
|
||||||
VOLUME /appdata
|
VOLUME /appdata
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
RUN addgroup --system --gid 1001 nodejs
|
|
||||||
RUN adduser --system --uid 1001 nextjs
|
|
||||||
|
|
||||||
# Enable homarr cli
|
# Enable homarr cli
|
||||||
COPY --from=builder --chown=nextjs:nodejs /app/packages/cli/cli.cjs /app/apps/cli/cli.cjs
|
COPY --from=builder /app/packages/cli/cli.cjs /app/apps/cli/cli.cjs
|
||||||
RUN echo $'#!/bin/bash\ncd /app/apps/cli && node ./cli.cjs "$@"' > /usr/bin/homarr
|
RUN echo $'#!/bin/bash\ncd /app/apps/cli && node ./cli.cjs "$@"' > /usr/bin/homarr
|
||||||
RUN chmod +x /usr/bin/homarr
|
RUN chmod +x /usr/bin/homarr
|
||||||
|
|
||||||
# Don't run production as root
|
# Don't run production as root
|
||||||
RUN mkdir -p /var/cache/nginx && chown -R nextjs:nodejs /var/cache/nginx && \
|
RUN mkdir -p /var/cache/nginx && \
|
||||||
mkdir -p /var/log/nginx && chown -R nextjs:nodejs /var/log/nginx && \
|
mkdir -p /var/log/nginx && \
|
||||||
mkdir -p /var/lib/nginx && chown -R nextjs:nodejs /var/lib/nginx && \
|
mkdir -p /var/lib/nginx && \
|
||||||
touch /run/nginx/nginx.pid && chown -R nextjs:nodejs /run/nginx/nginx.pid && \
|
touch /run/nginx/nginx.pid && \
|
||||||
mkdir -p /etc/nginx/templates /etc/nginx/ssl/certs && chown -R nextjs:nodejs /etc/nginx
|
mkdir -p /etc/nginx/templates /etc/nginx/ssl/certs
|
||||||
|
|
||||||
COPY --from=builder /app/apps/nextjs/next.config.mjs .
|
COPY --from=builder /app/apps/nextjs/next.config.mjs .
|
||||||
COPY --from=builder /app/apps/nextjs/package.json .
|
COPY --from=builder /app/apps/nextjs/package.json .
|
||||||
|
|
||||||
COPY --from=builder --chown=nextjs:nodejs /app/apps/tasks/tasks.cjs ./apps/tasks/tasks.cjs
|
COPY --from=builder /app/apps/tasks/tasks.cjs ./apps/tasks/tasks.cjs
|
||||||
COPY --from=builder --chown=nextjs:nodejs /app/apps/websocket/wssServer.cjs ./apps/websocket/wssServer.cjs
|
COPY --from=builder /app/apps/websocket/wssServer.cjs ./apps/websocket/wssServer.cjs
|
||||||
COPY --from=builder --chown=nextjs:nodejs /app/node_modules/better-sqlite3/build/Release/better_sqlite3.node /app/build/better_sqlite3.node
|
COPY --from=builder /app/node_modules/better-sqlite3/build/Release/better_sqlite3.node /app/build/better_sqlite3.node
|
||||||
|
|
||||||
COPY --from=builder --chown=nextjs:nodejs /app/packages/db/migrations ./db/migrations
|
COPY --from=builder /app/packages/db/migrations ./db/migrations
|
||||||
|
|
||||||
# Automatically leverage output traces to reduce image size
|
# Automatically leverage output traces to reduce image size
|
||||||
# https://nextjs.org/docs/advanced-features/output-file-tracing
|
# https://nextjs.org/docs/advanced-features/output-file-tracing
|
||||||
COPY --from=builder --chown=nextjs:nodejs /app/apps/nextjs/.next/standalone ./
|
COPY --from=builder /app/apps/nextjs/.next/standalone ./
|
||||||
COPY --from=builder --chown=nextjs:nodejs /app/apps/nextjs/.next/static ./apps/nextjs/.next/static
|
COPY --from=builder /app/apps/nextjs/.next/static ./apps/nextjs/.next/static
|
||||||
COPY --from=builder --chown=nextjs:nodejs /app/apps/nextjs/public ./apps/nextjs/public
|
COPY --from=builder /app/apps/nextjs/public ./apps/nextjs/public
|
||||||
COPY --chown=nextjs:nodejs scripts/run.sh ./run.sh
|
COPY scripts/run.sh ./run.sh
|
||||||
COPY scripts/entrypoint.sh ./entrypoint.sh
|
COPY --chmod=777 scripts/entrypoint.sh ./entrypoint.sh
|
||||||
RUN chmod +x ./entrypoint.sh
|
COPY packages/redis/redis.conf /app/redis.conf
|
||||||
COPY --chown=nextjs:nodejs packages/redis/redis.conf /app/redis.conf
|
COPY nginx.conf /etc/nginx/templates/nginx.conf
|
||||||
COPY --chown=nextjs:nodejs nginx.conf /etc/nginx/templates/nginx.conf
|
|
||||||
|
|
||||||
|
|
||||||
ENV DB_URL='/appdata/db/db.sqlite'
|
ENV DB_URL='/appdata/db/db.sqlite'
|
||||||
@@ -74,4 +68,4 @@ ENV DB_DRIVER='better-sqlite3'
|
|||||||
ENV AUTH_PROVIDERS='credentials'
|
ENV AUTH_PROVIDERS='credentials'
|
||||||
|
|
||||||
ENTRYPOINT [ "/app/entrypoint.sh" ]
|
ENTRYPOINT [ "/app/entrypoint.sh" ]
|
||||||
CMD ["sh", "run.sh"]
|
CMD ["sh", "run.sh"]
|
||||||
@@ -1,10 +1,25 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# Creating folders in volume
|
export PUID=${PUID:-0}
|
||||||
mkdir -p /appdata/db
|
export PGID=${PGID:-0}
|
||||||
mkdir -p /appdata/redis
|
|
||||||
|
|
||||||
chown -R nextjs:nodejs /appdata
|
echo "Starting with UID='$PUID', GID='$PGID'"
|
||||||
|
|
||||||
su-exec 1001:1001 "$@"
|
if [ "${PUID}" != "0" ] || [ "${PGID}" != "0" ]; then
|
||||||
|
# The below command will change the owner of all files in the /app directory (except node_modules) to the new UID and GID
|
||||||
|
echo "Changing owner to $PUID:$PGID, this will take about 10 seconds..."
|
||||||
|
find . -name 'node_modules' -prune -o -mindepth 1 -maxdepth 1 -exec chown -R $PUID:$PGID {} +
|
||||||
|
chown -R $PUID:$PGID /var/cache/nginx
|
||||||
|
chown -R $PUID:$PGID /var/log/nginx
|
||||||
|
chown -R $PUID:$PGID /var/lib/nginx
|
||||||
|
chown -R $PUID:$PGID /run/nginx/nginx.pid
|
||||||
|
chown -R $PUID:$PGID /etc/nginx
|
||||||
|
echo "Changing owner to $PUID:$PGID, done."
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${PUID}" != "0" ]; then
|
||||||
|
su-exec $PUID:$PGID "$@"
|
||||||
|
else
|
||||||
|
exec "$@"
|
||||||
|
fi
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
# Create sub directories in volume
|
||||||
|
mkdir -p /appdata/db
|
||||||
|
mkdir -p /appdata/redis
|
||||||
|
|
||||||
# Run migrations
|
# Run migrations
|
||||||
if [ $DB_MIGRATIONS_DISABLED = "true" ]; then
|
if [ $DB_MIGRATIONS_DISABLED = "true" ]; then
|
||||||
echo "DB migrations are disabled, skipping"
|
echo "DB migrations are disabled, skipping"
|
||||||
|
|||||||
Reference in New Issue
Block a user