Skip to content

Commit

Permalink
feat :Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
yayacat committed Jun 18, 2024
1 parent d16c1f4 commit e041601
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 5 deletions.
34 changes: 29 additions & 5 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
31 changes: 31 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]

0 comments on commit e041601

Please sign in to comment.