项目目录结构如下
对此项目,使用Jenkins构建dockers镜像
步骤如下:
1、安装Jenkins和docker,具体安装步骤,自行度娘把,在此不详述了。
2、Jenkins安装插件Gradle Plugin、Dockerer Plugin、Git Plugin
3、Jenkins全局工具配置
4、新建job,配置job
5、创建部署文件
进入部署文件目录
build.sh
docker-compose -f docker-compose.yaml up -d --build
docker-compose.yaml
1 version: '3' 2 services: 3 panda-api: 4 image: panda-api:1011 5 #build: ./ 6 restart: always 7 environment: 8 TZ: 'Asia/Shanghai' 9 ENV: ${ENV:-dev} 10 PORT: ${SERVER_PORT:-8580} 11 SPRING_PROFILES_ACTIVE: ${SPRING_PROFILES_ACTIVE:-dev} 12 ports: 13 - ${SERVER_PORT:-8580}:8580 14 volumes: 15 - "./docker-compose/opt/logs:/opt/logs"
Dockerfile
1 FROM airdock/oracle-jdk 2 3 ENV TZ='Asia/Shanghai' 4 5 WORKDIR /opt/ 6 7 COPY /opt/data/jenkins/var/workspace/panda_api/build/libs/panda_api.jar /opt/panda_api.jar 8 COPY /opt/data/jenkins/var/workspace/panda_api/docker/entrypoint.sh / 9 10 RUN chmod +x /entrypoint.sh 11 12 ENTRYPOINT ["/entrypoint.sh"]
entrypoint.sh
1 #!/bin/sh 2 3 export JAVA_OPTS="-Djava.security.egd=file:/dev/./urandom" 4 5 java -jar /opt/panda_api.jar --server.port=${PORT:-8580}
6、接下来就可以开始构建部署,点击构建
构建成功日志如图所示
查看构建的镜像
查看运行中的容器
到此,部署成功,这是基本流程,备份镜像等功能还需待完善,时间匆忙先简要把流程写一下