From 4a06b3943c76ca5a4eb95a2ef88090d751090342 Mon Sep 17 00:00:00 2001 From: Jerry Wang Date: Thu, 16 Feb 2023 20:25:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20docker=20=E6=9E=84?= =?UTF-8?q?=E5=BB=BA=E7=9A=84=E9=95=9C=E5=83=8F=E6=96=87=E4=BB=B6=E5=A4=A7?= =?UTF-8?q?=E5=B0=8F=EF=BC=8C=E6=B7=BB=E5=8A=A0=E8=87=AA=E5=8A=A8=E5=8C=96?= =?UTF-8?q?=E6=9E=84=E5=BB=BA=20(#42)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * perf: optimize docker image * perf: shrink image size * fix: build docker image * fix: docker image namespace * docs: add docker compose example * docs: fix docker compose example * docs: fix again :) * docs: and again..... --- .github/workflows/build_docker.yml | 37 ++++++++++++++++++++++++++++++ Dockerfile | 23 ++++++++++--------- README.md | 14 +++++++++++ 3 files changed, 63 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/build_docker.yml diff --git a/.github/workflows/build_docker.yml b/.github/workflows/build_docker.yml new file mode 100644 index 0000000..75f8011 --- /dev/null +++ b/.github/workflows/build_docker.yml @@ -0,0 +1,37 @@ +name: build_docker + +on: + push: + branches: [ main ] + +jobs: + build_docker: + name: Build docker + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: 0xjerry/chatgpt-web + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Login to DockerHub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Build and push + id: docker_build + uses: docker/build-push-action@v4 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + platforms: linux/amd64,linux/arm64 diff --git a/Dockerfile b/Dockerfile index 253cf70..f0b6f22 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,20 @@ -FROM node:lts +# build front-end +FROM node:lts-alpine AS builder -# copy resource -RUN mkdir /app COPY ./ /app WORKDIR /app -# build -RUN npm install pnpm -g -RUN pnpm bootstrap -WORKDIR /app/service -RUN pnpm install +RUN npm install pnpm -g && pnpm install && pnpm run build + +# service +FROM node:lts-alpine + +COPY /service /app +COPY --from=builder /app/dist /app/public + WORKDIR /app +RUN npm install pnpm -g && pnpm install -EXPOSE 1002 EXPOSE 3002 -CMD ["/bin/bash","./start.sh"] - +CMD ["pnpm", "run", "start"] \ No newline at end of file diff --git a/README.md b/README.md index 65714fc..cbaeae0 100644 --- a/README.md +++ b/README.md @@ -109,6 +109,20 @@ docker build -t marlkiller/chatgpt-web . docker run -p 1002:1002 marlkiller/chatgpt-web ``` +## Docker compose + +```yml +version: '3' + +service: + app: + image: 0xjerry/chatgpt-web + ports: + - 3002:3002 + environment: + OPENAI_API_KEY: xxxxxx +``` + ### 网页 根目录下运行以下命令,然后将 `dist` 文件夹复制到你的托管服务器上