Refactored Dockerfile #1375

Merged
konrad merged 6 commits from vlasov-y/api:main into main 2023-01-31 16:16:22 +00:00
2 changed files with 23 additions and 9 deletions
Showing only changes of commit eb9b1b47fc - Show all commits

View File

@ -25,16 +25,15 @@ RUN mage build:clean && \
# because of this, the container would not start when I compiled the image without cgo.
FROM alpine:3.16 AS runner
LABEL maintainer="maintainers@vikunja.io"
WORKDIR /app/vikunja/
WORKDIR /app/vikunja
ENTRYPOINT [ "/sbin/tini", "-g", "--", "/entrypoint.sh" ]
ENTRYPOINT [ "/app/vikunja/vikunja" ]
ENV VIKUNJA_SERVICE_ROOTPATH=/app/vikunja/
ENV VIKUNJA_PUID 1000
ENV VIKUNJA_PGID 1000

Can you rename these to just PUID and PGID? As documented here: https://vikunja.io/docs/install-backend/#setting-user-and-group-id-of-the-user-running-vikunja

Can you rename these to just `PUID` and `PGID`? As documented here: https://vikunja.io/docs/install-backend/#setting-user-and-group-id-of-the-user-running-vikunja

Okay

Okay

Done, please check

Done, please check
RUN apk --update --no-cache add tzdata && \
addgroup -g 1000 vikunja && \
adduser -s /bin/sh -D -G vikunja -u 1000 vikunja -h /app/vikunja -H && \
mkdir files && \
chown vikunja:vikunja files
RUN apk --update --no-cache add tzdata tini

The uid and gid of the Vikunja user has to be adjustable at runtime to avoid permission problems with the sqlite db (if used) or file uploads. That's what the script was used for.

The uid and gid of the Vikunja user has to be adjustable at runtime to avoid permission problems with the sqlite db (if used) or file uploads. That's what the script was used for.

a, okay, will do

a, okay, will do

Done. I have created an entrypoint script back and run it using tini. Now user creation can be controlled with env variables, which are set to 1000:1000 by default, but can be overridden during the runtime

Done. I have created an entrypoint script back and run it using [tini](https://github.com/krallin/tini). Now user creation can be controlled with env variables, which are set to 1000:1000 by default, but can be overridden during the runtime
COPY docker/entrypoint.sh /entrypoint.sh
RUN chmod 0755 /entrypoint.sh && mkdir files
COPY --from=builder --chown=vikunja:vikunja /build/vikunja-* vikunja
USER vikunja
COPY --from=builder /build/vikunja-* vikunja

15
docker/entrypoint.sh Normal file
View File

@ -0,0 +1,15 @@
#!/usr/bin/env sh
set -e
if [ -n "$VIKUNJA_PUID" ] && [ "$VIKUNJA_PUID" -ne 0 ] && \
[ -n "$VIKUNJA_PGID" ] && [ "$VIKUNJA_PGID" -ne 0 ] ; then
echo "info: creating the new user vikunja with $VIKUNJA_PUID:$VIKUNJA_PGID"
addgroup -g "$VIKUNJA_PGID" vikunja
adduser -s /bin/sh -D -G vikunja -u "$VIKUNJA_PUID" vikunja -h /app/vikunja -H
chown -R vikunja:vikunja ./
su -pc /app/vikunja/vikunja - vikunja "$@"
else
echo "info: creation of non-root user is skipped"
exec /app/vikunja/vikunja "$@"
fi