Browse Source

initial

master
OhYee 2 years ago
commit
c3c2145306
Signed by: OhYee
GPG Key ID: 5A9E1F63ED274FBB
  1. 3
      .gitignore
  2. 16
      README.md
  3. 47
      conf.d/blotter.conf
  4. 31
      docker-compose.yml
  5. 77
      script.bash

3
.gitignore vendored

@ -0,0 +1,3 @@ @@ -0,0 +1,3 @@
/data/
blotter_page
blotter

16
README.md

@ -0,0 +1,16 @@ @@ -0,0 +1,16 @@
# Blotter Docker
在 Docker 中 **无脑地** 运行 Blotter 博客
相关项目:
- [后端 OhYee/blotter](https://github.com/OhYee/blotter)
- [前端 OhYee/blotter_page](https://github.com/OhYee/blotter_page)
## TODO
- [x] Docker 编译镜像
- [x] Docker 运行博客
- [x] 自动初始化数据库
- [ ] 定时任务脚本自动配置
- [ ] 完善文档
- [ ] 自动部署

47
conf.d/blotter.conf

@ -0,0 +1,47 @@ @@ -0,0 +1,47 @@
map $http_upgrade $connection_upgrade{
default upgrade;
'' close;
}
server {
listen 8000;
client_max_body_size 20m;
proxy_max_temp_file_size 0;
location ^~ / {
proxy_pass http://frontend:50002;
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;
}
location ^~/api/ {
proxy_pass http://backend:50000;
proxy_set_header nginx true;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
# location ^~/static/ {
# root /home/ubuntu/blog;
# }
# location = /ads.txt {
# root /home/ubuntu/blog;
# }
rewrite /sitemap.txt /api/sitemap.txt;
rewrite /sitemap.xml /api/sitemap.xml;
rewrite /rss.xml /api/rss.xml;
rewrite /robots.txt /api/robots.txt;
}

31
docker-compose.yml

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

77
script.bash

@ -0,0 +1,77 @@ @@ -0,0 +1,77 @@
#!/bin/bash
func_check_docker() {
DOCKER_PATH=$(which docker)
if [[ $? -eq 0 ]]; then
echo "Docker in ${DOCKER_PATH}"
else
echo "Can not find docker, please install it first"
exit
fi
DOCKER_COMPOSE_PATH=$(which docker-compose)
if [[ $? -eq 0 ]]; then
echo "Docker compose in ${DOCKER_COMPOSE_PATH}"
else
echo "Can not find docker-compose, please install it first"
exit
fi
}
func_build_backend() {
echo "Building blotter backend"
cd blotter && bash ./build.bash && cd ..
}
func_build_frontend() {
echo "Building blotter frontend"
cd blotter_page && bash ./build.bash && cd ..
}
func_start() {
echo "Starting blotter"
docker-compose up -d
}
func_stop() {
echo "Stopping blotter"
docker-compose down
}
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 ""
echo "mongodb 数据存储在 data 目录中、nginx 配置文件存储在 conf.d 文件夹中,可根据需要自定义 HTTPS"
}
func_init() {
git clone https://github.com/OhYee/blotter.git --depth=1
git clone https://github.com/OhYee/blotter_page.git --depth=1
}
func_update() {
cd blotter && git pull && cd ..
cd blotter_page && git pull && cd ..
}
case $1 in
"check") func_check_docker $@;;
"update") func_update $@;;
"backend") func_check_docker && func_build_backend $@;;
"frontend") func_check_docker && func_build_frontend $@;;
"build") func_check_docker && func_build_backend && func_build_frontend $@;;
"start") func_start $@;;
"stop") func_stop $@;;
"init") func_init $@;;
*) func_help $@;;
esac
Loading…
Cancel
Save