Skip to content

Commit

Permalink
feat: build image and start service with container
Browse files Browse the repository at this point in the history
  • Loading branch information
usharerose committed Jul 20, 2024
1 parent 81f3ed3 commit 682cf5d
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
29 changes: 29 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 使用 Node 的官方镜像作为基础镜像
FROM node:20 AS build

# 设置工作目录
WORKDIR /app

# 将 package.json 和 package-lock.json 复制到工作目录
COPY package*.json ./

# 安装项目依赖
RUN npm install

# 复制项目文件到工作目录
COPY . .

# 构建项目
RUN npm run build

# 使用一个轻量级的镜像来运行构建好的应用
FROM nginx:alpine

# 将构建好的文件从 build 阶段复制到 nginx 的静态文件目录
COPY --from=build /app/dist /usr/share/nginx/html

# 暴露 80 端口
EXPOSE 80

# 启动 nginx
CMD ["nginx", "-g", "daemon off;"]
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
build:
docker-compose build geetest-demo-build

run: build clean-container
docker-compose up -d geetest-demo-run

clean-container:
# stop and remove useless containers
docker-compose down --remove-orphans
14 changes: 14 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: '3.7'

services:

geetest-demo-build:
build:
context: .
image: geetest-demo:${IMAGE_TAG:-latest}

geetest-demo-run:
image: geetest-demo:${IMAGE_TAG:-latest}
command: ["nginx", "-g", "daemon off;"]
ports:
- "30001:80"
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"main": "index.html",
"scripts": {
"dev": "vite"
"dev": "vite",
"build": "vite build"
},
"dependencies": {
"react": "^18.3.1",
Expand Down

0 comments on commit 682cf5d

Please sign in to comment.