Browse Source

feat: 从服务端拉取镜像运行

master
OhYee 10 months ago
parent
commit
f5682c5f13
Signed by: OhYee
GPG Key ID: 5A9E1F63ED274FBB
  1. 18
      README.md
  2. 24
      docker-compose.yml
  3. 4
      nginx/conf.d/blotter.conf
  4. 39
      nginx/conf.d/web.conf
  5. 1
      nginx/ssl/ssl.crt
  6. 1
      nginx/ssl/ssl.key
  7. 30
      script.bash

18
README.md

@ -6,6 +6,18 @@ @@ -6,6 +6,18 @@
- [后端 OhYee/blotter](https://github.com/OhYee/blotter)
- [前端 OhYee/blotter_page](https://github.com/OhYee/blotter_page)
## 使用
```bash
# 拉取最新版镜像
bash script.bash pull
# 启动服务
bash script.bash start
# 关闭服务
bash script.bash stop
```
## TODO
- [x] Docker 编译镜像
@ -13,4 +25,8 @@ @@ -13,4 +25,8 @@
- [ ] 自动初始化数据库
- [ ] 定时任务脚本自动配置
- [ ] 完善文档
- [ ] 自动部署
- [ ] 自动部署
## 公网访问
默认监听 50000 端口,同时在 80 端口监听 www.example.com 域名,可配置 nginx/conf.d 相关文件修改域名及 HTTPS

24
docker-compose.yml

@ -1,31 +1,41 @@ @@ -1,31 +1,41 @@
version: "3"
services:
nginx:
image: nginx:1.19.9
cap_add:
- NET_ADMIN
ports:
- 80:8000
- 443:8001
- 50000:50000
- 80:80
- 443:443
volumes:
- ./conf.d/:/etc/nginx/conf.d/
- ./nginx/conf.d:/etc/nginx/conf.d
- ./nginx/ssl:/etc/nginx/ssl
- /etc/localtime:/etc/localtime
links:
- backend:backend
- frontend:frontend
mongodb:
image: mongo:4.4.5
volumes:
- ./data:/data/db
- /etc/localtime:/etc/localtime
ports:
- 27017:27017
backend:
image: blotter
image: ${backendImage}
environment:
- mongoURI=mongodb:27017
depends_on:
- mongodb
volumes:
- /etc/localtime:/etc/localtime
links:
- mongodb:mongodb
frontend:
image: blotter_page
image: ${frontImage}
environment:
- backendURI=http://backend:50000
volumes:
- /etc/localtime:/etc/localtime
links:
- backend:backend

4
conf.d/blotter.conf → nginx/conf.d/blotter.conf

@ -4,13 +4,12 @@ map $http_upgrade $connection_upgrade{ @@ -4,13 +4,12 @@ map $http_upgrade $connection_upgrade{
}
server {
listen 8000;
listen 50000;
client_max_body_size 20m;
proxy_max_temp_file_size 0;
location ^~ / {
proxy_pass http://frontend:50002;
proxy_redirect off;
@ -20,6 +19,7 @@ server { @@ -20,6 +19,7 @@ server {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header Upgrade $http_upgrade;
}
location ^~/api/ {

39
nginx/conf.d/web.conf

@ -0,0 +1,39 @@ @@ -0,0 +1,39 @@
server {
listen 80;
server_name www.example.com;
client_max_body_size 20m;
proxy_max_temp_file_size 0;
location ^~ / {
proxy_pass http://localhost:50000;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Scheme $scheme;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header Upgrade $http_upgrade;
}
}
# server {
# listen 443 ssl http2;
# server_name www.example.com;
# ssl_certificate "ssl/ssl.crt";
# ssl_certificate_key "ssl/ssl.key";
# location ^~ / {
# proxy_pass http://localhost:50000;
# proxy_redirect off;
# proxy_set_header Host $host;
# proxy_set_header X-Scheme $scheme;
# proxy_set_header X-Forwarded-Proto $scheme;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-Host $server_name;
# proxy_set_header Upgrade $http_upgrade;
# }
# }

1
nginx/ssl/ssl.crt

@ -0,0 +1 @@ @@ -0,0 +1 @@
empty

1
nginx/ssl/ssl.key

@ -0,0 +1 @@ @@ -0,0 +1 @@
empty

30
script.bash

@ -1,5 +1,8 @@ @@ -1,5 +1,8 @@
#!/bin/bash
export backendImage="ohyee/blotter:cef7a23"
export frontImage="ohyee/blotter_page:eab3a5481"
func_check_docker() {
DOCKER_PATH=$(which docker)
if [[ $? -eq 0 ]]; then
@ -30,6 +33,19 @@ func_build_frontend() { @@ -30,6 +33,19 @@ func_build_frontend() {
cd blotter_page && bash ./build.bash && cd ..
}
func_pull() {
echo "Pulling blotter"
docker pull ${backendImage}
docker pull ${frontImage}
}
func_push() {
echo "Pushing blotter"
docker push ${backendImage}
docker push ${frontImage}
}
func_start() {
echo "Starting blotter"
@ -45,11 +61,13 @@ func_stop() { @@ -45,11 +61,13 @@ func_stop() {
func_help() {
echo "Blotter Docker 环境"
echo ""
echo "1. 安装 docker、docker-compose 环境"
echo "2. 需要运行 bash script.bash init 初始化前后端代码"
echo "3. bash script.bash build 构建前后端镜像(构建后可以删除前后端源码(但是没必要)"
echo "4. bash script.bash start 启动 blotter 前后端程序"
echo "5. bash script.bash stop 停止前后端按程序"
# echo "1. 安装 docker、docker-compose 环境"
# echo "2. 需要运行 bash script.bash init 初始化前后端代码"
# echo "3. bash script.bash build 构建前后端镜像(构建后可以删除前后端源码(但是没必要)"
# echo "4. bash script.bash start 启动 blotter 前后端程序"
# echo "5. bash script.bash stop 停止前后端程序"
echo "bash script.bash pull 拉取镜像"
echo "bash script.bash start 启动服务镜像"
echo ""
echo "mongodb 数据存储在 data 目录中、nginx 配置文件存储在 conf.d 文件夹中,可根据需要自定义 HTTPS"
}
@ -67,6 +85,8 @@ func_update() { @@ -67,6 +85,8 @@ func_update() {
case $1 in
"check") func_check_docker $@;;
"update") func_update $@;;
"pull") func_pull $@;;
"push") func_push $@;;
"backend") func_check_docker && func_build_backend $@;;
"frontend") func_check_docker && func_build_frontend $@;;
"build") func_check_docker && func_build_backend && func_build_frontend $@;;

Loading…
Cancel
Save