Skip to content

Commit

Permalink
Merge pull request #14 from ExpTechTW/Dockerfile
Browse files Browse the repository at this point in the history
Dockerfile
  • Loading branch information
whes1015 authored Jun 21, 2024
2 parents 5cc5d8f + f376085 commit f8185ec
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 41 deletions.
45 changes: 21 additions & 24 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,44 +1,41 @@
name: "deploy"

on:
push:
branches: [main]
workflow_dispatch:
branches: main
pull_request:
branches: "**"

jobs:
build:
runs-on: self-hosted

docker:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and export
uses: docker/build-push-action@v5
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
context: .
tags: docswebsite:latest
outputs: type=docker,dest=/tmp/docswebsite.tar
registry: images.exptech.dev
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Upload artifact
uses: actions/upload-artifact@v4
- name: Build and push
uses: docker/build-push-action@v6
with:
name: docswebsite
path: /tmp/docswebsite.tar
platforms: linux/amd64,linux/arm64
push: true
tags: images.exptech.dev/exptech-docs:latest
use:
runs-on: self-hosted
needs: build
needs: docker
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 pull images.exptech.dev/exptech-docs
docker image ls -a
cd /home/whes1015
docker compose up -d
34 changes: 17 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
# 選擇 Node.js 的基礎映像檔
FROM node:lts AS builder
# 構建階段
FROM node:18-alpine AS builder

# 設定工作目錄
WORKDIR /app

# 複製 package.json 和 package-lock.json (或 yarn.lock)
# 複製 package.json 和 package-lock.json(如果存在)
COPY package*.json ./

# 安裝依賴
RUN npm i
# 只安裝生產依賴
RUN npm ci --only=production

# 複製其他應用程式文件
# 複製源代碼
COPY . .

# 構建應用
RUN npm run build

# 選擇第二階段構建以優化大小
FROM node:lts-alpine
# 運行階段
FROM nginx:alpine

# 設定工作目錄
WORKDIR /app
# 複製構建結果到 Nginx 服務目錄
COPY --from=builder /app/build /usr/share/nginx/html

# 複製從第一階段構建的 node_modules 和應用文件
COPY --from=builder /app .
# 複製自定義 Nginx 配置(如果有的話)
# COPY nginx.conf /etc/nginx/conf.d/default.conf

# 暴露應用程式使用的端口
# EXPOSE 1015
# 暴露 80 端口
EXPOSE 80

# 定義啟動命令
CMD ["npm", "run", "serve", "--", "--port", "8080", "--host", "localhost"]
# 啟動 Nginx
CMD ["nginx", "-g", "daemon off;"]

0 comments on commit f8185ec

Please sign in to comment.