下面只是使用docker compose 启动容器docker-compose.yml文件
version: '3'
services:
drone-server:
restart: always
image: drone/drone:2
ports:
- "3000:80"
volumes:
- /home/dorne/lib/drone:/var/lib/drone/
- /home/dorne/data:/data/
environment:
- DRONE_GITEA_SERVER=http://域名:端口
- DRONE_GITEA_CLIENT_ID=gitea的密钥id
- DRONE_GITEA_CLIENT_SECRET=gitea的密钥
- DRONE_SERVER_HOST=域名:端口
- DRONE_SERVER_PROTO=http
- DRONE_RPC_SECRET=随机生成的32位字符
- DRONE_GIT_ALWAYS_AUTH=true
- DRONE_GIT_USERNAME=root
- DRONE_GIT_PASSWORD=123456
- DRONE_USER_CREATE=username:账户名,admin:true
drone-runner-docker:
restart: always
image: drone/drone-runner-docker:1
ports:
- "3002:3000"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
environment:
- DRONE_RPC_PROTO=http
- DRONE_RPC_HOST=drone-server
- DRONE_RPC_SECRET=随机生成的32位字符
- DRONE_RUNNER_NAME=drone-runner-docker
- DRONE_RUNNER_CAPACITY=2
version: "3"
networks:
gitea:
external: false
services:
server:
image: gitea/gitea:1.16.7
container_name: gitea
environment:
- USER_UID=1000
- USER_GID=1000
restart: always
networks:
- gitea
volumes:
- /home/data:/data
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
ports:
- "8090:3000"
- "8222:22"
启动流水线的.dron.yml文件
kind: pipeline
name: default
steps:
- name: deploy-to-server
image: appleboy/drone-ssh
settings:
host: "ip"
username: "root"
password: "宿主机密码"
port: 22
script:
- rm -rf /home/vueProject/vue3_demo
- cd /home/vueProject
- git clone 项目地址
- echo "当前构建分支:${DRONE_BRANCH}"
- cd /home/vueProject/vue3_demo
- git checkout ${DRONE_BRANCH}
- git pull origin ${DRONE_BRANCH}
- ../deploy.sh
- echo "构建分支 ${DRONE_BRANCH} successful!"
- deploy.sh脚本
```yaml
PROJECT_DIR="/home/vueProject/vue3_demo"
IMAGE_NAME="vue3_demo-application"
CONTAINER_NAME="vue3demo-application"
DOCKERFILE_PATH="./Dockerfile"
SOURCE="dist/index.html"
cd $PROJECT_DIR
echo "使用npm install 安装"
cnpm install
echo "在使用npm打包项目"
cnpm run build
echo "打包完成!"
if [ ! -f "$SOURCE" ]; then
echo "npm 构建失败"
exit 1
fi
echo "正在停止旧的 Docker 容器..."
docker stop $CONTAINER_NAME
echo "正在删除旧的 Docker 容器..."
docker rm $CONTAINER_NAME
echo "正在删除旧的 Docker 镜像..."
docker rmi $IMAGE_NAME
echo "正在构建新的 Docker 镜像..."
docker build -t $IMAGE_NAME -f $DOCKERFILE_PATH .
echo "正在启动新的 Docker 容器..."
docker run -d --name $CONTAINER_NAME --network=my-network -p 80:80 -v /home/vueProject/nginx.conf:/etc/nginx/nginx.con $IMAGE_NAME
if [ "$(docker ps -q -f name=$CONTAINER_NAME)" ]; then
echo "新的 Docker 容器 $CONTAINER_NAME 启动成功!"
else
echo "启动新的 Docker 容器失败。"
exit 1
fi