diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 00000000..8ef9d054 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,50 @@ +name: Deploy + +on: + # 推送时执行 + push: + branches: [dev] + # pr 时执行 + pull_request: + branches: [dev] + # 可手动执行 + workflow_dispatch: + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + # 1、检出源码 + - name: Checkout + uses: actions/checkout@master + # 2、安装 Java 环境 + - name: Install Java + uses: actions/setup-java@master + with: + distribution: 'adopt' + java-version: '8' + cache: 'maven' + # 3、打包 + - name: Build + run: mvn -B package -P dev --file pom.xml + # 4、拷贝 jar 包到服务器 + - name: Copy Jar + uses: garygrossgarten/github-action-scp@release + with: + host: ${{ secrets.SERVER_HOST }} + port: ${{ secrets.SERVER_PORT }} + username: ${{ secrets.SERVER_USERNAME }} + password: ${{ secrets.SERVER_PASSWORD }} + local: continew-admin-webapi/target/continew-admin.jar + remote: /docker/continew-admin/server/continew-admin.jar + # 5、启动后端服务 + - name: Start + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.SERVER_HOST }} + port: ${{ secrets.SERVER_PORT }} + username: ${{ secrets.SERVER_USERNAME }} + password: ${{ secrets.SERVER_PASSWORD }} + script: | + cd /docker + docker-compose up --force-recreate --build -d continew-admin-server \ No newline at end of file diff --git a/README.md b/README.md index 97920507..08eafc73 100644 --- a/README.md +++ b/README.md @@ -3,10 +3,37 @@ [![License](https://img.shields.io/badge/License-Apache%202.0-green.svg)](https://github.com/Charles7c/continew-admin/blob/dev/LICENSE) ![SNAPSHOT](https://img.shields.io/badge/SNAPSHOT-v0.0.1-%23ff3f59.svg) +📚 [在线 API 文档](http://cnadmin.charles7c.top/doc.html) + ### 简介 ContiNew-Admin (incubating) 中后台管理框架,Continue New Admin,持续以最新流行技术栈构建。当前阶段采用的技术栈:Spring Boot、Undertow、Redis、Redisson、Hutool 等。 +### 开始 + +```bash +# 1.克隆本项目 +git clone https://github.com/Charles7c/continew-admin.git + +# 2.在 IDE(IntelliJ IDEA/Eclipse)中打开本项目 + +# 3.修改配置文件中的 Redis 配置信息 +# [3.也可以在 IntelliJ IDEA 中直接配置程序启动环境变量(REDIS_HOST、REDIS_PORT、REDIS_PWD、REDIS_DB)] + +# 4.启动程序 +# 4.1 启动成功:访问 http://localhost:8000/,页面输出:ContiNew-Admin backend service started successfully. +# 4.2 接口文档:http://localhost:8000/doc.html + +# 5.部署 +# 5.1 Docker 部署 +# 5.1.1 服务器安装好 docker 及 docker-compose(参考:https://blog.charles7c.top/categories/fragments/2022/10/31/CentOS%E5%AE%89%E8%A3%85Docker) +# 5.1.2 执行 mvn package -P prod 进行项目打包,将 target 目录下的 continew-admin.jar 放到 /docker/continew-admin/server 目录下 +# 5.1.3 将 docker 目录上传到服务器 / 目录下,并授权(chmod -R 777 /docker) +# 5.1.4 修改 docker-compose.yml 中的 Redis 配置、continew-admin-server 配置、Nginx 配置 +# 5.1.5 执行 docker-compose up -d 创建并后台运行所有容器 +# 5.2 其他方式部署 +``` + ### 技术栈 | 名称 | 版本 | 简介 | diff --git a/docker/continew-admin/Dockerfile b/docker/continew-admin/Dockerfile new file mode 100644 index 00000000..e118c63f --- /dev/null +++ b/docker/continew-admin/Dockerfile @@ -0,0 +1,11 @@ +FROM java:8 + +MAINTAINER Charles7c charles7c@126.com + +ARG JAR_FILE=./server/*.jar +COPY ${JAR_FILE} app.jar + +ENTRYPOINT ["java", \ + "-jar", \ + "-Djava.security.egd=file:/dev/./urandom", \ + "app.jar"] \ No newline at end of file diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml new file mode 100644 index 00000000..e1dd3c42 --- /dev/null +++ b/docker/docker-compose.yml @@ -0,0 +1,47 @@ +version: '3' +services: + redis: + container_name: redis + image: redis:6.2.7 + restart: always + environment: + TZ: Asia/Shanghai + ports: + - '6379:6379' + volumes: + - /docker/redis/conf/redis.conf:/usr/local/redis/config/redis.conf + - /docker/redis/data:/data + - /docker/redis/logs:/logs + command: 'redis-server /usr/local/redis/config/redis.conf --appendonly yes --requirepass 123456' + privileged: true + continew-admin-server: + container_name: continew-admin-server + build: ./continew-admin + restart: always + environment: + TZ: Asia/Shanghai + REDIS_HOST: 172.17.0.1 + REDIS_PORT: 6379 + REDIS_PWD: 你的 Redis 密码 + REDIS_DB: 你的 Redis 数据库索引 + ports: + - '8000:8000' + volumes: + - /docker/continew-admin/server/logs:/logs + depends_on: + - redis + privileged: true + nginx: + container_name: nginx + image: nginx:1.22.1 + restart: always + environment: + TZ: Asia/Shanghai + ports: + - '80:80' + - '443:443' + volumes: + - /docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf + - /docker/nginx/logs:/var/log/nginx + - /docker/nginx/cert:/etc/nginx/cert + privileged: true \ No newline at end of file diff --git a/docker/nginx/conf/nginx.conf b/docker/nginx/conf/nginx.conf new file mode 100644 index 00000000..33632b9a --- /dev/null +++ b/docker/nginx/conf/nginx.conf @@ -0,0 +1,64 @@ +worker_processes 1; + +error_log /var/log/nginx/error.log warn; +pid /var/run/nginx.pid; + +events { + worker_connections 1024; +} + +http { + include mime.types; + default_type application/octet-stream; + sendfile on; + keepalive_timeout 65; + # 限制 body 大小 + client_max_body_size 100m; + + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + + upstream admin-server { + ip_hash; + server 172.17.0.1:8000; + } + + server { + listen 80; + # listen 443 ssl; + server_name cnadmin.charles7c.top; + + # 证书直接存放 /docker/nginx/cert 目录下即可(更改证书名称即可,无需更改证书路径) + # ssl on; + # ssl_certificate /etc/nginx/cert/xxx.local.pem; # /etc/nginx/cert/ 为 docker 映射路径 不允许更改 + # ssl_certificate_key /etc/nginx/cert/xxx.local.key; # /etc/nginx/cert/ 为 docker 映射路径 不允许更改 + # ssl_session_timeout 5m; + # ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; + # ssl_protocols TLSv1 TLSv1.1 TLSv1.2; + # ssl_prefer_server_ciphers on; + + location / { + 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_read_timeout 6000; + proxy_pass http://admin-server/; + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root html; + } + } + + # HTTP 请求 将转发到 HTTPS + # server { + # listen 80; + # server_name cnadmin.charles7c.top; + # rewrite ^ https://$http_host$request_uri? permanent; + # } +} diff --git a/docker/redis/conf/redis.conf b/docker/redis/conf/redis.conf new file mode 100644 index 00000000..79121a63 --- /dev/null +++ b/docker/redis/conf/redis.conf @@ -0,0 +1,29 @@ +bind 0.0.0.0 +# redis 密码 +requirepass 123456 + +# key 监听器配置 +# notify-keyspace-events Ex + +# 配置持久化文件存储路径 +dir ../data +# 配置rdb +# 15分钟内有至少1个key被更改则进行快照 +save 900 1 +# 5分钟内有至少10个key被更改则进行快照 +save 300 10 +# 1分钟内有至少10000个key被更改则进行快照 +save 60 10000 +# 开启压缩 +rdbcompression yes +# rdb文件名 用默认的即可 +dbfilename dump.rdb + +# 开启aof +appendonly yes +# 文件名 +appendfilename "appendonly.aof" +# 持久化策略,no:不同步,everysec:每秒一次,always:总是同步,速度比较慢 +# appendfsync always +appendfsync everysec +# appendfsync no diff --git a/docker/redis/data/README.md b/docker/redis/data/README.md new file mode 100644 index 00000000..a7ce096b --- /dev/null +++ b/docker/redis/data/README.md @@ -0,0 +1 @@ +Redis 数据存储目录,请确保赋予了读写权限,否则将无法写入数据 \ No newline at end of file