فهرست منبع

新增Docker部署

kuaifan 5 سال پیش
والد
کامیت
f9513e61e2
10فایلهای تغییر یافته به همراه341 افزوده شده و 22 حذف شده
  1. 80 8
      INSTALL-EN.md
  2. 80 12
      INSTALL.md
  3. 2 1
      README-EN.md
  4. 2 1
      README.md
  5. 33 0
      cmd
  6. 6 0
      composer.json
  7. 42 0
      docker-compose.yml
  8. 28 0
      docker/php.Dockerfile
  9. 58 0
      docker/site.conf
  10. 10 0
      docker/wookteam.conf

+ 80 - 8
INSTALL-EN.md

@@ -2,11 +2,83 @@
 
 **[中文文档](./INSTALL.md)**
 
-## Setup
+## Setup (using Docker)
+
+> `Docker` & `Docker Compose` must be installed
+
+#### 1. Clone the repository
+
+```bash
+// using ssh
+$ git clone git@github.com:kuaifan/wookteam.git
+// or you can use https
+$ git clone https://github.com/kuaifan/wookteam.git
+
+// copy .env
+$ cp .env.example .env
+```
+
+#### 2. Modify`.env`
+
+`APP_PORT`= (whatever port you want to run the app)
+
+`DB_HOST`= (Value should be`mariadb`)
+
+`DB_DATABASE`= (Add value as you wish)
+
+`DB_USERNAME`= (Add value as you wish)
+
+`DB_PASSWORD`= (Add value as you wish)
+
+`DB_ROOT_PASSWORD`= (Add value as you wish)
+
+> example:
+
+```env
+APP_PORT=80
+......
+DB_CONNECTION=mysql
+DB_HOST=mariadb
+DB_PORT=3306
+DB_DATABASE=wookteam
+DB_USERNAME=wookteam
+DB_PASSWORD=123456
+DB_ROOT_PASSWORD=123456
+......
+LARAVELS_LISTEN_IP=0.0.0.0
+LARAVELS_LISTEN_PORT=5200
+LARAVELS_PROXY_URL=
+```
+
+#### 3. Build image & install
+
+```bash
+./cmd build php
+./cmd composer install
+./cmd up -d
+./cmd art key:generate
+./cmd art migrate --seed
+./cmd npm install
+./cmd npm run prod
+```
+
+#### To stop the app server
+
+```bash
+./cmd stop
+```
+
+> P.S: Once application is setup, whenever you want to start the server (if it is stopped) run below command
+
+```bash
+./cmd start
+```
+
+## Setup (if you're not using docker)
 
 > Fork the repo if you are outside collaborator https://github.com/kuaifan/wookteam.
 
-#### Clone the project to your local or server
+#### 1. Clone the project to your local or server
 
 ```bash
 // using ssh
@@ -22,7 +94,7 @@ $ git remote add origin git@github.com:kuaifan/wookteam.git
 $ cp .env.example .env
 ```
 
-#### Modify`.env`
+#### 2. Modify`.env`
 
 > Database、WebSocket
 
@@ -41,7 +113,7 @@ LARAVELS_LISTEN_PORT=5200
 LARAVELS_PROXY_URL=ws://wookteam.com/ws
 ```
 
-#### Setup application
+#### 3. Setup application
 
 ```bash
 $ git checkout master # use dev branch for local development
@@ -55,7 +127,7 @@ $ npm install
 $ npm run production
 ```
 
-#### Run Laravels (WebSocket)
+#### 4. Run Laravels (WebSocket)
 
 > Please confirm your environment and installation[Swoole](https://www.swoole.com/)。
 
@@ -78,7 +150,7 @@ redirect_stderr=true
 stdout_logfile=/var/log/supervisor/%(program_name)s.log
 ```
 
-## Deployment To Nginx
+## 5. Deployment To Nginx
 
 ```nginx
 map $http_upgrade $connection_upgrade {
@@ -141,7 +213,7 @@ server {
 }
 ```
 
-#### Account
+## Account
 
 - admin/123456
-- system/123456
+- system/123456

+ 80 - 12
INSTALL.md

@@ -2,11 +2,11 @@
 
 **[English Documentation](./INSTALL-EN.md)**
 
-## 设置
+## 安装设置(使用Docker)
 
-> Fork the repo if you are outside collaborator https://github.com/kuaifan/wookteam.
+> 必须安装 `Docker` 和 `Docker Compose`
 
-#### 克隆项目到您的本地或服务器
+#### 1、克隆项目到您的本地或服务器
 
 ```bash
 // 使用ssh
@@ -14,15 +14,83 @@ $ git clone git@github.com:kuaifan/wookteam.git
 // 或者你也可以使用https
 $ git clone https://github.com/kuaifan/wookteam.git
 
-// 配置 remotes
-$ cd wookteam
-$ git remote add origin git@github.com:kuaifan/wookteam.git
+// 拷贝 .env
+$ cp .env.example .env
+```
+
+#### 2、修改`.env`
+
+`APP_PORT`= (你想要运行应用程序的任何端口)
+
+`DB_HOST`= (值应该是`mariadb`)
+
+`DB_DATABASE`= (设置你想要的数据库名称)
+
+`DB_USERNAME`= (设置你想要的数据库用户名)
+
+`DB_PASSWORD`= (设置你想要的数据库密码)
+
+`DB_ROOT_PASSWORD`= (设置你想要的数据库root密码)
+
+> 设置例子:
+
+```env
+APP_PORT=80
+......
+DB_CONNECTION=mysql
+DB_HOST=mariadb
+DB_PORT=3306
+DB_DATABASE=wookteam
+DB_USERNAME=wookteam
+DB_PASSWORD=123456
+DB_ROOT_PASSWORD=123456
+......
+LARAVELS_LISTEN_IP=0.0.0.0
+LARAVELS_LISTEN_PORT=5200
+LARAVELS_PROXY_URL=
+```
+
+#### 3、构建项目
+
+```bash
+./cmd build php
+./cmd composer install
+./cmd up -d
+./cmd art key:generate
+./cmd art migrate --seed
+./cmd npm install
+./cmd npm run prod
+```
+
+#### 停止服务
+
+```bash
+./cmd stop
+```
+
+> 一旦应用程序被设置,无论何时你想要启动服务器(如果它被停止)运行以下命令
+
+```bash
+./cmd start
+```
+
+## 安装设置(如果你没有使用docker)
+
+> Fork the repo if you are outside collaborator https://github.com/kuaifan/wookteam.
+
+#### 1、克隆项目到您的本地或服务器
+
+```bash
+// 使用ssh
+$ git clone git@github.com:kuaifan/wookteam.git
+// 或者你也可以使用https
+$ git clone https://github.com/kuaifan/wookteam.git
 
 // 拷贝 .env
 $ cp .env.example .env
 ```
 
-#### 修改`.env`
+#### 2、修改`.env`
 
 > 数据库信息、WebSocket
 
@@ -41,7 +109,7 @@ LARAVELS_LISTEN_PORT=5200
 LARAVELS_PROXY_URL=ws://wookteam.com/ws
 ```
 
-#### 设置项目
+#### 3、设置项目
 
 ```bash
 $ git checkout master # 如果使用dev分支进行本地开发
@@ -55,7 +123,7 @@ $ npm install
 $ npm run production
 ```
 
-#### 运行 Laravels (WebSocket)
+#### 4、运行 Laravels (WebSocket)
 
 > 请确认您的环境以及安装[Swoole](https://www.swoole.com/)。
 
@@ -78,7 +146,7 @@ redirect_stderr=true
 stdout_logfile=/var/log/supervisor/%(program_name)s.log
 ```
 
-## 部署到Nginx
+## 5、部署到Nginx
 
 ```nginx
 map $http_upgrade $connection_upgrade {
@@ -141,7 +209,7 @@ server {
 }
 ```
 
-#### 默认账号
+## 默认账号
 
 - admin/123456
-- system/123456
+- system/123456

+ 2 - 1
README-EN.md

@@ -9,7 +9,8 @@
 ## Website
 
 - [https://www.wookteam.com](https://www.wookteam.com)
-- [Install](./INSTALL-EN.md)
+- [Install(using Docker)](./INSTALL-EN.md#Setup-using-Docker)
+- [Install(not Docker)](./INSTALL-EN.md#Setup-if-youre-not-using-docker))
 
 ## Demo
 

+ 2 - 1
README.md

@@ -9,7 +9,8 @@
 ## 官网地址
 
 - [https://www.wookteam.com](https://www.wookteam.com)
-- [安装教程](./INSTALL.md)
+- [安装教程(Docker)](./INSTALL.md#安装设置-使用Docker)
+- [安装教程(非Docker)](./INSTALL.md#安装设置-如果你没有使用docker)
 
 ## 演示地址
 

+ 33 - 0
cmd

@@ -0,0 +1,33 @@
+#!/usr/bin/env bash
+
+COMPOSE="docker-compose"
+
+if [ $# -gt 0 ];then
+    if [[ "$1" == "art" ]]; then
+        shift 1
+        $COMPOSE run --rm -w /var/www php php artisan "$@"
+    elif [[ "$1" == "php" ]]; then
+        shift 1
+        $COMPOSE run --rm -w /var/www php php "$@"
+    elif [[ "$1" == "composer" ]]; then
+        shift 1
+        $COMPOSE run --rm -w /var/www php composer "$@"
+    elif [[ "$1" == "test" ]]; then
+        shift 1
+        $COMPOSE run --rm -w /var/www php ./vendor/bin/phpunit "$@"
+    elif [[ "$1" == "npm" ]]; then
+        shift 1
+        $COMPOSE run --rm -w /var/www php npm "$@"
+    elif [[ "$1" == "mysql" ]]; then
+        shift 1
+        $COMPOSE run --rm -w / mariadb mysql "$@"
+    elif [[ "$1" == "restart" ]]; then
+        shift 1
+        $COMPOSE stop
+        $COMPOSE start
+    else
+        $COMPOSE "$@"
+    fi
+else
+    $COMPOSE ps
+fi

+ 6 - 0
composer.json

@@ -65,5 +65,11 @@
         "post-create-project-cmd": [
             "@php artisan key:generate --ansi"
         ]
+    },
+    "repositories": {
+        "packagist": {
+            "type": "composer",
+            "url": "https://mirrors.aliyun.com/composer/"
+        }
     }
 }

+ 42 - 0
docker-compose.yml

@@ -0,0 +1,42 @@
+version: '3'
+
+services:
+  nginx:
+    image: nginx
+    ports:
+      - "${APP_PORT}:80"
+    volumes:
+      - ./docker/site.conf:/etc/nginx/conf.d/default.conf
+      - ./:/var/www
+    links:
+      - php
+    depends_on:
+      - php
+    restart: unless-stopped
+
+  php:
+    hostname: php
+    ports:
+      - "55200:5200"
+    build:
+      context: .
+      dockerfile: docker/php.Dockerfile
+    volumes:
+      - ./:/var/www
+    environment:
+      TZ: "Asia/Shanghai"
+    links:
+      - mariadb
+    depends_on:
+      - mariadb
+
+  mariadb:
+    hostname: mariadb
+    image: mariadb
+    command: --default-authentication-plugin=mysql_native_password
+    environment:
+      - "MYSQL_ROOT_PASSWORD=${DB_ROOT_PASSWORD}"
+      - "MYSQL_DATABASE=${DB_DATABASE}"
+      - "MYSQL_USER=${DB_USERNAME}"
+      - "MYSQL_PASSWORD=${DB_PASSWORD}"
+    restart: always

+ 28 - 0
docker/php.Dockerfile

@@ -0,0 +1,28 @@
+FROM phpswoole/swoole:4.5.2-php7.4
+
+# Installation dependencies and PHP core extensions
+RUN apt-get update \
+        && apt-get install -y \
+        libpng-dev \
+        libzip-dev \
+        libzip4 \
+        zip \
+        unzip \
+        git \
+        net-tools \
+        iputils-ping \
+        npm \
+        vim \
+        supervisor \
+        && rm -r /var/lib/apt/lists/* \
+        && docker-php-ext-configure gd \
+        && docker-php-ext-install pdo_mysql gd pcntl zip
+
+# Copy application file to /var/www
+COPY . /var/www
+
+# Copy scupervisor file conf
+COPY docker/wookteam.conf /etc/supervisor/conf.d/wookteam.conf
+
+# Set the WORKDIR to /var/www so all following commands run in /var/www
+WORKDIR /var/www

+ 58 - 0
docker/site.conf

@@ -0,0 +1,58 @@
+map $http_upgrade $connection_upgrade {
+    default upgrade;
+    ''      close;
+}
+upstream swoole {
+    # Connect IP:Port, php is the name of php container
+    server php:5200 weight=5 max_fails=3 fail_timeout=30s;
+    keepalive 16;
+}
+server {
+    listen 80;
+
+    # Don't forget to bind the host
+    server_name wookteam.com;
+    root /var/www/public;
+
+    autoindex off;
+    index index.html index.htm index.php;
+
+    charset utf-8;
+
+    location / {
+        try_files $uri @laravels;
+    }
+
+    location =/ws {
+        proxy_http_version 1.1;
+        proxy_set_header X-Real-IP $remote_addr;
+        proxy_set_header X-Real-PORT $remote_port;
+        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+        proxy_set_header Host $http_host;
+        proxy_set_header Scheme $scheme;
+        proxy_set_header Server-Protocol $server_protocol;
+        proxy_set_header Server-Name $server_name;
+        proxy_set_header Server-Addr $server_addr;
+        proxy_set_header Server-Port $server_port;
+        proxy_set_header Upgrade $http_upgrade;
+        proxy_set_header Connection $connection_upgrade;
+        # "swoole" is the upstream
+        proxy_pass http://swoole;
+    }
+
+    location @laravels {
+        proxy_http_version 1.1;
+        proxy_set_header Connection "";
+        proxy_set_header X-Real-IP $remote_addr;
+        proxy_set_header X-Real-PORT $remote_port;
+        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+        proxy_set_header Host $http_host;
+        proxy_set_header Scheme $scheme;
+        proxy_set_header Server-Protocol $server_protocol;
+        proxy_set_header Server-Name $server_name;
+        proxy_set_header Server-Addr $server_addr;
+        proxy_set_header Server-Port $server_port;
+        # "swoole" is the upstream
+        proxy_pass http://swoole;
+    }
+}

+ 10 - 0
docker/wookteam.conf

@@ -0,0 +1,10 @@
+[program:wookteam]
+directory=/var/www
+command=php bin/laravels start -i
+numprocs=1
+autostart=true
+autorestart=true
+startretries=3
+user=root
+redirect_stderr=true
+stdout_logfile=/var/log/supervisor/%(program_name)s.log