chore: fix container build and minimize container size (#380)

This commit is contained in:
ハン / Han 2022-07-01 01:09:36 +09:00 committed by GitHub
parent 4d6d9b9d2f
commit 0c36f39514
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 8 deletions

2
.dockerignore Normal file
View File

@ -0,0 +1,2 @@
node_modules
dist

View File

@ -1,7 +1,18 @@
FROM node:16-alpine FROM node:16-alpine as build-stage
WORKDIR /app
RUN corepack enable 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 . . COPY . .
RUN pnpm i --prod
RUN pnpm build 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;"]

View File

@ -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. 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 ### Docker Production Build
First, build the vitesse image by opening the terminal in the project's root directory.
First, build the vitesse image by opening the terminal in the project's root directory.
```bash ```bash
docker build . -t vitesse docker build . -t vitesse:latest
``` ```
Run the image and specify port mapping with the `-p` flag. Run the image and specify port mapping with the `-p` flag.
```bash ```bash
docker run -p 4173:4173 vitesse docker run --rm -it -p 8080:80 vitesse:latest
``` ```
## Why ## Why