添加docker文件
Some checks failed
CI Pipeline / build (push) Failing after 4m22s

This commit is contained in:
2025-08-24 13:58:31 +08:00
parent aeacbab06c
commit e0ec4bd324
5 changed files with 122 additions and 11 deletions

View File

@@ -31,8 +31,8 @@ jobs:
env:
DOCKER_REGISTRY_USERNAME: ${{ secrets.DOCKER_REGISTRY_USERNAME }}
DOCKER_REGISTRY_PASSWORD: ${{ secrets.DOCKER_REGISTRY_PASSWORD }}
DOCKER_REGISTRY_ADDRESS: crpi-s56ujsdigakae3xq.cn-hangzhou.personal.cr.aliyuncs.com/uniquespace
DOCKER_IMAGE_NAME: todolist
DOCKER_REGISTRY_ADDRESS: crpi-pqfsp88s5zx2zwfq.cn-hangzhou.personal.cr.aliyuncs.com/devstar
DOCKER_IMAGE_NAME: devstar_introduction
run: |
echo "$DOCKER_REGISTRY_PASSWORD" | docker login $DOCKER_REGISTRY_ADDRESS -u "$DOCKER_REGISTRY_USERNAME" --password-stdin
docker tag mynodeapp:latest $DOCKER_REGISTRY_ADDRESS/$DOCKER_IMAGE_NAME:latest

View File

@@ -1,12 +1,21 @@
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install --production
# 第一阶段node镜像打包
FROM node:20-alpine AS frontend-builder
WORKDIR /build-app
COPY . .
RUN npm install
RUN npm add -D vitepress
RUN npm run docs:build
EXPOSE 3000
# 第二阶段nginx打包
FROM nginx:1.25-alpine
EXPOSE 80
WORKDIR /app
# 替换nginx配置
COPY nginx.conf /etc/nginx/conf.d/default.conf
# 将第一阶段的静态文件复制到nginx中
RUN rm -rf /usr/share/nginx/html
RUN mkdir /usr/share/nginx/html
COPY --from=frontend-builder /build-app/docs/.vitepress/dist /usr/share/nginx/html
CMD ["node", "index.js"]
# 运行
CMD ["nginx", "-g", "daemon off;"]

34
k8s/deploy.yaml Normal file
View File

@@ -0,0 +1,34 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: devstar-app
namespace: devstar-deploy
spec:
replicas: 3
selector:
matchLabels:
app: devstar
template:
metadata:
labels:
app: devstar
spec:
containers:
- name: devstar
image: crp-pqf/sp885z2x2wfq.cn-hangzhou.personal.cr.aligunes.com/devstar/devstar_introduction:v1
ports:
- containerPort: 8889 # 容器监听端口
---
apiVersion: v1
kind: Service
metadata:
name: devstar-server-svc
namespace: devstar-deploy
spec:
type: NodePort
ports:
- port: 8889
targetPort: 8889
nodePort: 31234
selector:
app: devstar

47
k8s/zero-server.yaml Normal file
View File

@@ -0,0 +1,47 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: zero-server
namespace: zero-server
labels:
app: zero-server
spec:
replicas: 3
revisionHistoryLimit: 5
selector:
matchLabels:
app: zero-server
template:
metadata:
labels:
app: zero-server
spec:
imagePullSecrets:
- name: my-aliyun
containers:
- name: zero-server
image: crpi-pqfsp88s5zx2zwfq.cn-hangzhou.personal.cr.aliyuncs.com/devstar/devstar_introduction:v1
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8889
volumeMounts:
- name: timezone
mountPath: /etc/localtime
volumes:
- name: timezone
hostPath:
path: /usr/share/zoneinfo/Asia/Shanghai
apiVersion: v1
kind: Service
metadata:
name: zero-server-svc
namespace: zero-server
spec:
ports:
- port: 8889
targetPort: 8889
nodePort: 30115
selector:
app: zero-server
type: NodePort

21
nginx.conf Normal file
View File

@@ -0,0 +1,21 @@
server {
listen 80;
listen [::]:80;
server_name localhost;
access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
# 新增下面这句其他是默认nginx配置
# 解决部分前端框架的路由问题在浏览器刷新报错404
try_files $uri $uri/ /index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}