Skip to content

Commit a60a5b4

Browse files
committed
set pid and gid as env
Signed-off-by: Jayadeep KM <kmjayadeep@gmail.com>
1 parent 057ec91 commit a60a5b4

2 files changed

Lines changed: 35 additions & 4 deletions

File tree

Dockerfile

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,30 @@ COPY --from=builder /build/taskwarrior-api .
4444
# Copy web templates
4545
COPY --from=builder /build/web ./web
4646

47+
# Copy entrypoint script
48+
COPY entrypoint.sh /app/entrypoint.sh
49+
RUN chmod +x /app/entrypoint.sh
50+
51+
# Create a default non-root user (UID/GID will be modified at runtime)
52+
RUN groupadd -g 1000 appuser && \
53+
useradd -u 1000 -g 1000 -m -s /bin/bash appuser
54+
4755
# Create directory for Taskwarrior data and initialize config
48-
RUN mkdir -p /root/.task && \
49-
echo "data.location=/root/.task" > /root/.taskrc && \
50-
echo "confirmation=no" >> /root/.taskrc
56+
RUN mkdir -p /home/appuser/.task && \
57+
echo "data.location=/home/appuser/.task" > /home/appuser/.taskrc && \
58+
echo "confirmation=no" >> /home/appuser/.taskrc && \
59+
chown -R appuser:appuser /home/appuser/.task /home/appuser/.taskrc
60+
61+
# Change ownership of app directory
62+
RUN chown -R appuser:appuser /app
5163

5264
# Expose port
5365
EXPOSE 8080
5466

67+
# Set environment variables with defaults
68+
ENV PUID=1000
69+
ENV PGID=1000
70+
5571
LABEL org.opencontainers.image.source "https://github.com/dotbinio/taskwarrior-api"
5672

57-
CMD ["./taskwarrior-api"]
73+
ENTRYPOINT ["/app/entrypoint.sh"]

entrypoint.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
# Default to UID/GID 1000 if not specified
4+
PUID=${PUID:-1000}
5+
PGID=${PGID:-1000}
6+
7+
echo "Starting with PUID=${PUID} and PGID=${PGID}"
8+
9+
# Modify the appuser UID and GID to match the requested values
10+
groupmod -o -g "${PGID}" appuser
11+
usermod -o -u "${PUID}" appuser
12+
13+
# Execute the API as the appuser
14+
exec su appuser -c "./taskwarrior-api"
15+

0 commit comments

Comments
 (0)