# docker-demo **Repository Path**: 00fly/docker-demo ## Basic Information - **Project Name**: docker-demo - **Description**: 演示:docker镜像的打包分发与上传镜像仓库,通过crontab调用shell脚本实现定时修改git代码并自动提交 - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-03-01 - **Last Updated**: 2025-08-14 ## Categories & Tags **Categories**: Uncategorized **Tags**: SpringBoot, Docker, shell, Git ## README # war && docker镜像自动更新部署运行演示项目 #### pom如何打开docker镜像构建与推送 - 打开goals节点, 将docker build、push绑定到package阶段 - 默认使用本地docker环境,使用远程docker环境需打开dockerHost节点 #### 脚本与配置说明 - reload-demo.sh war运行脚本 - restart.sh docker镜像容器脚本 nignx 负载均衡部分核心配置脚本为: ``` #设定负载均衡的服务器列表 upstream test { #weigth参数表示权值,权值越高被分配到的几率越大 server 127.0.0.1:8080 weight=5; server 127.0.0.1:8081 weight=5; server 127.0.0.1:8082 weight=5; } server { listen 80; server_name test.001fly.top; rewrite ^(.*) https://$server_name$1 permanent; } server { listen 443 ssl http2; server_name test.001fly.top; #加载SSL证书配置 include conf.d/ssl_certificate.conf; location /user/ { proxy_pass http://test; client_max_body_size 5m; } 。。。 } ``` --- 为方便演示,已经移除J2Cache缓存功能。 # 非docker运行apidoc **[apidoc](https://apidocjs.com/) 是一个可以将源代码中的注释直接生成api接口文档的工具,对现有代码无侵入** ## 1.安装 ``` #安装apidoc之前要先安装node.js、npm yum install -y nodejs yum install -y npm #安装apidoc npm install -g apidoc #验证 apidoc -v apidoc -h ``` ## 2.生成文档 ```shell #扫描src目录在doc目录生成接口文档(default) apidoc apidoc -i src -o doc #扫描src目录在apidoc目录生成接口文档 apidoc -i src -o apidoc ``` # 其他 ## 1.git更新 **移动git-update.sh到上一级目录,执行git仓库更新** git-update.sh ```shell #!/bin/sh for dir in $(ls -d */) do if [ -d "$dir"/.git ]; then echo "$dir" && cd "$dir" && git pull && cd .. fi done ``` ## 2.git推送 git-push.sh ```shell #!/bin/sh if [ -n "$(git status -s)" ];then git add . git commit -m "update: `date +"%Y-%m-%d %H:%M:%S"` auto commit" git push fi ``` ## 3.配置个人令牌 为了避免每次push输入密码,考虑配置个人令牌,以[https://gitcode.com/00fly](https://gitcode.com/00fly)为例: **git repo 目录执行** ```shell #当前目录保存 git config user.name userName git config user.email userEmail git config credential.helper store #全局保存 git config --global user.name userName git config --global user.email userEmail git config --global credential.helper store #修改本地文件后执行,会要求输入用户名、个人令牌 sh git-push.sh ``` ## 4.服务器git源码下载 ```shell mkdir /work/gitee && cd /work/gitee git clone https://gitee.com/00fly/docker-demo.git ``` ## 5. 配置crontab定时任务 ```shell #查看作业任务 crontab -l 0 */4 * * * cd /work/gitee&&sh all-in-one-cron-push.sh>>/work/logs/test.log */5 * * * * cd /work/gitee&&sh run.sh>>/work/logs/run.log #编辑作业任务 crontab -e ``` 举例如下: ```0 */1 * * * cd /work/gitee&&sh all-in-one-cron-push.sh``` 每1小时执行一次 ```*/5 * * * * cd /work/gitee&&sh all-in-one-cron-push.sh```每5分钟执行一次 ```0 */4 * * * cd /work/gitee&&sh all-in-one-cron-push.sh```每4小时执行一次 **```注意:直接写为0 */4 * * * /work/gitee/all-in-one-cron-push.sh,crontab执行pwd结果为/root```**