Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat :Dockerfile #8

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"]
Loading