From 866f71edd8b0f0cf2a2bfeded05d128f3f300408 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Laurent?= <francois.laurent@posteo.net>
Date: Fri, 13 Sep 2024 14:13:04 +0200
Subject: [PATCH] nginx docker image changed to unprivileged

---
 front/Containerfile                  | 43 ++++++++++++++++++++++++++++
 {nginx => front}/Containerfile.local | 11 ++++---
 {nginx => front}/Manifest.toml       |  0
 {nginx => front}/build-run-local.sh  |  2 +-
 {nginx => front}/build.sh            |  4 +--
 {nginx => front}/entrypoint.sh       |  2 --
 {nginx => front}/proxy.conf          |  0
 nginx/Containerfile                  | 31 --------------------
 8 files changed, 53 insertions(+), 40 deletions(-)
 create mode 100644 front/Containerfile
 rename {nginx => front}/Containerfile.local (69%)
 rename {nginx => front}/Manifest.toml (100%)
 rename {nginx => front}/build-run-local.sh (92%)
 rename {nginx => front}/build.sh (84%)
 rename {nginx => front}/entrypoint.sh (86%)
 rename {nginx => front}/proxy.conf (100%)
 delete mode 100644 nginx/Containerfile

diff --git a/front/Containerfile b/front/Containerfile
new file mode 100644
index 0000000..3c501fb
--- /dev/null
+++ b/front/Containerfile
@@ -0,0 +1,43 @@
+FROM docker.io/nginxinc/nginx-unprivileged:1.27
+
+ENV JULIA_PROJECT /app
+ENV JULIA_DEPOT_PATH /app/julia
+ENV JULIAUP_DEPOT_PATH /app/juliaup
+
+ARG JULIA_VERSION=1.10.5
+
+# UID/GID should match with same arguments defined in:
+# https://github.com/nginxinc/docker-nginx-unprivileged/blob/main/mainline/debian/Dockerfile
+ARG UID=101
+ARG GID=101
+
+COPY --chown="$UID:$GID" . "$JULIA_PROJECT"
+
+RUN export HOME="$JULIA_PROJECT" \
+ && curl -fsSL https://install.julialang.org \
+  | sh -s -- --yes --default-channel "$JULIA_VERSION"
+
+ENV PATH "$PATH:$JULIA_PROJECT/.juliaup/bin"
+
+RUN cd "$JULIA_PROJECT" \
+ && rm -rf public \
+ && rm -rf storage \
+ && cp front/Manifest.toml . \
+ && julia -e 'using Pkg; Pkg.instantiate()' \
+ && mkdir -p public \
+ && chmod a+x front/entrypoint.sh
+
+
+ARG PUBLIC_URL=localhost
+
+ARG NGINX_CONFIG=/etc/nginx/conf.d/default.conf
+
+COPY front/proxy.conf "$NGINX_CONFIG"
+
+RUN if [ -n "$PUBLIC_URL" ]; then \
+    sed -i "s/localhost/$PUBLIC_URL/" "$NGINX_CONFIG"; \
+    fi \
+ && sed -i "s/80;/8080;/" "$NGINX_CONFIG"
+
+ENTRYPOINT ["/app/front/entrypoint.sh"]
+CMD []
diff --git a/nginx/Containerfile.local b/front/Containerfile.local
similarity index 69%
rename from nginx/Containerfile.local
rename to front/Containerfile.local
index b3df602..ab09c3c 100644
--- a/nginx/Containerfile.local
+++ b/front/Containerfile.local
@@ -1,6 +1,8 @@
 FROM nginx:1.27.1
 
-COPY ./NyxUI.jl/nginx/proxy.conf /etc/nginx/conf.d/default.conf
+# builds from NyxUI.jl's parent directory
+
+COPY ./NyxUI.jl/front/proxy.conf /etc/nginx/conf.d/default.conf
 
 ENV JULIAUP_DEPOT_PATH /juliaup
 ENV JULIA_DEPOT_PATH /julia
@@ -9,6 +11,8 @@ ARG JULIA_VERSION=1.10.5
 RUN curl -fsSL https://install.julialang.org \
   | sh -s -- --yes --default-channel $JULIA_VERSION
 
+ENV PATH "$PATH:/root/.juliaup/bin"
+
 COPY ./NyxWidgets.jl /app/NyxWidgets.jl
 COPY ./NyxPlots.jl /app/NyxPlots.jl
 COPY ./NyxUI.jl /app/NyxUI.jl
@@ -16,10 +20,9 @@ COPY ./NyxUI.jl /app/NyxUI.jl
 ENV JULIA_PROJECT /app/NyxUI.jl
 
 RUN cd /app/NyxUI.jl \
- && . /root/.profile \
  && julia -e 'using Pkg; Pkg.add(path="../NyxWidgets.jl"); Pkg.add(path="../NyxPlots.jl"); Pkg.instantiate();' \
  && mkdir -p public \
- && chmod a+x nginx/entrypoint.sh
+ && chmod a+x front/entrypoint.sh
 
-ENTRYPOINT ["/app/NyxUI.jl/nginx/entrypoint.sh"]
+ENTRYPOINT ["/app/NyxUI.jl/front/entrypoint.sh"]
 CMD []
diff --git a/nginx/Manifest.toml b/front/Manifest.toml
similarity index 100%
rename from nginx/Manifest.toml
rename to front/Manifest.toml
diff --git a/nginx/build-run-local.sh b/front/build-run-local.sh
similarity index 92%
rename from nginx/build-run-local.sh
rename to front/build-run-local.sh
index 78711e0..2d209dc 100755
--- a/nginx/build-run-local.sh
+++ b/front/build-run-local.sh
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 
-CONTAINERFILE=nginx/Containerfile.local
+CONTAINERFILE=front/Containerfile.local
 
 if ! [ -f "$CONTAINERFILE" -a -f routes.jl ]; then
   echo "Run $0 from the project root directory"
diff --git a/nginx/build.sh b/front/build.sh
similarity index 84%
rename from nginx/build.sh
rename to front/build.sh
index f4938b5..02619d9 100755
--- a/nginx/build.sh
+++ b/front/build.sh
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 
-CONTAINERFILE=nginx/Containerfile
+CONTAINERFILE=front/Containerfile
 
 if ! [ -f "$CONTAINERFILE" -a -f routes.jl ]; then
   echo "Run $0 from the project root directory"
@@ -14,7 +14,7 @@ podman rmi -f $IMAGE || true
 podman build --tag $IMAGE -f "$CONTAINERFILE" .
 
 if [ "$1" = "--now" ]; then
-  podman run -d -p 8080:80 $IMAGE
+  podman run -d -p 8080:8080 $IMAGE
 
   CONTAINER=`podman ps | grep $IMAGE | cut -d' ' -f1`
 
diff --git a/nginx/entrypoint.sh b/front/entrypoint.sh
similarity index 86%
rename from nginx/entrypoint.sh
rename to front/entrypoint.sh
index 187991f..33fda00 100644
--- a/nginx/entrypoint.sh
+++ b/front/entrypoint.sh
@@ -2,8 +2,6 @@
 
 echo "JULIA_PROJECT=$JULIA_PROJECT"
 
-command -v julia || . /root/.bashrc
-
 #export GENIE_ENV=prod
 #export GENIE_BASE_PATH=/g
 export BONITO_BASE_PATH=/bonito
diff --git a/nginx/proxy.conf b/front/proxy.conf
similarity index 100%
rename from nginx/proxy.conf
rename to front/proxy.conf
diff --git a/nginx/Containerfile b/nginx/Containerfile
deleted file mode 100644
index 0fcf907..0000000
--- a/nginx/Containerfile
+++ /dev/null
@@ -1,31 +0,0 @@
-FROM nginx:1.27.1
-
-ARG SERVER_NAME
-
-COPY nginx/proxy.conf /etc/nginx/conf.d/default.conf
-
-RUN if [ -n "$SERVER_NAME" ]; then \
-    sed -i "s/server_name localhost/server_name $SERVER_NAME/" \
-    /etc/nginx/conf.d/default.conf; \
-    fi
-
-ENV JULIAUP_DEPOT_PATH /juliaup
-ENV JULIA_DEPOT_PATH /julia
-ARG JULIA_VERSION=1.10.5
-
-RUN curl -fsSL https://install.julialang.org \
-  | sh -s -- --yes --default-channel $JULIA_VERSION
-
-COPY . /app
-
-ENV JULIA_PROJECT /app
-
-RUN cd $JULIA_PROJECT \
- && . /root/.profile \
- && cp nginx/Manifest.toml . \
- && julia -e 'using Pkg; Pkg.instantiate()' \
- && mkdir -p public \
- && chmod a+x nginx/entrypoint.sh
-
-ENTRYPOINT ["/app/nginx/entrypoint.sh"]
-CMD []
-- 
GitLab