From 22446291619945c8e79ab2f583c77138fef02d42 Mon Sep 17 00:00:00 2001 From: tawoe Date: Tue, 7 May 2024 14:23:25 +0200 Subject: [PATCH] creating containers --- Dockerfiles/Dockerfile_backend | 22 +++++++++------------- Dockerfiles/Dockerfile_backend_OC | 23 ----------------------- Dockerfiles/Dockerfile_frontend | 9 ++++++--- Dockerfiles/nginx.conf | 20 ++------------------ 4 files changed, 17 insertions(+), 57 deletions(-) delete mode 100644 Dockerfiles/Dockerfile_backend_OC diff --git a/Dockerfiles/Dockerfile_backend b/Dockerfiles/Dockerfile_backend index cba1787..1c8fa28 100644 --- a/Dockerfiles/Dockerfile_backend +++ b/Dockerfiles/Dockerfile_backend @@ -1,25 +1,21 @@ # First stage builds the application -FROM ubi8/nodejs-16 as builder +FROM node:lts-bullseye as builder # Add application sources -ADD app-src $HOME - +ADD ../.. /home/node/app/ +WORKDIR /home/node/app # Install the dependencies RUN npm install -RUN npm build-server +RUN npm run build-server # Run script uses standard ways to run the application -CMD npm run -d start +# CMD npm run -d start FROM node:lts-bullseye -USER 0 - -COPY --from=builder /app/server-dist /app -WORKDIR /app -RUN chown 1001 / -RUN chown -R 1001 /app -RUN chgrp -R 0 /app && chmod -R g+rwX /app -USER 1001 +COPY --from=builder /home/node/app/server-dist /home/node/app +RUN mkdir /home/node/node_modules +COPY --from=builder /home/node/app/node_modules /home/node/node_modules +WORKDIR /home/node/app CMD ["node", "app.js"] diff --git a/Dockerfiles/Dockerfile_backend_OC b/Dockerfiles/Dockerfile_backend_OC deleted file mode 100644 index a034a0d..0000000 --- a/Dockerfiles/Dockerfile_backend_OC +++ /dev/null @@ -1,23 +0,0 @@ -# First stage builds the application -FROM ubi8/nodejs-16 as builder - -# Add application sources -ADD app-src $HOME - -# Install the dependencies -RUN npm install -RUN npm build-server - -FROM ubi8/nodejs-16-minimal - -USER 0 -COPY --from=builder $HOME $HOME -RUN chown -R 1001:0 $HOME -USER 1001 Copy the application source and build artifacts from the builder image to this one - - -# Run script uses standard ways to run the application -CMD npm run -d start - - - diff --git a/Dockerfiles/Dockerfile_frontend b/Dockerfiles/Dockerfile_frontend index 4bb0f84..87f6434 100644 --- a/Dockerfiles/Dockerfile_frontend +++ b/Dockerfiles/Dockerfile_frontend @@ -1,7 +1,9 @@ -FROM ubi8/nodejs-16 as builder +FROM node:lts-bullseye as builder USER 0 # Add application sources -ADD .. $HOME +# Add application sources +ADD ../.. /home/node/app/ +WORKDIR /home/node/app # Install the dependencies RUN npm install @@ -10,8 +12,9 @@ RUN npm run build FROM registry.access.redhat.com/ubi9/nginx-120 USER 0 RUN dnf update -y +RUN chown -R 1001 /var/log/nginx ADD Dockerfiles/nginx.conf "${NGINX_DEFAULT_CONF_PATH}" -COPY --from=builder /app/dist /opt/app-root/src +COPY --from=builder /home/node/app/dist /opt/app-root/src RUN chgrp -R 0 /opt/app-root/src/ && chmod -R g+rwX /opt/app-root/src/ USER 1001 CMD ["nginx", "-g", "daemon off;"] diff --git a/Dockerfiles/nginx.conf b/Dockerfiles/nginx.conf index 40c41f8..79ca96f 100644 --- a/Dockerfiles/nginx.conf +++ b/Dockerfiles/nginx.conf @@ -1,23 +1,7 @@ -http { - include /etc/nginx/mime.types; - default_type application/octet-stream; - log_format main '$remote_addr - $remote_user [$time_local] "$request" ' - '$status $body_bytes_sent "$http_referer" ' - '"$http_user_agent" "$http_x_forwarded_for"'; - access_log /var/log/nginx/access.log main; - sendfile on; - keepalive_timeout 65; - server { - listen 80; + server_name localhost; location / { - root /app; + root /opt/app-root/src/; index index.html; try_files $uri $uri/ /index.html; } - error_page 500 502 503 504 /50x.html; - location = /50x.html { - root /usr/share/nginx/html; - } - } -} \ No newline at end of file