Jenkins自動化部署配置-pom、yml、Dockerfile的配置
阿新 • • 發佈:2019-01-23
1.專案中對應的pom檔案配置:
<directory>${project.basedir}/target</directory>
<docker.image.prefix>192.168.1.230:5000/platform</docker.image.prefix> <docker.plugin.version>1.0.0</docker.plugin.version>
<!--新增docker-maven-plugin外掛--> <build> <finalName>${project.artifactId}</finalName><plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <version>${docker.plugin.version}</version> <configuration> <imageName>${docker.image.prefix}/${project.artifactId}</imageName> <dockerDirectory>${project.basedir}</dockerDirectory><resources> <resource> <targetPath>/</targetPath> <directory>${project.build.directory}</directory> <include>${project.build.finalName}.jar</include> </resource> </resources> </configuration> </plugin> </plugins> </build>
2.專案中對應的yml檔案配置:
--- spring: profiles: docker application: name: os-search server: port: ${{SERVER_PORT}:9301} eureka: client: serviceUrl:defaultZone: ${ADDITIONAL_EUREKA_SERVER_LIST}
3.linux伺服器中(部署docker和Jenkins的伺服器)對應的配置
專案中的yml檔案執行的時候會從linux伺服器中的yml檔案中去獲取相關配置資訊,
比如- SPRING_PROFILES_ACTIVE=docker
- SERVER_PORT=9301
#商品匹配搜尋介面
os-search:
container_name: os-search
image: 192.168.1.230:5000/platform/os-search
ports:
- "9301:9301"
environment:
- ADDITIONAL_EUREKA_SERVER_LIST=http://192.168.1.236:8201/eureka/
- SPRING_PROFILES_ACTIVE=docker
- SERVER_PORT=9301
# links:
# - cloud-eureka
4.專案中Dockerfile檔案的配置
FROM java:8-jre-alpine VOLUME /tmp ADD target/*.jar app.jar RUN sh -c 'touch /app.jar' RUN echo $(date) > /image_built_at ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar","--spring.profiles.active=${SPRING_PROFILES_ACTIVE}"]