This commit is contained in:
64
.drone.yml
Normal file
64
.drone.yml
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
kind: pipeline # 定义一个管道
|
||||||
|
type: docker # 当前管道的类型
|
||||||
|
name: build # 当前管道的名称
|
||||||
|
|
||||||
|
steps: # 定义管道的执行步骤
|
||||||
|
# - name: build-project # 步骤名称
|
||||||
|
# image: node:18-bullseye # 当前步骤使用的镜像
|
||||||
|
# volumes:
|
||||||
|
# - name: node_modules
|
||||||
|
# path: /drone/src/node_modules
|
||||||
|
# commands: # 当前步骤执行的命令
|
||||||
|
# - pwd
|
||||||
|
# - npm config set registry https://registry.npm.taobao.org
|
||||||
|
# - npm i
|
||||||
|
|
||||||
|
- name: build-image
|
||||||
|
image: plugins/docker
|
||||||
|
depends_on: [clone]
|
||||||
|
settings:
|
||||||
|
username:
|
||||||
|
from_secret: docker_username
|
||||||
|
password:
|
||||||
|
from_secret: docker_passwd
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
mirror: https://fpswa5tm.mirror.aliyuncs.com
|
||||||
|
registry: https://git.liliyamol.cn:8081
|
||||||
|
repo: git.liliyamol.cn:8081/mol/my-dev-server
|
||||||
|
# auto_tag: true
|
||||||
|
tags: [latest]
|
||||||
|
|
||||||
|
---
|
||||||
|
kind: pipeline # 定义一个管道
|
||||||
|
type: docker # 当前管道的类型
|
||||||
|
name: deploy # 当前管道的名称
|
||||||
|
|
||||||
|
depends_on:
|
||||||
|
- build
|
||||||
|
|
||||||
|
clone:
|
||||||
|
disable: true
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: deploy-project
|
||||||
|
image: appleboy/drone-ssh
|
||||||
|
settings:
|
||||||
|
host:
|
||||||
|
from_secret: host
|
||||||
|
username:
|
||||||
|
from_secret: server_username # 使用secrets
|
||||||
|
key:
|
||||||
|
from_secret: server_key
|
||||||
|
port: 22
|
||||||
|
command_timeout: 2m
|
||||||
|
secrets: [docker_username, docker_passwd]
|
||||||
|
script:
|
||||||
|
- echo ==-----==开始部署==-----==
|
||||||
|
- docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWD git.liliyamol.cn:8081
|
||||||
|
- docker pull git.liliyamol.cn:8081/mol/my-dev-server:latest
|
||||||
|
- list=$(docker ps -a | grep my-dev-server* | awk '{print $1}')
|
||||||
|
- test "$list" = "" && echo "none my-dev-server containers running" || docker stop $list && docker container rm $list
|
||||||
|
# 过滤出dockerImages的id, 删除none镜像
|
||||||
|
- docker run -d -p 18000:22 -v /mnt/data/opt/dev-server/.vscode-server:/root/.vscode-server -v /mnt/data/opt/dev-server/data:/data -v /mnt/data/opt/dev-server/.ssh:/root/.ssh -e ROOT_PASSWD=heiyu518 -e GIT_USER=mol -e GIT_EMAIL=hiiragi10073@163.com -e DOCKER_USER=mol10073 -e DOCKER_PASSWD=5opmbU2YvhTMwB --restart=always --name=my-dev-server git.liliyamol.cn:8081/mol/my-dev-server:latest
|
||||||
|
- docker rmi $(docker images | grep "none" | awk '{print $3}')
|
||||||
|
- echo ==-----==部署成功==-----==
|
15
Dockerfile
15
Dockerfile
@ -13,7 +13,8 @@ ARG PROXY
|
|||||||
# ENV http_proxy=${PROXY}
|
# ENV http_proxy=${PROXY}
|
||||||
|
|
||||||
# 安装基础工具与配置文件
|
# 安装基础工具与配置文件
|
||||||
RUN export http_proxy=${PROXY} && \
|
RUN echo "安装基础工具与配置文件" && \
|
||||||
|
export http_proxy=${PROXY} && \
|
||||||
export https_proxy=${PROXY} && \
|
export https_proxy=${PROXY} && \
|
||||||
apt-get update && \
|
apt-get update && \
|
||||||
# 时区
|
# 时区
|
||||||
@ -31,7 +32,8 @@ RUN export http_proxy=${PROXY} && \
|
|||||||
touch info.log
|
touch info.log
|
||||||
|
|
||||||
# 安装 node 环境
|
# 安装 node 环境
|
||||||
RUN export http_proxy=${PROXY} && \
|
RUN echo "安装 node 环境" && \
|
||||||
|
export http_proxy=${PROXY} && \
|
||||||
export https_proxy=${PROXY} && \
|
export https_proxy=${PROXY} && \
|
||||||
# 安装 brew
|
# 安装 brew
|
||||||
curl -ofsSL install.sh https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh | bash && \
|
curl -ofsSL install.sh https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh | bash && \
|
||||||
@ -47,7 +49,8 @@ RUN export http_proxy=${PROXY} && \
|
|||||||
npm i -g live-server
|
npm i -g live-server
|
||||||
|
|
||||||
# 安装 python 环境
|
# 安装 python 环境
|
||||||
RUN export http_proxy=${PROXY} && \
|
RUN echo "安装 python 环境" && \
|
||||||
|
export http_proxy=${PROXY} && \
|
||||||
export https_proxy=${PROXY} && \
|
export https_proxy=${PROXY} && \
|
||||||
apt update && \
|
apt update && \
|
||||||
apt install -y software-properties-common && \
|
apt install -y software-properties-common && \
|
||||||
@ -55,13 +58,15 @@ RUN export http_proxy=${PROXY} && \
|
|||||||
apt install -y python3.8 python3.8-dev python3.8-venv python3-pip python3-wheel
|
apt install -y python3.8 python3.8-dev python3.8-venv python3-pip python3-wheel
|
||||||
|
|
||||||
# 安装 docker 环境
|
# 安装 docker 环境
|
||||||
RUN export http_proxy=${PROXY} && \
|
RUN echo "安装 docker 环境" && \
|
||||||
|
export http_proxy=${PROXY} && \
|
||||||
export https_proxy=${PROXY} && \
|
export https_proxy=${PROXY} && \
|
||||||
apt update && \
|
apt update && \
|
||||||
apt install -y docker.io
|
apt install -y docker.io
|
||||||
|
|
||||||
# 配置 ssh
|
# 配置 ssh
|
||||||
RUN rm -f /etc/ssh/ssh_host_rsa_key && \
|
RUN echo "配置 ssh" && \
|
||||||
|
rm -f /etc/ssh/ssh_host_rsa_key && \
|
||||||
ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N '' && \
|
ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N '' && \
|
||||||
rm -f /etc/ssh/ssh_host_dsa_key && \
|
rm -f /etc/ssh/ssh_host_dsa_key && \
|
||||||
ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N '' && \
|
ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N '' && \
|
||||||
|
@ -5,11 +5,19 @@ if [ -n "$ROOT_PASSWD" ]; then
|
|||||||
echo "密码设置完毕" >> /app/info.log
|
echo "密码设置完毕" >> /app/info.log
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "$GIT_USER" ] && [ -n "$GIT_EMAIL" ]; then
|
if [ -e "/root/.gitconfig" ]; then
|
||||||
|
echo "git配置文件已存在" >> /app/info.log
|
||||||
|
else
|
||||||
touch /root/.gitconfig
|
touch /root/.gitconfig
|
||||||
|
echo "git配置文件已创建" >> /app/info.log
|
||||||
|
fi
|
||||||
|
|
||||||
|
# git使用openssh的shh程序
|
||||||
|
git config --global core.sshCommand "/usr/bin/ssh"
|
||||||
|
|
||||||
|
if [ -n "$GIT_USER" ] && [ -n "$GIT_EMAIL" ]; then
|
||||||
git config --global user.name "$GIT_USER"
|
git config --global user.name "$GIT_USER"
|
||||||
git config --global user.email "$GIT_EMAIL"
|
git config --global user.email "$GIT_EMAIL"
|
||||||
git config --global core.sshCommand "/usr/bin/ssh"
|
|
||||||
echo "git 用户已设置完毕" >> /app/info.log
|
echo "git 用户已设置完毕" >> /app/info.log
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -19,5 +27,6 @@ if [ -n "$DOCKER_USER" ] && [ -n "$DOCKER_PASSWD" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
service ssh start >> /app/info.log
|
service ssh start >> /app/info.log
|
||||||
|
ssh-agent bash >> /app/info.log
|
||||||
|
|
||||||
tail -f /app/info.log
|
tail -f /app/info.log
|
||||||
|
Reference in New Issue
Block a user