mirror of
https://github.com/10h30/astroplate.git
synced 2026-07-11 18:56:06 +09:00
Merge pull request #20 from sydneysoftwaredev/chore/update-docker-config-for-static-site-2
chore: configure Dockerfile to serve the project as a static site
This commit is contained in:
+21
-33
@@ -1,7 +1,11 @@
|
|||||||
|
ARG INSTALLER=yarn
|
||||||
|
|
||||||
FROM node:18-alpine AS base
|
FROM node:18-alpine AS base
|
||||||
|
|
||||||
# Install dependencies only when needed
|
# Install dependencies only when needed
|
||||||
FROM base AS deps
|
FROM base AS deps
|
||||||
|
ARG INSTALLER
|
||||||
|
|
||||||
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
|
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
|
||||||
RUN apk add --no-cache libc6-compat
|
RUN apk add --no-cache libc6-compat
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
@@ -9,10 +13,10 @@ WORKDIR /app
|
|||||||
# Install dependencies based on the preferred package manager
|
# Install dependencies based on the preferred package manager
|
||||||
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
|
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
|
||||||
RUN \
|
RUN \
|
||||||
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
|
if [ "${INSTALLER}" == "yarn" ]; then yarn --frozen-lockfile; \
|
||||||
elif [ -f package-lock.json ]; then npm ci; \
|
elif [ "${INSTALLER}" == "npm" ]; then npm ci; \
|
||||||
elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i --frozen-lockfile; \
|
elif [ "${INSTALLER}" == "pnpm" ]; then yarn global add pnpm && pnpm i --frozen-lockfile; \
|
||||||
else echo "Lockfile not found." && exit 1; \
|
else echo "Valid installer not set." && exit 1; \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
@@ -22,34 +26,18 @@ WORKDIR /app
|
|||||||
COPY --from=deps /app/node_modules ./node_modules
|
COPY --from=deps /app/node_modules ./node_modules
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Next.js collects completely anonymous telemetry data about general usage.
|
# RUN chmod u+x ./installer && ./installer
|
||||||
# Learn more here: https://nextjs.org/telemetry
|
ARG INSTALLER
|
||||||
# Uncomment the following line in case you want to disable telemetry during the build.
|
RUN \
|
||||||
# ENV NEXT_TELEMETRY_DISABLED 1
|
if [ "${INSTALLER}" == "yarn" ]; then yarn build; \
|
||||||
|
elif [ "${INSTALLER}" == "npm" ]; then npm run build; \
|
||||||
|
elif [ "${INSTALLER}" == "pnpm" ]; then pnpm run build; \
|
||||||
|
else echo "Valid installer not set." && exit 1; \
|
||||||
|
fi
|
||||||
|
|
||||||
RUN yarn build
|
# Production image, copy all the files and run nginx
|
||||||
|
FROM nginx:alpine AS runner
|
||||||
|
COPY ./config/nginx/nginx.conf /etc/nginx/nginx.conf
|
||||||
|
COPY --from=builder /app/dist /usr/share/nginx/html
|
||||||
|
|
||||||
# If using npm comment out above and use below instead
|
WORKDIR /usr/share/nginx/html
|
||||||
# RUN npm run build
|
|
||||||
|
|
||||||
# Production image, copy all the files and run next
|
|
||||||
FROM base AS runner
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
ENV NODE_ENV production
|
|
||||||
# Uncomment the following line in case you want to disable telemetry during runtime.
|
|
||||||
# ENV NEXT_TELEMETRY_DISABLED 1
|
|
||||||
|
|
||||||
RUN addgroup --system --gid 1001 nodejs
|
|
||||||
RUN adduser --system --uid 1001 astro
|
|
||||||
|
|
||||||
COPY --from=builder /app/public ./public
|
|
||||||
|
|
||||||
USER astro
|
|
||||||
|
|
||||||
EXPOSE 3000
|
|
||||||
|
|
||||||
ENV PORT 3000
|
|
||||||
ENV HOSTNAME localhost
|
|
||||||
|
|
||||||
CMD ["node", "server.js"]
|
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
worker_processes 1;
|
||||||
|
|
||||||
|
events {
|
||||||
|
worker_connections 1024;
|
||||||
|
}
|
||||||
|
|
||||||
|
http {
|
||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
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}.html $uri/index.html =404;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -92,7 +92,19 @@ npm run build
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker build -t astroplate .
|
docker build -t astroplate .
|
||||||
docker run -p 3000:3000 astroplate
|
# or
|
||||||
|
# docker --build-arg=npm build -t astroplate .
|
||||||
|
# or
|
||||||
|
# docker --build-arg=pnpm build -t astroplate .
|
||||||
|
docker run -p 3000:80 astroplate
|
||||||
|
# or
|
||||||
|
# docker run --rm -p 3000:80 astroplate
|
||||||
|
```
|
||||||
|
|
||||||
|
To access the shell within the container:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run -it --rm astroplate ash
|
||||||
```
|
```
|
||||||
|
|
||||||
<!-- reporting issue -->
|
<!-- reporting issue -->
|
||||||
|
|||||||
Reference in New Issue
Block a user