From c6a41dc22356aed1023f5b8f5445f9b0badf8bc2 Mon Sep 17 00:00:00 2001 From: hardy4yooz Date: Wed, 16 Nov 2022 15:13:03 +0800 Subject: [PATCH 1/2] feat: Add quick setup with docker-compose 1. auto setup redis,mysql,brcc-server with docker-compose 2. build brcc-server with multi-stage --- .dockerignore | 2 + Dockerfile | 13 +++---- Dockerfile-mysql | 9 +++++ .../service/impl/ConfigGroupServiceImpl.java | 1 - doc/database/{schema.sql => 1.schema.sql} | 2 +- doc/database/{tables.sql => 2.tables.sql} | 0 doc/database/{data.sql => 3.data.sql} | 0 doc/deploy-guide.md | 12 +++++- docker-compose.yml | 37 +++++++++++++++++++ 9 files changed, 65 insertions(+), 11 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile-mysql rename doc/database/{schema.sql => 1.schema.sql} (86%) rename doc/database/{tables.sql => 2.tables.sql} (100%) rename doc/database/{data.sql => 3.data.sql} (100%) create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..19d49af --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +.git/ +*.md \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 8f68a34..1365b24 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,14 @@ -FROM openjdk:8-jre-alpine +FROM maven:3.8.6-openjdk-8 as builder +COPY . . +RUN mvn clean package -DskipTests -Dgpg.skip +FROM openjdk:8-jre-alpine ENV MY_HOME=/app - ARG JAVA_OPTS="" - ENV OPTS=$JAVA_OPTS +COPY --from=builder brcc-server/target/*.jar $MY_HOME/app.jar WORKDIR $MY_HOME - EXPOSE 8088 - RUN apk add --update ttf-dejavu fontconfig - -ADD brcc-server/target/*.jar $MY_HOME/app.jar - ENTRYPOINT ["sh","-c","java $OPTS -Djava.security.egd=file:/dev/urandom -jar app.jar"] diff --git a/Dockerfile-mysql b/Dockerfile-mysql new file mode 100644 index 0000000..9e0519f --- /dev/null +++ b/Dockerfile-mysql @@ -0,0 +1,9 @@ +FROM mysql:5.7 +ENV MYSQL_DATABASE brcc +ENV MYSQL_ROOT_PASSWORD brcc123456 + +COPY doc/database/*.sql /docker-entrypoint-initdb.d/ + +RUN chmod 777 /docker-entrypoint-initdb.d -R + +CMD [ "mysqld", "--sql-mode=", "--max_allowed_packet=1024M", "--character-set-server=utf8mb4" ] diff --git a/brcc-core/src/main/java/com/baidu/brcc/service/impl/ConfigGroupServiceImpl.java b/brcc-core/src/main/java/com/baidu/brcc/service/impl/ConfigGroupServiceImpl.java index 332ae19..5e06f2f 100644 --- a/brcc-core/src/main/java/com/baidu/brcc/service/impl/ConfigGroupServiceImpl.java +++ b/brcc-core/src/main/java/com/baidu/brcc/service/impl/ConfigGroupServiceImpl.java @@ -18,7 +18,6 @@ */ package com.baidu.brcc.service.impl; -import java.security.acl.Group; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; diff --git a/doc/database/schema.sql b/doc/database/1.schema.sql similarity index 86% rename from doc/database/schema.sql rename to doc/database/1.schema.sql index 0119de5..91d6a6d 100644 --- a/doc/database/schema.sql +++ b/doc/database/1.schema.sql @@ -1,5 +1,5 @@ drop database if exists brcc; -drop user 'brcc'@'%'; +-- drop user if exists 'brcc'@'%'; create database brcc default character set utf8mb4 collate utf8mb4_unicode_ci; use brcc; create user 'brcc'@'%' identified by 'brcc123456'; diff --git a/doc/database/tables.sql b/doc/database/2.tables.sql similarity index 100% rename from doc/database/tables.sql rename to doc/database/2.tables.sql diff --git a/doc/database/data.sql b/doc/database/3.data.sql similarity index 100% rename from doc/database/data.sql rename to doc/database/3.data.sql diff --git a/doc/deploy-guide.md b/doc/deploy-guide.md index 2242144..431b115 100644 --- a/doc/deploy-guide.md +++ b/doc/deploy-guide.md @@ -91,4 +91,14 @@ http://ip:port 其中IP为服务启动的IP,Port为web服务监听端口,例 # 三、 容器化部署 - [制作Docker镜像](./docker-guide.md) -- [Kubernetes](./k8s-guide.md) \ No newline at end of file +- [Kubernetes](./k8s-guide.md) + +## Docker-compose 快速部署 + + + 在工程根目录执行: `docker-compose up -d` + +> 这里使用的 docker-compose 3 + +浏览器访问WebUI: http://localhost:8088 + \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..9ade105 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,37 @@ +version: "3.9" + +services: + mysql: + platform: linux/amd64 + build: + context: . + dockerfile: Dockerfile-mysql + + redis: + image: redis:5.0 + + server: + build: + context: . + dockerfile: Dockerfile + environment: + - SERVER_PORT=8088 + - REDIS_HOST=redis + - REDIS_PORT=6379 + - DB_HOST=mysql + - DB_PORT=3306 + - DB_USERNAME=brcc + - DB_PASSWORD=brcc123456 + ports: + - "8088:8088" + links: + - mysql + - redis + depends_on: + - mysql + - redis + + + + + From 0f50850511391087a8daf9fa48e0ede99ce83802 Mon Sep 17 00:00:00 2001 From: hardy4yooz Date: Wed, 16 Nov 2022 15:29:23 +0800 Subject: [PATCH 2/2] fix: Uncomment the drop user ddl --- doc/database/1.schema.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/database/1.schema.sql b/doc/database/1.schema.sql index 91d6a6d..b065a98 100644 --- a/doc/database/1.schema.sql +++ b/doc/database/1.schema.sql @@ -1,5 +1,5 @@ drop database if exists brcc; --- drop user if exists 'brcc'@'%'; +drop user if exists 'brcc'@'%'; create database brcc default character set utf8mb4 collate utf8mb4_unicode_ci; use brcc; create user 'brcc'@'%' identified by 'brcc123456';