Skip to content

Commit

Permalink
docker 调整
Browse files Browse the repository at this point in the history
  • Loading branch information
landy committed Apr 22, 2020
1 parent 5d4efd5 commit 7f66c95
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ADD . /build
ENV TZ=Asia/Shanghai
RUN ln -sf /usr/share/zoneinfo/{TZ} /etc/localtime && echo "{TZ}" > /etc/timezone

RUN cd /build && mvn package -Dmaven.test.skip=true -Ph2 \
RUN cd /build && mvn package -Dmaven.test.skip=true -Pdocker \
&& cp -f target/mblog-latest.jar /app/mblog && rm -rf /build/*

EXPOSE 8080
Expand Down
18 changes: 17 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
version: '3'
services:
mysql:
container_name: blog-mysql
image: mysql/mysql-server:5.7
environment:
MYSQL_DATABASE: db_mblog
MYSQL_ROOT_PASSWORD: 12345
MYSQL_ROOT_HOST: '%'
TZ: Asia/Shanghai
expose:
- "3306"
volumes:
- ./mysql/mysql_data:/var/lib/mysql
restart: always

server:
container_name: mtons-blog
image: langhsu/mblog:latest
environment:
TZ: Asia/Shanghai
ports:
- "8080:8080"
- "8080:8080"
depends_on:
- mysql
restart: always
14 changes: 11 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -270,22 +270,30 @@
<profiles>
<!--开发默认环境-->
<profile>
<id>mysql</id>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<profileActive>mysql</profileActive>
<profileActive>dev</profileActive>
</properties>
</profile>

<!--测试环境-->
<!--H2环境-->
<profile>
<id>h2</id>
<properties>
<profileActive>h2</profileActive>
</properties>
</profile>

<!--Docker环境-->
<profile>
<id>docker</id>
<properties>
<profileActive>docker</profileActive>
</properties>
</profile>
</profiles>

<build>
Expand Down
23 changes: 16 additions & 7 deletions src/main/java/com/mtons/mblog/base/storage/StorageFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.mtons.mblog.base.storage.impl.UpYunStorageImpl;
import com.mtons.mblog.config.SiteOptions;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
Expand All @@ -28,20 +29,20 @@
* on 2019/1/21
*/
@Component
public class StorageFactory {
public class StorageFactory implements InitializingBean {
@Autowired
private ApplicationContext applicationContext;
@Autowired
private SiteOptions siteOptions;

private Map<String, Storage> fileRepoMap = new HashMap<>();

@PostConstruct
public void init() {
fileRepoMap.put("native", applicationContext.getBean(NativeStorageImpl.class));
fileRepoMap.put("upyun", applicationContext.getBean(UpYunStorageImpl.class));
fileRepoMap.put("aliyun", applicationContext.getBean(AliyunStorageImpl.class));
fileRepoMap.put("qiniu", applicationContext.getBean(QiniuStorageImpl.class));
public boolean registry(String key, Storage storage) {
if (fileRepoMap.containsKey(key)) {
return false;
}
fileRepoMap.put(key, storage);
return true;
}

public Storage get() {
Expand All @@ -51,4 +52,12 @@ public Storage get() {
}
return fileRepoMap.get(scheme);
}

@Override
public void afterPropertiesSet() throws Exception {
fileRepoMap.put("native", applicationContext.getBean(NativeStorageImpl.class));
fileRepoMap.put("upyun", applicationContext.getBean(UpYunStorageImpl.class));
fileRepoMap.put("aliyun", applicationContext.getBean(AliyunStorageImpl.class));
fileRepoMap.put("qiniu", applicationContext.getBean(QiniuStorageImpl.class));
}
}
File renamed without changes.
23 changes: 23 additions & 0 deletions src/main/resources/application-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
spring:
datasource:
#schema: classpath*:scripts/schema.sql
#continue-on-error: false
#sql-script-encoding: utf-8
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://mysql/db_mblog?useSSL=false&characterEncoding=utf8&serverTimezone=GMT%2B8
username: root
password: 12345
flyway:
enabled: true
jpa:
database: mysql
show-sql: false
hibernate:
ddl-auto: update
database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
properties:
hibernate.format_sql: true
hibernate.naming.physical-strategy: org.hibernate.scripts.model.naming.PhysicalNamingStrategyStandardImpl
hibernate.cache.use_second_level_cache: false
hibernate.search.default.directory_provider: filesystem
hibernate.search.default.indexBase: ${site.location}/storage/indexes

0 comments on commit 7f66c95

Please sign in to comment.