From 427e14ac46820d72ab79a9b6a8301e365eb8109c Mon Sep 17 00:00:00 2001 From: Dylan Decrulle <81740200+ddecrulle@users.noreply.github.com> Date: Tue, 25 Jul 2023 15:28:55 +0200 Subject: [PATCH] fix: docker image --- Dockerfile | 29 ++++++++++++++++------------- nginx.conf | 2 +- package.json | 2 +- scripts/env.sh | 2 +- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/Dockerfile b/Dockerfile index 16e9254..0bb9021 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,34 +5,37 @@ COPY package.json yarn.lock .env ./ COPY public ./public RUN yarn install --frozen-lockfile --network-timeout 600000 COPY jsconfig.json .prettierrc ./ +COPY scripts ./scripts COPY src ./src RUN yarn build COPY nginx.conf ./ # Production Env FROM nginx:stable-alpine - COPY --from=build /app/nginx.conf /etc/nginx/conf.d/default.conf -WORKDIR /usr/share/nginx +WORKDIR /usr/share/nginx/html + + +# Add bash +RUN apk add --no-cache bash + ## Copy .env file and shell script to container -COPY ./scripts/env.sh . -COPY ./scripts/.env . +COPY --from=build /app/build ./ +COPY --from=build /app/scripts/env.sh . +COPY --from=build /app/scripts/.env . -COPY --from=build /app/build ./html ## Make shell script executable and prevent windows encoding RUN sed -i -e 's/\r$//' env.sh && sed -i -e 's/\r$//' .env && chmod +x env.sh -RUN sed -i.orig -e '/user[[:space:]]\+nginx/d' -e 's@pid[[:space:]]\+.*@pid /tmp/nginx.pid;@' /etc/nginx/nginx.conf && \ - diff -u /etc/nginx/nginx.conf.orig /etc/nginx/nginx.conf ||: && \ - chown nginx /usr/share/nginx/html/index.html && \ - chown -Rc nginx /var/cache/nginx -# Equivalent to 'USER nginx', see: https://github.com/InseeFrLab/onyxia-web/pull/279 -USER 101 +# add non-root user +RUN touch /var/run/nginx.pid +RUN chown -R nginx:nginx /var/run/nginx.pid /usr/share/nginx/html /var/cache/nginx /var/log/nginx /etc/nginx/conf.d -## non root users cannot listen on 80 +# non root users cannot listen on 80 EXPOSE 8080 + USER nginx # Start Nginx server -CMD ["/bin/bash", "-c", "/usr/share/nginx/html/env.sh && nginx -g \"daemon off;\""] \ No newline at end of file +ENTRYPOINT bash -c "/usr/share/nginx/html/env.sh && nginx -g 'daemon off;'" \ No newline at end of file diff --git a/nginx.conf b/nginx.conf index 2ce9bd9..71a8ab5 100644 --- a/nginx.conf +++ b/nginx.conf @@ -1,5 +1,5 @@ server { - listen 80 default_server; + listen 8080; server_name /usr/share/nginx/html; root /usr/share/nginx/html; diff --git a/package.json b/package.json index 60e5a3a..f051c61 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "platine-management", - "version": "0.2.11", + "version": "0.2.12", "private": true, "dependencies": { "@emotion/react": "^11.11.1", diff --git a/scripts/env.sh b/scripts/env.sh index 8c24202..49b14c0 100644 --- a/scripts/env.sh +++ b/scripts/env.sh @@ -19,6 +19,6 @@ do done < .env envsubst < "./configuration.json" > "configuration.temp" - envsubst < "./keycloak.json" > "keycloak.temp" +envsubst < "./keycloak.json" > "keycloak.temp" mv configuration.temp configuration.json mv keycloak.temp keycloak.json