├── .dockerignore ├── .env.example ├── .gitignore ├── Caddyfile.example ├── build.sh ├── configs └── nginx.conf ├── docker-compose.no-caddy.yml ├── docker-compose.yml ├── install.sh ├── readme.md ├── setup-node.sh └── update.sh /.dockerignore: -------------------------------------------------------------------------------- 1 | .git 2 | kami 3 | -------------------------------------------------------------------------------- /.env.example: -------------------------------------------------------------------------------- 1 | # THIS ENV FILE EXAMPLE ONLY FOR DOCKER COMPOSE 2 | # SEE https://docs.docker.com/compose/environment-variables/#the-env-file 3 | JWT_SECRET=asffasgvxczfqreqw213 4 | ALLOWED_ORIGINS=innei.ren 5 | BASE_URL=https://dev.shizuri.net 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | kami 2 | .env 3 | Caddyfile 4 | no-caddy 5 | -------------------------------------------------------------------------------- /Caddyfile.example: -------------------------------------------------------------------------------- 1 | ---------DOMAIN------------ { 2 | encode gzip 3 | handle /qaqdmin { 4 | reverse_proxy app-server:2333 5 | } 6 | 7 | handle /proxy/* { 8 | rewrite * / 9 | reverse_proxy app-server:2333 10 | } 11 | 12 | handle /api/v2 { 13 | reverse_proxy app-server:2333 { 14 | header_up Host {host} 15 | header_up X-Real-IP {remote} 16 | } 17 | } 18 | 19 | handle /feed { 20 | rewrite * / 21 | reverse_proxy app-server:2333 22 | } 23 | 24 | handle /atom.xml { 25 | rewrite * / 26 | reverse_proxy app-server:2333 27 | } 28 | 29 | handle /sitemap { 30 | rewrite * / 31 | reverse_proxy app-server:2333 32 | } 33 | handle /render/* { 34 | rewrite * / 35 | reverse_proxy app-server:2333 { 36 | header_up Host {host} 37 | header_up X-Real-IP {remote} 38 | } 39 | } 40 | 41 | handle /api/v2/* { 42 | reverse_proxy app-server:2333 { 43 | header_up Host {host} 44 | header_up X-Real-IP {remote} 45 | } 46 | } 47 | 48 | handle /socket.io/* { 49 | uri strip_prefix /path 50 | rewrite * /socket.io{path} 51 | reverse_proxy app-server:2333 { 52 | header_up Host {host} 53 | header_up X-Real-IP {remote} 54 | } 55 | } 56 | 57 | 58 | handle /* { 59 | reverse_proxy app-kami:2323 60 | } 61 | tls --------EMAIL------------ 62 | } -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!env sh 2 | set -e 3 | preCheck() { 4 | git version || { 5 | echo 'git 未安装' 6 | exit -1 7 | } 8 | docker -v || { 9 | echo 'docker 未安装' 10 | exit -1 11 | } 12 | docker compose version || { 13 | echo 'Docker 版本过低,需要支持 compose 的 Docker' 14 | exit -1 15 | } 16 | git lfs version || { 17 | echo 'git lfs 未安装' 18 | exit -1 19 | } 20 | uuidgen 1>/dev/null || { 21 | echo 'uuidgen 未安装' 22 | exit -1 23 | } 24 | } 25 | 26 | # main 27 | 28 | if [ -e "${PWD}/Caddyfile" ] || [ -e "${PWD}/.env" ]; then 29 | read -p "已经构建过了,是否重新构建,(需要更新请执行 update.sh) [y/N]" choice 30 | if [ "$choice" = "y" ]; then 31 | rm -rf .env 32 | rm -rf Caddyfile 33 | elif [ "$choice" = "n" ]; then 34 | exit 0 35 | elif [ "$choice" = "N" ]; then 36 | exit 0 37 | elif [ "$choice" = "" ]; then 38 | exit 0 39 | else 40 | echo "选项错误" 41 | exit -1 42 | fi 43 | fi 44 | 45 | preCheck 46 | 47 | read -p "你的域名为:(需要提前绑定)" domain 48 | 49 | if [ -z "$domain" ]; then 50 | echo "域名不能为空" 51 | exit 1 52 | fi 53 | read -p "你的邮箱为: (此步留空,则不部署 Caddy 服务) " email 54 | caddy2=true 55 | if [ "$email" ]; then 56 | read -p "是否部署 Caddy 2.0? (Y/n)" caddy2 57 | case $caddy2 in 58 | y) 59 | caddy2=true 60 | ;; 61 | n) 62 | caddy2=false 63 | ;; 64 | *) 65 | caddy2=true 66 | ;; 67 | esac 68 | 69 | fi 70 | 71 | setupCaddy2=$email && $caddy2 72 | 73 | if [ "x$setupCaddy2" != "x" ]; then 74 | caddy=$(cat ./Caddyfile.example) 75 | rm -f Caddyfile 76 | echo "$caddy" | sed -e "s/---------DOMAIN------------/$domain/g" | sed -e "s/--------EMAIL------------/$email/g" >Caddyfile 77 | fi 78 | 79 | randomString=$(uuidgen | tr -d '-') 80 | 81 | cp .env.example .env 82 | echo BASE_URL=https://${domain} >>.env 83 | echo JWT_SECRET=${randomString} >>.env 84 | echo ALLOWED_ORIGINS=${domain} >>.env 85 | rm -rf kami 86 | git clone https://github.com/mx-space/kami --depth=1 87 | 88 | cd kami 89 | git fetch --tags 90 | latestTagHash=$(git rev-list --tags --max-count=1) 91 | latestTag=$(git describe --tags $latestTagHash) 92 | git checkout $latestTag 93 | cd .. 94 | 95 | if [ "x$setupCaddy2" != "x" ]; then 96 | docker compose build 97 | docker compose up -d 98 | else 99 | docker compose -f docker-compose.no-caddy.yml build 100 | docker compose -f docker-compose.no-caddy.yml up -d 101 | touch ./no-caddy 102 | fi 103 | -------------------------------------------------------------------------------- /configs/nginx.conf: -------------------------------------------------------------------------------- 1 | # This is a example for nginx configure if you host mx-space manually 2 | location ~* \.(gif|png|jpg|css|js|woff|woff2)$ { 3 | proxy_pass http://127.0.0.1:2323; 4 | proxy_set_header Host $host; 5 | proxy_set_header X-Real-IP $remote_addr; 6 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 7 | proxy_set_header REMOTE-HOST $remote_addr; 8 | expires 30d; 9 | } 10 | 11 | location / { 12 | proxy_pass http://127.0.0.1:2323; 13 | proxy_set_header Host $host; 14 | proxy_set_header X-Real-IP $remote_addr; 15 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 16 | proxy_set_header REMOTE-HOST $remote_addr; 17 | 18 | add_header X-Cache $upstream_cache_status; 19 | 20 | add_header Cache-Control no-cache; 21 | proxy_intercept_errors on; 22 | } 23 | 24 | 25 | location ~* \/(feed|sitemap|atom.xml) { 26 | proxy_pass http://127.0.0.1:2333/$1; 27 | proxy_set_header Host $host; 28 | proxy_set_header X-Real-IP $remote_addr; 29 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 30 | proxy_set_header REMOTE-HOST $remote_addr; 31 | 32 | add_header X-Cache $upstream_cache_status; 33 | 34 | add_header Cache-Control max-age=60; 35 | } 36 | 37 | location ^~ /api/v2 { 38 | proxy_pass http://127.0.0.1:2333/api/v2; 39 | proxy_set_header Host $host; 40 | proxy_set_header X-Real-IP $remote_addr; 41 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 42 | proxy_set_header REMOTE-HOST $remote_addr; 43 | proxy_set_header Host $host; 44 | 45 | add_header server PHP/8; 46 | } 47 | 48 | 49 | location /proxy/qaqdmin { 50 | proxy_pass http://127.0.0.1:2333/proxy/qaqdmin; 51 | proxy_ignore_headers Set-Cookie Cache-Control expires; 52 | add_header Cache-Control no-store; 53 | expires 12h; 54 | } 55 | 56 | 57 | location ^~ /proxy/ { 58 | proxy_pass http://127.0.0.1:2333/proxy/; 59 | 60 | add_header X-Cache $upstream_cache_status; 61 | #Set Nginx Cache 62 | 63 | add_header Cache-Control max-age=36000000; 64 | } 65 | 66 | location ^~ /render/ { 67 | proxy_pass http://127.0.0.1:2333/render/; 68 | 69 | add_header X-Cache $upstream_cache_status; 70 | add_header Cache-Control max-age=10; 71 | expires 1h; 72 | } 73 | 74 | location ^~ /socket.io { 75 | proxy_pass http://127.0.0.1:2333/socket.io; 76 | proxy_set_header Host $host; 77 | proxy_set_header X-Real-IP $remote_addr; 78 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 79 | proxy_set_header REMOTE-HOST $remote_addr; 80 | proxy_set_header Upgrade $http_upgrade; 81 | proxy_set_header Connection "upgrade"; 82 | proxy_set_header Host $host; 83 | 84 | add_header X-Cache $upstream_cache_status; 85 | } 86 | -------------------------------------------------------------------------------- /docker-compose.no-caddy.yml: -------------------------------------------------------------------------------- 1 | version: '3.8' 2 | 3 | services: 4 | app-kami: 5 | env_file: 6 | - .env 7 | container_name: mx-kami 8 | restart: 'on-failure' 9 | ports: 10 | - '2323:2323' 11 | build: 12 | context: ./kami 13 | args: 14 | NODE_ENV: production 15 | BASE_URL: '${BASE_URL}' 16 | 17 | depends_on: 18 | - app-server 19 | command: 'node server.js' 20 | environment: 21 | NODE_ENV: production 22 | networks: 23 | - app-network 24 | links: 25 | - app-server 26 | 27 | app-server: 28 | container_name: mx-server 29 | image: innei/mx-server:3 30 | volumes: 31 | - ./data/mx-space:/root/.mx-space 32 | command: node index.js --redis_host=redis --db_host=mongo --allowed_origins=${ALLOWED_ORIGINS} --jwt_secret=${JWT_SECRET} --cluster --color 33 | restart: 'on-failure' 34 | ports: 35 | - '2333:2333' 36 | depends_on: 37 | - mongo 38 | - redis 39 | links: 40 | - mongo 41 | - redis 42 | networks: 43 | - app-network 44 | environment: 45 | - NODE_ENV=production 46 | - TZ=Asia/Shanghai 47 | 48 | mongo: 49 | container_name: mongo 50 | image: mongo 51 | volumes: 52 | - ./data/db:/data/db 53 | ports: 54 | - '3344:27017' 55 | networks: 56 | - app-network 57 | 58 | redis: 59 | image: redis 60 | container_name: redis 61 | 62 | ports: 63 | - '3333:6379' 64 | networks: 65 | - app-network 66 | networks: 67 | app-network: 68 | driver: bridge 69 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.8" 2 | 3 | services: 4 | caddy: 5 | container_name: caddy 6 | image: caddy:2.4.5 7 | ports: 8 | - "80:80" 9 | - "443:443" 10 | volumes: 11 | - $PWD/Caddyfile:/etc/caddy/Caddyfile 12 | depends_on: 13 | - app-kami 14 | networks: 15 | - app-network 16 | 17 | app-kami: 18 | env_file: 19 | - .env 20 | container_name: mx-kami 21 | restart: "on-failure" 22 | ports: 23 | - "2323:2323" 24 | build: 25 | context: ./kami 26 | args: 27 | NODE_ENV: production 28 | BASE_URL: "${BASE_URL}" 29 | depends_on: 30 | - app-server 31 | command: "node server.js" 32 | environment: 33 | NODE_ENV: production 34 | networks: 35 | - app-network 36 | links: 37 | - app-server 38 | 39 | app-server: 40 | container_name: mx-server 41 | image: innei/mx-server:3 42 | volumes: 43 | - ./data/mx-space:/root/.mx-space 44 | command: node index.js --redis_host=redis --db_host=mongo --allowed_origins=${ALLOWED_ORIGINS} --jwt_secret=${JWT_SECRET} --cluster --color 45 | 46 | restart: "on-failure" 47 | ports: 48 | - "2333:2333" 49 | depends_on: 50 | - mongo 51 | - redis 52 | links: 53 | - mongo 54 | - redis 55 | networks: 56 | - app-network 57 | environment: 58 | - NODE_ENV=production 59 | - TZ=Asia/Shanghai 60 | healthcheck: 61 | test: ["CMD", "curl", "-f", "http://localhost:2333/info"] 62 | interval: 30s 63 | timeout: 10s 64 | retries: 3 65 | start_period: 40s 66 | 67 | mongo: 68 | container_name: mongo 69 | image: mongo 70 | volumes: 71 | - ./data/db:/data/db 72 | ports: 73 | - "127.0.0.1:3344:27017" 74 | networks: 75 | - app-network 76 | 77 | redis: 78 | image: redis 79 | container_name: redis 80 | 81 | networks: 82 | - app-network 83 | networks: 84 | app-network: 85 | driver: bridge 86 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | set -e 2 | echo "Install in workspace ~/mx" 3 | cd 4 | mkdir -p mx 5 | cd mx 6 | 7 | echo "Delete old files" 8 | [ -f ".env.example" ] && rm -f .env.example 9 | [ -f "Caddyfile.example" ] && rm -f Caddyfile.example 10 | [ -f "build.sh" ] && rm -f build.sh 11 | [ -f "update.sh" ] && rm -f update.sh 12 | [ -f "docker-compose.yml"] && rm -f docker-compose.yml 13 | [ -f "docker-compose.no-caddy.yml"] && rm -f docker-compose.no-caddy.yml 14 | 15 | echo "Download nessary scripts and config..." 16 | wget https://fastly.jsdelivr.net/gh/mx-space/docker@master/.env.example 17 | wget https://fastly.jsdelivr.net/gh/mx-space/docker@master/Caddyfile.example 18 | wget https://fastly.jsdelivr.net/gh/mx-space/docker@master/docker-compose.yml 19 | wget https://fastly.jsdelivr.net/gh/mx-space/docker@master/docker-compose.no-caddy.yml 20 | wget https://fastly.jsdelivr.net/gh/mx-space/docker@master/build.sh 21 | wget https://fastly.jsdelivr.net/gh/mx-space/docker@master/update.sh 22 | 23 | echo "Run build.sh" 24 | bash build.sh 25 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # MSpace Docker 2 | 3 | 使用之前你需要安装 Docker (with compose) 4 | 5 | 你需要先把域名解析到服务器 6 | 7 | ```bash 8 | # install docker 9 | curl -fsSL https://get.docker.com | bash -s docker 10 | docker -v 11 | docker compose version 12 | bash ./build.sh 13 | ``` 14 | 15 | 参考输入: 16 | 17 | ``` 18 | Your domain name is: innei.ren 19 | Your email is: tukon@gmail.com 20 | ``` 21 | 22 | ## 更新 23 | 24 | ``` 25 | bash ./update.sh 26 | ``` 27 | 28 | ## 从零开始的部署过程 29 | 30 | 假设现在你有一台 Ubuntu 的服务器。还没有安装任何环境。并且你已经将域名解析到了服务器。复制以下脚本运行。 31 | 32 | ```bash 33 | sudo apt update && sudo apt install git curl vim wget -y 34 | curl -fsSL https://get.docker.com | bash -s docker 35 | 36 | mkdir -p mx 37 | cd mx 38 | git clone https://github.com/mx-space/docker --depth=1 39 | cd docker 40 | bash ./build.sh 41 | ``` 42 | 43 | CentOS Install Docker 44 | 45 | ```bash 46 | curl -fsSL https://get.docker.com | bash -s docker 47 | ``` 48 | 49 | ## 如果你选择 Nginx... 50 | 51 | 如果选择 Nginx 作为服务器。这里也提供一份反向代理的配置文件。 52 | 53 | 在 [nginx.conf](./configs/nginx.conf) 查看。 54 | -------------------------------------------------------------------------------- /setup-node.sh: -------------------------------------------------------------------------------- 1 | #!env bash 2 | function install_node() { 3 | curl -L https://raw.githubusercontent.com/tj/n/master/bin/n -o n 4 | # 如果无法访问 Github raw 的话就执行下面这条命令 5 | # curl -L https://github.do/https://raw.githubusercontent.com/tj/n/master/bin/n -o n 6 | export N_PREFIX=$HOME/.n 7 | export PATH=$N_PREFIX/bin:$PATH 8 | # export N_NODE_MIRROR=https://npmmirror.com/mirrors/node #如果官方源下载慢的话可以执行这条换国内源 9 | bash n lts 10 | export N_PRESERVE_NPM=1 11 | npm i -g npm@latest 12 | npm i -g yarn zx pnpm n 13 | 14 | } 15 | 16 | if command -v node &>/dev/null; then 17 | echo "node is install" 18 | else 19 | install_node 20 | fi 21 | 22 | if command -v npm &>/dev/null; then 23 | echo "npm is install" 24 | fi 25 | 26 | if command -v zx &>/dev/null; then 27 | echo "zx is install" 28 | exit 0 29 | else 30 | npm i -g zx 31 | fi 32 | -------------------------------------------------------------------------------- /update.sh: -------------------------------------------------------------------------------- 1 | #!env sh 2 | cd kami 3 | git fetch --all --tags --prune 4 | latestTagHash=$(git rev-list --tags --max-count=1) 5 | latestTag=$(git describe --tags $latestTagHash) 6 | echo "Latest tag: $latestTag, checkout" 7 | git checkout $latestTag 8 | cd .. 9 | 10 | docker compose pull 11 | if [ -f "./no-caddy" ]; then 12 | echo "Build docker without Caddy2" 13 | docker compose -f docker-compose.no-caddy.yml build 14 | docker compose -f docker-compose.no-caddy.yml up -d 15 | else 16 | echo "Build docker with Caddy2 (HTTP host)" 17 | docker compose build 18 | docker compose up -d 19 | fi 20 | --------------------------------------------------------------------------------