Skip to content

Commit

Permalink
build(docker): essai avec nginx unprivileged
Browse files Browse the repository at this point in the history
  • Loading branch information
ocruze committed Feb 13, 2024
1 parent fe6a320 commit df63995
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
20 changes: 11 additions & 9 deletions .docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ RUN apk add git

WORKDIR /app
COPY . .

RUN npm ci \
&& npx @11ty/eleventy --pathprefix=/docs/ \
&& npx pagefind --site _site/ --output-subdir \"_pagefind\" \
Expand All @@ -15,19 +16,20 @@ RUN npm ci \
#----------------------------------------------------------------------
# cartesgouvfr-documentation : Config d'un serveur statique avec nginx
#----------------------------------------------------------------------
FROM nginx:alpine
COPY --from=builder /app/_site /usr/share/nginx/html/docs/
FROM nginxinc/nginx-unprivileged:alpine
COPY --from=builder /app/_site /usr/share/nginx/html/
COPY --from=builder /app/_site/fr/index.html /usr/share/nginx/html/
COPY .docker/nginx.conf /etc/nginx/nginx.conf

WORKDIR /app
# WORKDIR /app

RUN chown -R nginx:nginx /app && chmod -R 755 /app \
&& chown -R nginx:nginx /var/cache/nginx \
&& chown -R nginx:nginx /var/log/nginx \
&& chown -R nginx:nginx /etc/nginx/conf.d
# RUN chown -R nginx:nginx /app && chmod -R 755 /app \
# && chown -R nginx:nginx /var/cache/nginx \
# && chown -R nginx:nginx /var/log/nginx \
# && chown -R nginx:nginx /etc/nginx/conf.d

RUN touch /var/run/nginx.pid \
&& chown -R nginx:nginx /var/run/nginx.pid
# RUN touch /var/run/nginx.pid \
# && chown -R nginx:nginx /var/run/nginx.pid

EXPOSE 8082

Expand Down
12 changes: 4 additions & 8 deletions .docker/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pid /tmp/nginx.pid;
worker_processes 1;

events {
Expand Down Expand Up @@ -26,21 +27,16 @@ http {

index index.html index.htm;

# Redirect "/", "/docs" to "/fr"
location ~ ^(/|/docs(/)?)$ {
return 301 /docs/fr;
}

# Serve static files
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /docs/404.html;
try_files $uri $uri/ /404.html;
}

# Handle 404 errors
error_page 404 /docs/404.html;
location = /docs/404.html {
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
internal;
}
Expand Down
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/.vscode
/.github
/.docker/Dockerfile
/node_modules/
/docs
/_site
Expand Down

0 comments on commit df63995

Please sign in to comment.