Gitlab集成jenkins及docker自动化部署教程
能实现提交代码到gitlab后,我们只需要合并代码到指定分支就可以上Jenkins自动拉取最新代码并重新构建部署
1、登录Jenkins点击如下加号新增视图
2、gitlab配置Jenkins成员,供Jenkins使用
3、Jenkins配置选择如下选项
代码如下:
REPOSITORY=192.168.1.240:5000/project_name/service_name:test1 cat > Dockerfile << EOF #基础镜像,如果本地没有,会从远程仓库拉取。 FROM openjdk:8 #声明了容器应该打开的端口并没有实际上将它打开 EXPOSE 10011 # 将jar包添加到容器中并更名为app.jar ADD target/service_name-2.0.0-SNAPSHOT.jar app.jar #指定容器启动时要执行的命令,但如果存在CMD指令,CMD中的参数会被附加到ENTRYPOINT指令的后面 ENTRYPOINT ["java","-Xms512m","-Xmx1024m","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar", "--spring.profiles.active=test1"] EOF # 构建镜像 docker build -t $REPOSITORY . docker login -u admin -p 123456 192.168.1.240:5000 # 上传镜像 docker push $REPOSITORY
Docker环境部署代码如下:
REPOSITORY=192.168.1.240:5000/project_name/service_name:test1 docker login -u admin -p 123456 192.168.1.240:5000 docker pull $REPOSITORY docker rmi $(docker images | grep "none" | awk '{print $3}') mkdir -p /usr/local/docker/project_name/service_name cd /usr/local/docker/project_name/service_name cat > docker-compose.yml<< EOF version: "3.7" services: kxkd-push-service: image: $REPOSITORY restart: always container_name: service_name logging: driver: "json-file" options: max-size: "1G" environment: - TZ=Asia/Shanghai ports: - "10011:10011" volumes: - "/usr/local/docker/project_name/service_name/logs:/logs" - "/usr/local/docker/project_name/service_name/sensors:/usr/local/docker/kxkd" - "/usr/local/docker/project_name/service_name/fonts:/usr/local/openjdk-8/jre/lib/fonts" EOF docker-compose down docker-compose up -d
4、配置gitlab环境
5、上面就已经配置完成了,接下来可以测试自动部署环境
标签:name,service,部署,Gitlab,project,Jenkins,jenkins,docker From: https://www.cnblogs.com/luolei0120/p/17059490.html