Skip to content

Commit

Permalink
chore: simplifying nginx frontend service + add caching (#18)
Browse files Browse the repository at this point in the history
* simplifying nginx frontend service + add caching (#18)
  • Loading branch information
edevosc2c authored Jan 27, 2025
1 parent 21f807d commit 9eea680
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 46 deletions.
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ services:
maelstro-front:
build:
context: ./frontend
target: server
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/maelstro/"]
interval: 10s
Expand Down
18 changes: 3 additions & 15 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,9 @@ COPY ./ .
RUN npm run build


FROM nginx:1.27-alpine AS server
FROM nginxinc/nginx-unprivileged:1.27-alpine

RUN mkdir /app
ENV CUSTOM_SCRIPTS_DIRECTORY ""
COPY --from=builder /app/dist /app
COPY nginx.conf /etc/nginx/nginx.conf
COPY --from=builder --chown=nginx /app/dist /app
COPY nginx-default.conf /etc/nginx/conf.d/default.conf
COPY ./docker-entrypoint.sh /

## add permissions
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

## switch to non-root user
USER nginx
34 changes: 34 additions & 0 deletions frontend/nginx-default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
server {
listen 8080 default_server;
server_name _;

access_log /var/log/nginx/access.log main;

location /maelstro {
alias /app;
index index.html;
try_files $uri $uri/ /index.html;
autoindex off;
expires off;
add_header Cache-Control "public, max-age=0, s-maxage=0, must-revalidate" always;
}

# all assets contain hash in filename, cache forever
location ^~ /assets/ {
alias /app;
add_header Cache-Control "public, max-age=31536000, s-maxage=31536000, immutable";
try_files $uri =404;
}

# all workbox scripts are compiled with hash in filename, cache forever
location ^~ /workbox- {
alias /app;
add_header Cache-Control "public, max-age=31536000, s-maxage=31536000, immutable";
try_files $uri =404;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
30 changes: 0 additions & 30 deletions frontend/nginx.conf

This file was deleted.

0 comments on commit 9eea680

Please sign in to comment.