From 0c36f39514d741f6125e464d3c62d1201063aec4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=8F=E3=83=B3=20/=20Han?= <16288797+hannoeru@users.noreply.github.com> Date: Fri, 1 Jul 2022 01:09:36 +0900 Subject: [PATCH] chore: fix container build and minimize container size (#380) --- .dockerignore | 2 ++ Dockerfile | 19 +++++++++++++++---- README.md | 12 ++++++++---- 3 files changed, 25 insertions(+), 8 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..f06235c --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +node_modules +dist diff --git a/Dockerfile b/Dockerfile index 1f6e2b1..6f913a9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,18 @@ -FROM node:16-alpine +FROM node:16-alpine as build-stage + +WORKDIR /app RUN corepack enable -WORKDIR /root/app + +COPY .npmrc package.json pnpm-lock.yaml ./ +RUN --mount=type=cache,id=pnpm-store,target=/root/.pnpm-store \ + pnpm install --frozen-lockfile + COPY . . -RUN pnpm i --prod RUN pnpm build -CMD pnpm preview --host + +FROM nginx:stable-alpine as production-stage + +COPY --from=build-stage /app/dist /usr/share/nginx/html +EXPOSE 80 + +CMD ["nginx", "-g", "daemon off;"] diff --git a/README.md b/README.md index 94c9940..dca17b2 100644 --- a/README.md +++ b/README.md @@ -191,14 +191,18 @@ And you will see the generated file in `dist` that ready to be served. Go to [Netlify](https://app.netlify.com/start) and select your clone, `OK` along the way, and your App will be live in a minute. -### Docker -First, build the vitesse image by opening the terminal in the project's root directory. +### Docker Production Build + +First, build the vitesse image by opening the terminal in the project's root directory. + ```bash -docker build . -t vitesse +docker build . -t vitesse:latest ``` + Run the image and specify port mapping with the `-p` flag. + ```bash -docker run -p 4173:4173 vitesse +docker run --rm -it -p 8080:80 vitesse:latest ``` ## Why