From 09d6e1e9a097166a931ee9a6100663a0165c3846 Mon Sep 17 00:00:00 2001 From: Alex Wellnitz Date: Sat, 2 Sep 2023 23:38:32 +0200 Subject: [PATCH] feat: use nginx as server --- .dockerignore | 3 +++ Dockerfile | 28 ++++++----------------- charts/alexohneander-astro/values.yaml | 2 +- nginx/nginx.conf | 31 ++++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 22 deletions(-) create mode 100644 .dockerignore create mode 100644 nginx/nginx.conf diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..a44058c --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +.DS_Store +node_modules +dist \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 5208d75..1e72550 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,25 +1,11 @@ -FROM node:lts AS base +FROM node:lts AS build WORKDIR /app - -# By copying only the package.json and package-lock.json here, we ensure that the following `-deps` steps are independent of the source code. -# Therefore, the `-deps` steps will be skipped if only the source code changes. -COPY package.json package-lock.json ./ - -FROM base AS prod-deps -RUN npm install - -FROM base AS build-deps -RUN npm install - -FROM build-deps AS build +COPY package*.json ./ +RUN npm install COPY . . RUN npm run build -FROM base AS runtime -COPY --from=prod-deps /app/node_modules ./node_modules -COPY --from=build /app/dist ./dist - -ENV HOST=0.0.0.0 -ENV PORT=4321 -EXPOSE 4321 -CMD node ./dist/server/entry.mjs \ No newline at end of file +FROM nginx:alpine AS runtime +COPY ./nginx/nginx.conf /etc/nginx/nginx.conf +COPY --from=build /app/dist /usr/share/nginx/html +EXPOSE 8080 \ No newline at end of file diff --git a/charts/alexohneander-astro/values.yaml b/charts/alexohneander-astro/values.yaml index 2d16b71..9d42053 100644 --- a/charts/alexohneander-astro/values.yaml +++ b/charts/alexohneander-astro/values.yaml @@ -38,7 +38,7 @@ securityContext: {} service: type: ClusterIP - port: 4321 + port: 8080 ingress: enabled: false diff --git a/nginx/nginx.conf b/nginx/nginx.conf new file mode 100644 index 0000000..a1a6187 --- /dev/null +++ b/nginx/nginx.conf @@ -0,0 +1,31 @@ +worker_processes 1; + +events { + worker_connections 1024; +} + +http { + server { + listen 8080; + server_name _; + + root /usr/share/nginx/html; + index index.html index.htm; + include /etc/nginx/mime.types; + + gzip on; + gzip_min_length 1000; + gzip_proxied expired no-cache no-store private auth; + gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript; + + error_page 404 /404.html; + location = /404.html { + root /usr/share/nginx/html; + internal; + } + + location / { + try_files $uri $uri/index.html =404; + } + } +} \ No newline at end of file