Skip to content

Commit

Permalink
购物车微服务迁移至docker
Browse files Browse the repository at this point in the history
build supermarket-cart image, rename docker to start_up
  • Loading branch information
ZongXR committed Mar 26, 2022
1 parent 5ea3b87 commit ef9177e
Show file tree
Hide file tree
Showing 39 changed files with 75 additions and 10 deletions.
9 changes: 9 additions & 0 deletions cart/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM openjdk:11.0.7-jre
MAINTAINER ZongXiangrui<zxr@tju.edu.cn>
ENV APP_PORT=10005
EXPOSE ${APP_PORT}
ARG JAR_FILE
WORKDIR /opt
COPY target/${JAR_FILE} /opt/app.jar
CMD ["java", "-version"]
ENTRYPOINT ["java", "-jar", "/opt/app.jar"]
63 changes: 58 additions & 5 deletions cart/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>cart</artifactId>

<artifactId>${project.parent.artifactId}-cart</artifactId>
<groupId>com.supermarket.cart</groupId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<dependencies>
<!-- 共享资源 -->
<dependency>
<groupId>com.supermarket</groupId>
<artifactId>common</artifactId>
<scope>system</scope>
<systemPath>${project.basedir}/../common/target/supermarket-common.jar</systemPath>
<groupId>com.supermarket.common</groupId>
<artifactId>supermarket-common</artifactId>
<version>1.0-SNAPSHOT</version>
<exclusions>
<exclusion>
Expand Down Expand Up @@ -48,6 +51,16 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- mybatis连接spring -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
Expand Down Expand Up @@ -99,7 +112,47 @@
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>

<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>1.4.13</version>

<executions>
<execution>
<id>build-image</id>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
<execution>
<id>push-image</id>
<phase>deploy</phase>
<goals>
<goal>push</goal>
</goals>
</execution>
</executions>

<configuration>
<repository>zongxr/${project.artifactId}</repository>
<tag>${project.version}</tag>
<buildArgs>
<JAR_FILE>${project.build.finalName}.jar</JAR_FILE>
</buildArgs>
</configuration>
</plugin>
</plugins>
</build>

</project>
7 changes: 3 additions & 4 deletions cart/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
server.port=10005
server.port=${APP_PORT}

# Êý¾ÝÔ´
#spring.datasource.url=jdbc:mysql://localhost:3306/supermarket?useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true&serverTimezone=Asia/Shanghai
spring.datasource.url=jdbc:mysql://10.42.83.8:8066/supermarket?useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true&serverTimezone=Asia/Shanghai
spring.datasource.url=jdbc:mysql://mycat:8066/supermarket?useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true&serverTimezone=Asia/Shanghai
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
Expand All @@ -14,4 +13,4 @@ mybatis.configuration.map-underscore-to-camel-case=true

# ÅäÖÃ΢·þÎñ
spring.application.name=cart
eureka.client.service-url.defaultZone=http://localhost:10000/eureka
eureka.client.service-url.defaultZone=http://supermarket-eureka-1:10000/eureka
2 changes: 1 addition & 1 deletion cart/src/main/resources/log4j2-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
<!--然后定义logger,只有定义了logger并引入的appender,appender才会生效 -->
<loggers>
<!--<root level="all">-->
<root level="ALL">
<root level="INFO">
<appender-ref ref="Console" />
<appender-ref ref="RollingFileInfo" />
<appender-ref ref="RollingFileWarn" />
Expand Down
File renamed without changes.
4 changes: 4 additions & 0 deletions docker/app/start_app.sh → start_up/app/start_app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ docker run -d --name supermarket-eureka-1 --restart always --net net-app -p 1000
docker run -d --name supermarket-product-1 --restart always --net net-app -p 10002:10002 zongxr/supermarket-product:1.0-SNAPSHOT
docker network connect net-mysql supermarket-product-1
docker network connect net-redis supermarket-product-1

# 启动购物车微服务
docker run -d --name supermarket-cart-1 --restart always --net net-app -p 10005:10005 zongxr/supermarket-cart:1.0-SNAPSHOT
docker network connect net-mysql supermarket-cart-1
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit ef9177e

Please sign in to comment.