From e04160199262eb44b6c36b288344a29ad25b9256 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9C=E5=A4=9C?= Date: Wed, 19 Jun 2024 00:20:13 +0800 Subject: [PATCH] feat :Dockerfile --- .github/workflows/deploy.yml | 34 +++++++++++++++++++++++++++++----- Dockerfile | 31 +++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 Dockerfile diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 7ea2b19..9ea1847 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -8,11 +8,35 @@ jobs: runs-on: self-hosted steps: - - name: Checkout Repository + - name: Checkout uses: actions/checkout@v4 - - name: Install dependency - run: npm i + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 - - name: Build - run: npm run build + - name: Build and export + uses: docker/build-push-action@v5 + with: + context: . + tags: docswebsite:latest + outputs: type=docker,dest=/tmp/docswebsite.tar + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: docswebsite + path: /tmp/docswebsite.tar + use: + runs-on: ubuntu-latest + needs: build + steps: + - name: Download artifact + uses: actions/download-artifact@v4 + with: + name: docswebsite + path: /tmp + + - name: Load image + run: | + docker load --input /tmp/docswebsite.tar + docker image ls -a \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8e34115 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,31 @@ +# 選擇 Node.js 的基礎映像檔 +FROM node:lts AS builder + +# 設定工作目錄 +WORKDIR /app + +# 複製 package.json 和 package-lock.json (或 yarn.lock) +COPY package*.json ./ + +# 安裝依賴 +RUN npm i + +# 複製其他應用程式文件 +COPY . . + +RUN npm run build + +# 選擇第二階段構建以優化大小 +FROM node:lts-alpine + +# 設定工作目錄 +WORKDIR /app + +# 複製從第一階段構建的 node_modules 和應用文件 +COPY --from=builder /app . + +# 暴露應用程式使用的端口 +# EXPOSE 1015 + +# 定義啟動命令 +CMD ["npm", "--", "run", "serve", "--", "--port", "8080", "--host", "localhost"]