deploy log
sh
# 当前目录
docker build -t my-app:latest .
# -f:指定 Dockerfile 路径
# ./docker:上下文目录(通常是包含 app 源码和 Dockerfile 的目录)
docker build -f ./docker/Dockerfile -t my-app:dev ./docker
# 指定目标构建阶段
docker build --traget builder -t my-app:latest .23101 / hlx-demo-11ty
dockerfile
# 构建
FROM node:22-alpine AS builder
WORKDIR /app
COPY . .
RUN npm install --registry https://registry.npmmirror.com && \
npm run build
# 生产
FROM nginx:1.24-alpine
COPY --from=builder /app/dist/ /opt
COPY nginx.conf /etc/nginx/conf.d/default.conf
# CMD ["nginx", "-g", "daemon off;"]
EXPOSE 23101nginx
server {
listen 23101;
root /opt;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
}25001 / hlx2
open hlx doc + hlx demo
nginx
server {
listen 25001;
location / {
root /opt/doc;
index index.html;
try_files $uri $uri/ /index.html;
}
}Dockerfile
# 构建环境
FROM node:22-alpine AS builder
WORKDIR /app
COPY . .
RUN corepack enable && corepack prepare pnpm@8.15.5 --activate
RUN pnpm install --registry https://registry.npmmirror.com && pnpm build
# 生产环境
FROM nginx:1.24-alpine
COPY --from=builder /app/packages/doc/dist /opt/doc
COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 25001yml
kind: pipeline
type: exec
name: hlx2-local
platform:
os: linux
arch: amd64
steps:
- name: 编译image
commands:
- docker build -t hlx2-local .
- name: 运行image
commands:
- docker stop hlx2 || true
- docker rm hlx2 || true
- docker run -dit -p 25001:25001 --name hlx2 hlx2-local
---
kind: pipeline
type: docker
name: hlx2-acr
steps:
- name: 构建并推送镜像
image: plugins/docker
settings:
registry: registry.cn-chengdu.aliyuncs.com
repo: registry.cn-chengdu.aliyuncs.com/qins-img/hlx2
tags:
- ${DRONE_BUILD_NUMBER}
username:
from_secret: username
password:
from_secret: password
- name: 部署到服务器
image: appleboy/drone-ssh
settings:
host:
from_secret: ssh_host
username:
from_secret: ssh_user
password:
from_secret: ssh_pwd
port: 22
script:
- echo "开始拉取镜像并重启服务..."
# 使用非交互式登录
- echo "$acr_password" | docker login -u $acr_username --password-stdin registry.cn-chengdu.aliyuncs.com
# 拉取镜像
- docker pull registry.cn-chengdu.aliyuncs.com/qins-img/hlx2:${DRONE_BUILD_NUMBER}
# 停止并删除旧容器
- docker stop hlx2 || true
- docker rm hlx2 || true
# 运行新容器
- docker run -dit --name hlx2 -p 25001:25001 registry.cn-chengdu.aliyuncs.com/qins-img/hlx2:${DRONE_BUILD_NUMBER}
environment:
acr_username:
from_secret: username
acr_password:
from_secret: password测试
sh
docker run -dit --rm -p 25001:25001 --name testhlx2 hlx225002 / wanx-demo_read-aloud
hono + vue
特点
hono 为 vue 做网管路由,没有使用 nginx。
只适合简单的 demo 部署方式
vue2 在 docker 打包非常坑,会被 node 卡报错!!!
dockerfile
FROM registry.cn-chengdu.aliyuncs.com/qins-img/node:22-alpine AS builder
WORKDIR /app
COPY . .
RUN npm install -g pnpm@10.7.1 --registry=https://registry.npmmirror.com
RUN pnpm install --registry https://registry.npmmirror.com && pnpm build
FROM registry.cn-chengdu.aliyuncs.com/qins-img/node:22-alpine AS runner
WORKDIR /app
COPY --from=builder /app/packages/api/dist /app/dist
COPY --from=builder /app/packages/api/web /app/web
COPY --from=builder /app/packages/api/package.json /app/package.json
RUN npm install --production --registry https://registry.npmmirror.com
EXPOSE 25002
CMD ["node", "/app/dist/index.js"]yml
kind: pipeline
type: docker
name: wanx_机器人_朗读
trigger:
branch:
include:
- master
steps:
- name: 构建并推送镜像
image: plugins/docker
settings:
registry: registry.cn-chengdu.aliyuncs.com
repo: registry.cn-chengdu.aliyuncs.com/qins-img/wanx-demo_read-aloud
tags:
- ${DRONE_BUILD_NUMBER}
username:
from_secret: acr_username
password:
from_secret: acr_password
- name: 部署到服务器
image: appleboy/drone-ssh
settings:
host:
from_secret: ssh_host
username:
from_secret: ssh_user
password:
from_secret: ssh_pwd
port: 22
script:
- echo "开始拉取镜像并重启服务..."
# 使用非交互式登录
# - echo "$acr_password" | docker login -u $acr_username --password-stdin registry.cn-chengdu.aliyuncs.com
# 拉取镜像
- docker pull registry.cn-chengdu.aliyuncs.com/qins-img/wanx-demo_read-aloud:${DRONE_BUILD_NUMBER}
# 停止并删除旧容器
- docker stop wanx-demo_read-aloud || true
- docker rm wanx-demo_read-aloud || true
# 运行新容器
- docker run -dit --name wanx-demo_read-aloud -p 25002:25002 --network nginx-net registry.cn-chengdu.aliyuncs.com/qins-img/wanx-demo_read-aloud:${DRONE_BUILD_NUMBER}
environment:
acr_username:
from_secret: acr_username
acr_password:
from_secret: acr_passwordnginx
server {
listen 80;
listen [::]:80;
server_name w25.q123q.cc;
location /read-aloud/ {
proxy_pass http://wanx-demo_read-aloud:25002;
# 传递必要的请求头
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}