后续下载的内容 放在里边方便管理
cd /
mkdir docker
cd docker
mkdir maven
mkdir jenkins
mkdir java
mkdir registry
不在赘述 前往官网有安装命令 宝塔下载页面
修改docker 配置 可远程访问
vim /lib/systemd/system/docker.service
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
# ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H fd:// -- containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always
重载配置重启
systemctl daemon-reload && systemctl restart docker
选择版本下载 如:apache-maven-3.8.6-bin.tar.gz
上传至服务器/docker/maven目录下 解压
tar –xvf apache-maven-3.8.6-bin.tar.gz
创建仓库保存目录
mkdir repository
修改maven settings.xml 文件
cd /docker/maven/apache-maven-3.8.6/conf
vim settings.xml
<mirror>
<id>alimavenid>
<name>aliyun mavenname>
<url>http://maven.aliyun.com/nexus/content/groups/public/url>
<mirrorOf>centralmirrorOf>
mirror>
<localRepository>/docker/maven/repository/repolocalRepository>
选择版本下载 如:jdk-8u351-linux-aarch64.tar.gz
上传至服务器/docker/java目录下 解压
tar –xvf jdk-8u351-linux-aarch64.tar.gz
下载镜像
docker search registry
docker pull registry
启动容器
docker run -d -v /docker/registry:/var/lib/registry -p 5000:5000 --name myregistry registry:latest
访问http://ip:5000/v2/_catalog 看到 {“repositories”:[]} 表示成功
修改/etc/docker/daemon.json 第二行 没有的话可以不加 可以去docker镜像服务申请 详见docker镜像私服
{
"insecure-registries":["192.168.0.107:5000"],
"registry-mirrors": ["**********"]
}
重启docker
systemctl restart docker
拉取jenkins 镜像
docker search jenkins
挂载容器卷启动容器
docker run -d -p 18080:8080 -p 50000:50000 --privileged=true -u root -v /docker/jenkins:/var/jenkins_home
-v /docker/maven/apache-maven-3.8.6:/usr/local/apache-maven
-v /docker/java/jdk1.8.0_341:/usr/local/java/jdk1.8
-v /var/run/docker.sock:/var/run/docker.sock
-v /usr/bin/docker:/usr/bin/docker
-v /www/wwwroot:/www/wwwroot
-e JAVA_OPTS=-Duser.timezone=Asia/Shanghai --name jenkins jenkins
这两个解决jenkins shell docker命令找不到问题
-v /var/run/docker.sock:/var/run/docker.sock
-v /usr/bin/docker:/usr/bin/docker
这个为前端项目部署创建 挂载目录
-v /www/wwwroot:/www/wwwroot
解决离线问题
cd /docker/jenkins
vim hudson.model.UpdateCenter.xml
改为清华镜像
<sites>
<site>
<id>defaultid>
<url>https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/current/update-center.jsonurl>
site>
sites>
解决插件安装慢问题
替换 default.json内的内容
cd /docker/jenkins/updates
sed -i 's/www.google.com/www.baidu.com/g' default.json
sed -i 's/updates.jenkins-ci.org\/download/mirrors.tuna.tsinghua.edu.cn\/jenkins/g' default.json
#重启 Jenkins
docker restart jenkins的容器id
登录 开始安装依赖
原始密码在initialAdminPassword文件内
cd /docker/jenkins/secrets
cat initialAdminPassword
cd /docker/jenkins/updates
touch hudson.plugins.nodejs.tools.NodeJSInstaller
vim hudson.plugins.nodejs.tools.NodeJSInstaller
{
"list":[
{
"id":"12.16.3",
"name":"NodeJS 12.16.3",
"url":"https://nodejs.org/dist/v12.16.3/"
},
{
"id":"9.9.0",
"name":"NodeJS 9.9.0",
"url":"https://nodejs.org/dist/v9.9.0/"
},
{
"id":"9.8.0",
"name":"NodeJS 9.8.0",
"url":"https://nodejs.org/dist/v9.8.0/"
},
{
"id":"9.7.1",
"name":"NodeJS 9.7.1",
"url":"https://nodejs.org/dist/v9.7.1/"
}
]
}
pom.xml配置
<build>
<finalName>appfinalName>
<plugins>
<plugin>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-maven-pluginartifactId>
plugin>
<plugin>
<groupId>com.spotifygroupId>
<artifactId>docker-maven-pluginartifactId>
<version>1.2.0version>
<configuration>
<imageName>192.168.0.107:5000/${project.artifactId}:${project.version}imageName>
<baseImage>jdk1.8baseImage>
<entryPoint>["java", "-jar", "/${project.build.finalName}.jar"]entryPoint>
<resources>
<resource>
<targetPath>/targetPath>
<directory>${project.build.directory}directory>
<include>${project.build.finalName}.jarinclude>
resource>
resources>
<dockerHost>http://192.168.0.107:2375dockerHost>
configuration>
plugin>
plugins>
build>
echo "在指定docker目录创建Dockerfile文件用于生成docker容器"
cd yshop-app/target
cat>Dockerfile<FROM jdk1.8
ADD /app.jar //
ENTRYPOINT ["java", "-jar", "/app.jar"]
# ENTRYPOINT ["java", "-jar", "/admin.jar",">> ","/var/logs/log.log","&"]
EOF
echo "清理已有容器及镜像资源"
container="yshop-app"
image=${container}
if docker ps | grep ${container} ;then
docker stop ${container}
fi
if docker ps -a | grep ${container};then
docker rm ${container}
fi
if docker images | grep ${image};then
docker rmi ${image}
fi
echo "镜像制作"
docker build -t ${image} .
echo "容器运行"
docker run -d --restart=always --name ${container} -v /usr/local/project/tidePlayMall/app/logs:/var/logs -p 8008:8008 ${image} -Duser.timezone=GMT+8
# docker run -d --restart=always --name ${container} -v /usr/local/project/tidePlayMall/admin/avatar:/usr/local/project/tidePlayMall/admin/avatar -v /usr/local/project/tidePlayMall/admin/file:/usr/local/project/tidePlayMall/admin/file -v /usr/local/project/tidePlayMall/admin/logs:/var/logs -p 8001:8001 ${image} -Duser.timezone=GMT+8
echo "在指定docker目录创建Dockerfile文件用于生成docker容器"
cd yz-server/target
cat>Dockerfile<<EOF
FROM jdk1.8.0_341
ADD /yz-server.jar //
ENTRYPOINT ["java", "-jar", "/yz-server.jar"]
# ENTRYPOINT ["java", "-jar", "/admin.jar",">> ","/var/logs/log.log","&"]
EOF
echo "清理已有容器及镜像资源"
container="yz-server"
image=${container}
if docker ps | grep ${container} ;then
docker stop ${container}
fi
if docker ps -a | grep ${container};then
docker rm ${container}
fi
if docker images | grep ${image};then
docker rmi ${image}
fi
echo "镜像制作"
docker build -t ${image} .
echo "容器运行"
docker run -d --restart=always --name ${container} -p 48080:48080 -e TZ=Asia/Shanghai -v /usr/local/project/groupBuy/api/:/usr/local/project/groupBuy/api/ ${image}
配置 Webhook
执行sell
node -v
npm install
rm -rf ./dist/* #移除工作区dist文件
npm run-script build #打包项目
rm -rf /www/wwwroot/192.168.0.107/dist/* #删除/www/wwwroot/192.168.0.107/dist上一次构建文件
cp -rf ./dist/* /www/wwwroot/192.168.0.107/dist #将打包后的dist文件拷贝 到/www/wwwroot/192.168.0.107/dist ,/www/wwwroot/192.168.0.107/dist为nginx文件目录
node -v
npm install
rm -rf ./dist/* #移除工作区dist文件
npm run build:prod #打包项目
distDir="/www/wwwroot/******/dist"
if [ -d $distDir ]
then
echo "dist路径已存在"
else
mkdir $distDir
fi
rm -rf /www/wwwroot/******/dist/* #删除/www/wwwroot/******/dist上一次构建文件
cp -rf ./dist/* /www/wwwroot/******/dist #将打包后的dist文件拷贝 到/www/wwwroot/******/dist ,/www/wwwroot/******/dist为nginx文件目录
其他的git地址配置 Webhook 都一样