# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

FROM --platform=$BUILDPLATFORM node:26-trixie-slim AS builder

WORKDIR /home/node/code
COPY . .

# Node 25+ images no longer bundle Yarn or Corepack, so run the Yarn release
# checked in under .yarn/releases (the yarnPath in .yarnrc.yml).
RUN YARN="node $(sed -n 's/^yarnPath: *//p' .yarnrc.yml)" && \
    $YARN install && \
    $YARN build

# nginxinc/nginx-unprivileged stopped publishing on 2026-10-19, and its last
# build (1.31.7) predates the CVE-2026-123007 fixes. Use the maintained
# official image, which ships 1.31.9.
FROM nginx/nginx-unprivileged:1.31.9
USER 0
#ADD https://github.com/ufoscout/docker-compose-wait/releases/download/2.9.0/wait /wait
#RUN chmod +x /wait
RUN rm /etc/nginx/conf.d/default.conf
COPY ./nginx.conf /etc/nginx/conf.d/default.conf.tpl
WORKDIR /usr/share/nginx/html
RUN rm -rf ./*
COPY --from=builder /home/node/code/dist/. ./
EXPOSE 4000 4443
# apt-get upgrade picks up Debian security fixes that the base tag does not contain yet
RUN apt-get update && \
    apt-get upgrade -y && \
    apt-get install -y apache2-utils iproute2 && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*
COPY --from=builder /home/node/code/nginx.sh /usr/bin/nginx.sh
RUN chmod +x /usr/bin/nginx.sh
RUN chgrp -R 0 /etc/nginx /var/log/nginx /usr/share/nginx /run && \
    chmod -R g=u /etc/nginx /var/log/nginx /usr/share/nginx /run
USER 101
CMD ["/usr/bin/nginx.sh"]
