Skip to content

Commit fabf738

Browse files
committed
Make persistent storage work smoothly for podman/docker.
1 parent 7b1c664 commit fabf738

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

Containerfile

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,16 @@ RUN set -ex && \
8181

8282
FROM docker.io/python:${PYTHON_VERSION}-slim AS app_runtime
8383
ARG PYTHON_VERSION=3.12
84+
ARG APP_UID=999
8485

8586
# Add the application virtualenv to search path.
8687
ENV PATH=/app/bin:$PATH
8788

88-
# Don't run your app as root.
89+
# We will run the app as a user 'app' with a stable uid that is
90+
# configurable via an ARG.
8991
RUN set -ex && \
90-
groupadd -r app && \
91-
useradd -r -d /app -g app -N app
92+
groupadd -r -g ${APP_UID} app && \
93+
useradd -r -d /app -g app -u ${APP_UID} -N app
9294

9395
# See <https://hynek.me/articles/docker-signals/>.
9496
STOPSIGNAL SIGINT
@@ -100,7 +102,7 @@ apt-get update -qy && \
100102
apt-get install -qyy \
101103
-o APT::Install-Recommends=false \
102104
-o APT::Install-Suggests=false \
103-
curl && \
105+
curl gosu && \
104106
apt-get clean && \
105107
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
106108

@@ -129,4 +131,13 @@ python -Ic 'import tiled'
129131

130132
EXPOSE 8000
131133

134+
# Following the example of PG, Redis, and other services that write to a
135+
# storage volume, run the entrypoint as root. As root, ensure that the
136+
# /storage volume is writable by the app user. Then use gosu to switch to
137+
# the app user.
138+
USER root
139+
COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
140+
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
141+
ENTRYPOINT ["docker-entrypoint.sh"]
142+
132143
CMD ["tiled", "serve", "config", "--host", "0.0.0.0", "--port", "8000", "--scalable"]

docker-entrypoint.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
# docker-entrypoint.sh
3+
set -e
4+
5+
# If storage dir exists but isn't owned by app, fix it
6+
if [ "$(stat -c %u /storage)" != "$(id -u app)" ]; then
7+
chown -R app:app /storage
8+
fi
9+
10+
exec gosu app "$@"

0 commit comments

Comments
 (0)