From d861eaf7107b7ea9878847ffd635d0b6875210cd Mon Sep 17 00:00:00 2001 From: none Date: Tue, 30 May 2023 11:38:49 +0800 Subject: [PATCH] airplane --- .gitignore | 2 ++ Dockerfile | 22 ++++++++++++++++++++++ README.md | 43 +++++++++++++++++++++++++++++++++++++++++++ api/.gitignore | 3 +++ api/start.sh | 5 +++++ conf/nginx.conf | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 124 insertions(+) create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 api/.gitignore create mode 100644 api/start.sh create mode 100644 conf/nginx.conf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..867dad5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +frontend/ +backend/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e463dbf --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +FROM eclipse-temurin:17-alpine + +LABEL maintainer="0xtyz " + +RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/' /etc/apk/repositories && \ +sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/' /etc/apk/repositories && \ +sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/' /etc/apk/repositories + +# 安装基本组件 +RUN apk update && apk add nginx + +RUN mkdir /app + +# Copy代码 +COPY frontend /app/frontend +COPY backend /app/backend +COPY api /app/api +COPY conf/nginx.conf /etc/nginx/http.d/default.conf + +RUN chmod +x /app/api/start.sh + +ENTRYPOINT ["/app/api/start.sh"] \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..7a1c772 --- /dev/null +++ b/README.md @@ -0,0 +1,43 @@ +### PlayEdu Light Docker 构建方案 + +本套方案将 API + PC 前台 + 后台管理 三个整合在一个镜像当中,适用于轻量级客户。 + +### 上手 + +- API 程序 `package` 之后,将 `jar` 包复制到 `api` 目录下,并重新命名为 `app.jar` +- PC 界面程序 build 之后,将 `dist` 目录复制到本项目的根目录,然后重命名为 `frontend` +- 后台界面程序 build 之后,将 `dist` 目录复制到本项目的根目录,然后重命名为 `backend` + +之后,在本项目目录命令执行: + +``` +docker build -t playedu-light . +``` + +执行完毕之后,可运行下面命令将 PlayEdu 服务跑起来: + +``` +docker run -d -p 9898:80 --name playedu-local \ + -e DB_HOST=数据库host \ + -e DB_PORT=数据库端口 \ + -e DB_NAME=数据库名 \ + -e DB_USER=数据库用户 \ + -e DB_PASS=数据库密码 \ + -e REDIS_HOST=Redis的host \ + -e REDIS_PORT=Redis的端口 \ + -e REDIS_PASS=redis的密码 \ + -e MINIO_USER=minio的accessKey \ + -e MINIO_PASS=minio的secretKey \ + -e MINIO_END_POINT=minio的服务地址 \ + -e MINIO_BUCKET=minio的bucket \ + -e MINIO_DOMAIN=minio的访问域名 \ + playedu-light +``` + +跑起来之后,可以通过下面的链接访问前后台: + +| 端口 | 地址 | +| -------- | ----------------------------- | +| 学员界面 | `http://localhost:9898` | +| 后台管理 | `http://localhost:9898/admin` | +| API 服务 | `http://localhost:9898/api` | diff --git a/api/.gitignore b/api/.gitignore new file mode 100644 index 0000000..6059910 --- /dev/null +++ b/api/.gitignore @@ -0,0 +1,3 @@ +* +!.gitignore +!start.sh \ No newline at end of file diff --git a/api/start.sh b/api/start.sh new file mode 100644 index 0000000..7a0d663 --- /dev/null +++ b/api/start.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +nginx + +java -jar /app/api/app.jar --spring.profiles.active=prod --spring.datasource.url="jdbc:mysql://${DB_HOST}:${DB_PORT}/${DB_NAME}?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false" --spring.datasource.username=${DB_USER} --spring.datasource.password=${DB_PASS} --spring.data.redis.host=${REDIS_HOST} --spring.data.redis.port=${REDIS_PORT} --spring.data.redis.password=${REDIS_PASS} --minio.access-key=${MINIO_USER} --minio.secret-key=${MINIO_PASS} --minio.end-point=${MINIO_END_POINT} --minio.bucket=${MINIO_BUCKET} --minio.domain=${MINIO_DOMAIN} \ No newline at end of file diff --git a/conf/nginx.conf b/conf/nginx.conf new file mode 100644 index 0000000..c7a1001 --- /dev/null +++ b/conf/nginx.conf @@ -0,0 +1,49 @@ +server { + listen 80 default_server; + absolute_redirect off; + server_name _; + + root /app/frontend; + index index.html; + + location / { + try_files $uri $uri/ /index.html; + + gzip on; + gzip_static on; + gzip_buffers 4 16k; + gzip_http_version 1.1; + gzip_comp_level 5; + gzip_types text/plain application/javascript text/css application/xml text/javascript; + gzip_vary on; + } + + location /api/ { + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_pass http://127.0.0.1:9898/; + } + + location /admin { + alias /app/backend; + index index.html; + + try_files $uri $uri/ /admin/index.html; + + gzip on; + gzip_static on; + gzip_buffers 4 16k; + gzip_http_version 1.1; + gzip_comp_level 5; + gzip_types text/plain application/javascript text/css application/xml text/javascript; + gzip_vary on; + } + + location ~ /\.ht { + deny all; + } + + location ~* ^/(?![api|admin].*) { + try_files $uri /index.html; + } +} \ No newline at end of file