Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions web/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
docs/

.dockerignore
.gitignore
.prettierignore
.prettierrc
Dockerfile
CLAUDE.md
crowdin.yml
README.md
60 changes: 34 additions & 26 deletions web/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,45 +28,64 @@ RUN yarn build:cast
RUN yarn build:share
RUN yarn build:embed

FROM nginx
FROM nginxinc/nginx-unprivileged:1.29-alpine-otel

WORKDIR /out
USER root

COPY --from=builder /build/web/apps/photos/out /out/photos
COPY --from=builder /build/web/apps/accounts/out /out/accounts
COPY --from=builder /build/web/apps/auth/out /out/auth
COPY --from=builder /build/web/apps/cast/out /out/cast
COPY --from=builder /build/web/apps/share/out /out/share
COPY --from=builder /build/web/apps/embed/out /out/embed
COPY --chmod=755 <<EOF /docker-entrypoint.d/90-replace-ente-env.sh
sed -i'' "s#ENTE_API_ORIGIN_PLACEHOLDER#\$ENTE_API_ORIGIN#g" /etc/nginx/conf.d/default.conf
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P0 Badge Make default.conf writable before the startup sed

After USER nginx, the image starts under the unprivileged account and the upstream entrypoint executes 90-replace-ente-env.sh before nginx. This sed -i edits /etc/nginx/conf.d/default.conf, but that file is created by COPY without --chown, so it stays root-owned (and its parent directory is not writable either). The first command in the script will therefore fail with Permission denied, causing the entrypoint to exit before nginx starts, which makes the new web image unusable with its default startup path.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a misunderstanding, this step is ONLY CREATING the script that will alter the /etc/nginx/conf.d/default.conf file. The file /etc/nginx/conf.d/default.conf itself is created in line 54 and following AFTER the USER nginx directive in line 45. So the user nginx is perfectly able to change the file /etc/nginx/conf.d/default.conf when the container is starting

find /usr/share/nginx/html -name '*.js' |
xargs sed -i'' "s#ENTE_API_ORIGIN_PLACEHOLDER#\$ENTE_API_ORIGIN#g"
find /usr/share/nginx/html/photos -name '*.js' |
xargs sed -i'' "s#ENTE_ALBUMS_ORIGIN_PLACEHOLDER#\$ENTE_ALBUMS_ORIGIN#g"
find /usr/share/nginx/html/photos -name '*.js' |
xargs sed -i'' "s#ENTE_PHOTOS_ORIGIN_PLACEHOLDER#\$ENTE_PHOTOS_ORIGIN#g"
EOF

USER nginx

COPY --from=builder --chown=nginx:nginx /build/web/apps/photos/out /usr/share/nginx/html/photos
COPY --from=builder --chown=nginx:nginx /build/web/apps/accounts/out /usr/share/nginx/html/accounts
COPY --from=builder --chown=nginx:nginx /build/web/apps/auth/out /usr/share/nginx/html/auth
COPY --from=builder --chown=nginx:nginx /build/web/apps/cast/out /usr/share/nginx/html/cast
COPY --from=builder --chown=nginx:nginx /build/web/apps/share/out /usr/share/nginx/html/share
COPY --from=builder --chown=nginx:nginx /build/web/apps/embed/out /usr/share/nginx/html/embed

COPY <<EOF /etc/nginx/conf.d/default.conf
server {
listen 3000; root /out/photos;
listen 3000; root /usr/share/nginx/html/photos;
location / { try_files \$uri \$uri.html /index.html; }
add_header 'Access-Control-Allow-Origin' 'ENTE_API_ORIGIN_PLACEHOLDER';
}
server {
listen 3001; root /out/accounts;
listen 3001; root /usr/share/nginx/html/accounts;
location / { try_files \$uri \$uri.html /index.html; }
add_header 'Access-Control-Allow-Origin' 'ENTE_API_ORIGIN_PLACEHOLDER';
}
server {
listen 3002; root /out/photos;
listen 3002; root /usr/share/nginx/html/photos;
location / { try_files \$uri \$uri.html /index.html; }
add_header 'Access-Control-Allow-Origin' 'ENTE_API_ORIGIN_PLACEHOLDER';
}
server {
listen 3003; root /out/auth;
listen 3003; root /usr/share/nginx/html/auth;
location / { try_files \$uri \$uri.html /index.html; }
add_header 'Access-Control-Allow-Origin' 'ENTE_API_ORIGIN_PLACEHOLDER';
}
server {
listen 3004; root /out/cast;
listen 3004; root /usr/share/nginx/html/cast;
location / { try_files \$uri \$uri.html /index.html; }
add_header 'Access-Control-Allow-Origin' 'ENTE_API_ORIGIN_PLACEHOLDER';
}
server {
listen 3005; root /out/share;
listen 3005; root /usr/share/nginx/html/share;
location / { try_files \$uri \$uri.html /index.html; }
add_header 'Access-Control-Allow-Origin' 'ENTE_API_ORIGIN_PLACEHOLDER';
}
server {
listen 3006; root /out/embed;
listen 3006; root /usr/share/nginx/html/embed;
location / { try_files \$uri \$uri.html /index.html; }
add_header 'Access-Control-Allow-Origin' 'ENTE_API_ORIGIN_PLACEHOLDER';
}
EOF

Expand All @@ -81,14 +100,3 @@ EXPOSE 3006
ENV ENTE_API_ORIGIN=http://localhost:8080
ENV ENTE_ALBUMS_ORIGIN=https://localhost:3002
ENV ENTE_PHOTOS_ORIGIN=https://localhost:3000

COPY <<EOF /docker-entrypoint.d/90-replace-ente-env.sh
find /out -name '*.js' |
xargs sed -i'' "s#ENTE_API_ORIGIN_PLACEHOLDER#\$ENTE_API_ORIGIN#g"
find /out/photos -name '*.js' |
xargs sed -i'' "s#ENTE_ALBUMS_ORIGIN_PLACEHOLDER#\$ENTE_ALBUMS_ORIGIN#g"
find /out/photos -name '*.js' |
xargs sed -i'' "s#ENTE_PHOTOS_ORIGIN_PLACEHOLDER#\$ENTE_PHOTOS_ORIGIN#g"
EOF

RUN chmod +x /docker-entrypoint.d/90-replace-ente-env.sh