FROM docker.io/node:lts-alpine AS build WORKDIR /app COPY package*.json ./ RUN npm ci COPY / ./ RUN npm run build FROM docker.io/nixos/nix:2.26.2 AS build-nginx # Install nginx RUN mkdir -p /output/store RUN nix-env --profile /output/profile -i nginx RUN cp -va $(nix-store -qR /output/profile) /output/store # Create empty directories needed by nginx RUN mkdir -p /to_add/var/log/nginx \ /to_add/var/cache/nginx/tmp \ /to_add/var/conf/ \ /to_add/var/conf/ \ /to_add/var/www \ /to_add/var/run # Create user and group for nginx RUN nix-shell -p busybox --command "addgroup --system nginx && adduser --system -G nginx --uid 31337 nginx" # Make sure nginx can write to required directories RUN chown -R 31337 /to_add/ FROM scratch # Copy over nginx files and dependencies COPY --from=build-nginx /output/store /nix/store COPY --from=build-nginx /output/profile/ /usr/local/ COPY --from=build-nginx /to_add / # Copy required user information COPY --from=build-nginx /etc/passwd /etc/passwd COPY --from=build-nginx /etc/group /etc/group # Add user specific content and config COPY --from=build --chown=nginx:nginx /app/dist/ /var/www/ COPY ./nginx.conf /var/conf/nginx.conf EXPOSE 8000 ENTRYPOINT ["nginx", "-p", "/var/"]