Skip to content

Commit 3dba622

Browse files
committed
add ability to override UID and GID at runtime
1 parent 60819e1 commit 3dba622

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

Dockerfile

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,35 @@ WORKDIR /build
44
COPY go.mod go.sum ./
55
RUN go mod download
66
COPY . .
7-
87
ARG SMALLWEB_VERSION=dev
98
RUN go build -ldflags="-s -w -X github.com/pomdtr/smallweb/build.Version=${SMALLWEB_VERSION}" -o smallweb
109

1110
FROM debian:bookworm-slim
1211
COPY --from=builder /build/smallweb /usr/local/bin/smallweb
1312

14-
RUN apt update && apt install -y git unzip curl && rm -rf /var/lib/apt/lists/*
13+
# Install required packages
14+
RUN apt update && apt install -y git unzip curl gosu && rm -rf /var/lib/apt/lists/*
1515

16+
# Install Deno
1617
ARG DENO_VERSION=v2.2.2
1718
RUN curl -fsSL https://deno.land/install.sh | DENO_INSTALL=/usr/local/deno sh -s "$DENO_VERSION"
1819
ENV PATH="/usr/local/deno/bin:$PATH"
1920

21+
# Set up default user with ID 1000
2022
ARG UID=1000
2123
ARG GID=1000
22-
RUN groupadd -g $GID smallweb && useradd -m -s /bin/bash -u $UID -g $GID smallweb
23-
RUN mkdir /smallweb && chown smallweb:smallweb /smallweb
24+
RUN groupadd -g $GID smallweb && useradd -m -s /bin/bash -u $GID -g $1000 smallweb
25+
26+
# Create app directory
27+
RUN mkdir -p /smallweb && chown smallweb:smallweb /smallweb
28+
29+
# Add entrypoint script
30+
COPY entrypoint.sh /entrypoint.sh
31+
RUN chmod +x /entrypoint.sh
2432

25-
USER smallweb
2633
VOLUME /smallweb
2734
WORKDIR /smallweb
2835
EXPOSE 7777 2222
29-
ENTRYPOINT ["/usr/local/bin/smallweb"]
30-
CMD [ "up", "--enable-crons", "--addr", ":7777", "--ssh-addr", ":2222"]
36+
37+
ENTRYPOINT ["/entrypoint.sh"]
38+
CMD ["up", "--enable-crons", "--addr", ":7777", "--ssh-addr", ":2222"]

entrypoint.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Get current UID/GID from environment or use defaults
5+
USER_ID=${PUID:-1000}
6+
GROUP_ID=${PGID:-1000}
7+
8+
echo "Starting with UID: $USER_ID, GID: $GROUP_ID"
9+
10+
# Update the user to match desired UID/GID if needed
11+
if [ "$USER_ID" != "1000" ] || [ "$GROUP_ID" != "1000" ]; then
12+
echo "Updating user 'smallweb' with new UID:GID -> $USER_ID:$GROUP_ID"
13+
groupmod -g "$GROUP_ID" smallweb
14+
usermod -u "$USER_ID" -g "$GROUP_ID" smallweb
15+
fi
16+
17+
# Ensure correct ownership of the application directory
18+
chown -R smallweb:smallweb /smallweb
19+
20+
# Execute the command as the smallweb user
21+
exec gosu smallweb:smallweb /usr/local/bin/smallweb "$@"

0 commit comments

Comments
 (0)