Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker 快速一键部署,配详细文档 #203

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@ build/
### mac ###
.DS_Store

.flattened-pom.xml
.flattened-pom.xml

volumes/
17 changes: 17 additions & 0 deletions api.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM maven:3.9.6-amazoncorretto-8-debian AS build
WORKDIR /app
COPY . .
RUN mvn clean package

FROM openjdk:8
LABEL MAINTAINER="K8sCat <[email protected]>"
ENV TZ=Asia/Shanghai
WORKDIR /app
EXPOSE 8160
COPY --from=build /app/campus-modular/target/campus-modular.jar ./app.jar
ENTRYPOINT ["java", \
"-Djava.security.egd=file:/dev/./urandom", \
"-Dspring.config.additional-location=/app/application-prod.yml", \
"-Dserver.port=8160", \
"-jar", "/app/app.jar", \
"--spring.profiles.active=prod"]
3 changes: 3 additions & 0 deletions doc/sql/campus_imaotai-1.0.5.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
Date: 02/08/2023 17:33:32
*/

CREATE DATABASE campus_imaotai;
USE campus_imaotai;

SET NAMES utf8;
SET FOREIGN_KEY_CHECKS = 0;

Expand Down
76 changes: 76 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
services:
imaotai-db:
image: mysql:8.0.35
container_name: imaotai-db
environment:
MYSQL_ROOT_PASSWORD: 123456789
volumes:
- ./volumes/db/data/:/var/lib/mysql/
- ./volumes/db/logs:/logs
- ./doc/sql/campus_imaotai-1.0.5.sql:/docker-entrypoint-initdb.d/campus_imaotai-1.0.5.sql
command: [
'mysqld',
'--innodb-buffer-pool-size=80M',
'--character-set-server=utf8mb4',
'--collation-server=utf8mb4_unicode_ci',
'--default-time-zone=+8:00',
'--lower-case-table-names=1',
'--default-authentication-plugin=mysql_native_password'
]
networks:
- imaotai_net
restart: always

imaotai-redis:
image: redis:6.2.12
container_name: imaotai-redis
volumes:
- ./volumes/redis/data/:/redis/data/
networks:
- imaotai_net
restart: always

imaotai-api:
image: imaotai-api:latest
build:
context: .
dockerfile: ./api.Dockerfile
container_name: imaotai-api
volumes:
- ./templates/application-prod.yml:/app/application-prod.yml
networks:
- imaotai_net
depends_on:
- imaotai-db
restart: always
healthcheck:
test: ["CMD", "curl", "-f", "http://127.0.0.1:8160/captchaImage"]
interval: 3s
timeout: 10s
retries: 20
start_period: 40s
start_interval: 5s

imaotai-web:
image: imaotai-web:latest
build:
context: .
dockerfile: ./web.Dockerfile
container_name: imaotai-web
volumes:
- ./templates/web.conf:/etc/nginx/conf.d/default.conf
- ./volumes/web/log:/var/log/nginx
privileged: true
networks:
- imaotai_net
ports:
- 80:80
depends_on:
imaotai-api:
restart: false
condition: service_healthy
restart: always

networks:
imaotai_net:
name: imaotai_net
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ spring:
driverClassName: com.mysql.cj.jdbc.Driver
# jdbc 所有参数配置参考 https://lionli.blog.csdn.net/article/details/122018562
# rewriteBatchedStatements=true 批处理优化 大幅提升批量插入更新删除性能(对数据库有性能损耗 使用批量操作应考虑性能问题)
url: jdbc:mysql://localhost:3306/campus_imaotai?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true
url: jdbc:mysql://imaotai-db:3306/campus_imaotai?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true
username: root
password: 123456789
# 从库数据源
Expand Down Expand Up @@ -52,7 +52,7 @@ spring:
spring:
redis:
# 地址
host: localhost
host: imaotai-redis
# 端口,默认为6379
port: 6379
# 数据库索引
Expand Down
27 changes: 27 additions & 0 deletions templates/web.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
upstream api {
server imaotai-api:8160;
}

server {
listen 80;
server_name localhost;

location / {
root /app;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}

location /prod-api/ {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://api/;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
11 changes: 11 additions & 0 deletions web.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM node:16 AS build
WORKDIR /app
COPY ./vue_campus_admin .
RUN npm i --registry=https://registry.npmmirror.com \
&& npm run build:prod

FROM nginx:1.23.4
LABEL MAINTAINER="K8sCat <[email protected]>"
ENV TZ=Asia/Shanghai
RUN mkdir -p /app
COPY --from=build /app/dist/ /app/