Merge pull request #44 from captainChaozi/master
使用docker+docker-compose部署shopxofeat/task1-c-wallet
commit
42ec1a7366
|
|
@ -0,0 +1,20 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# See https://docs.docker.com/compose/environment-variables/#the-env-file
|
||||
|
||||
# Nginx
|
||||
NGINX_HOST=localhost
|
||||
|
||||
# PHP
|
||||
|
||||
# See https://hub.docker.com/r/nanoninja/php-fpm/tags/
|
||||
PHP_VERSION=latest
|
||||
|
||||
# MySQL
|
||||
MYSQL_VERSION=5.7.22
|
||||
MYSQL_HOST=mysql
|
||||
MYSQL_DATABASE=test
|
||||
MYSQL_ROOT_USER=root
|
||||
MYSQL_ROOT_PASSWORD=root
|
||||
MYSQL_USER=dev
|
||||
MYSQL_PASSWORD=dev
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
# Global
|
||||
.*.swp
|
||||
.DS_Store
|
||||
|
||||
# Application
|
||||
web/app/composer.json
|
||||
web/app/composer.lock
|
||||
web/app/vendor/
|
||||
web/app/doc/
|
||||
web/app/report/
|
||||
data/
|
||||
|
||||
# PHPStorm
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
.idea/dictionaries
|
||||
|
||||
# Netbeans
|
||||
nbproject/
|
||||
/nbproject/
|
||||
/nbproject/private/
|
||||
/nbproject/private/private.properties
|
||||
|
||||
# SSL Certs
|
||||
etc/ssl/
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
sudo: required
|
||||
|
||||
env:
|
||||
DOCKER_COMPOSE_VERSION: 1.18.0
|
||||
|
||||
services:
|
||||
- docker
|
||||
|
||||
before_install:
|
||||
- sudo apt update
|
||||
- sudo rm /usr/local/bin/docker-compose
|
||||
- curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose
|
||||
- chmod +x docker-compose
|
||||
- sudo mv docker-compose /usr/local/bin
|
||||
- docker-compose --version
|
||||
|
||||
before_script:
|
||||
- sudo make docker-start
|
||||
- sleep 2m
|
||||
|
||||
script:
|
||||
- sudo make apidoc
|
||||
- sudo make gen-certs
|
||||
- sudo make mysql-dump
|
||||
- sudo make mysql-restore
|
||||
- sudo make phpmd
|
||||
- sudo make test
|
||||
|
||||
after_script:
|
||||
- sudo make docker-stop
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
# Makefile for Docker Nginx PHP Composer MySQL
|
||||
|
||||
include .env
|
||||
|
||||
# MySQL
|
||||
MYSQL_DUMPS_DIR=data/db/dumps
|
||||
|
||||
help:
|
||||
@echo ""
|
||||
@echo "usage: make COMMAND"
|
||||
@echo ""
|
||||
@echo "Commands:"
|
||||
@echo " apidoc Generate documentation of API"
|
||||
@echo " code-sniff Check the API with PHP Code Sniffer (PSR2)"
|
||||
@echo " clean Clean directories for reset"
|
||||
@echo " composer-up Update PHP dependencies with composer"
|
||||
@echo " docker-start Create and start containers"
|
||||
@echo " docker-stop Stop and clear all services"
|
||||
@echo " gen-certs Generate SSL certificates"
|
||||
@echo " logs Follow log output"
|
||||
@echo " mysql-dump Create backup of all databases"
|
||||
@echo " mysql-restore Restore backup of all databases"
|
||||
@echo " phpmd Analyse the API with PHP Mess Detector"
|
||||
@echo " test Test application"
|
||||
|
||||
init:
|
||||
@$(shell cp -n $(shell pwd)/web/app/composer.json.dist $(shell pwd)/web/app/composer.json 2> /dev/null)
|
||||
|
||||
apidoc:
|
||||
@docker-compose exec -T php php -d memory_limit=256M -d xdebug.profiler_enable=0 ./app/vendor/bin/apigen generate app/src --destination app/doc
|
||||
@make resetOwner
|
||||
|
||||
clean:
|
||||
@rm -Rf data/db/mysql/*
|
||||
@rm -Rf $(MYSQL_DUMPS_DIR)/*
|
||||
@rm -Rf web/app/vendor
|
||||
@rm -Rf web/app/composer.lock
|
||||
@rm -Rf web/app/doc
|
||||
@rm -Rf web/app/report
|
||||
@rm -Rf etc/ssl/*
|
||||
|
||||
code-sniff:
|
||||
@echo "Checking the standard code..."
|
||||
@docker-compose exec -T php ./app/vendor/bin/phpcs -v --standard=PSR2 app/src
|
||||
|
||||
composer-up:
|
||||
@docker run --rm -v $(shell pwd)/web/app:/app composer update
|
||||
|
||||
docker-start: init
|
||||
docker-compose up -d
|
||||
|
||||
docker-stop:
|
||||
@docker-compose down -v
|
||||
@make clean
|
||||
|
||||
gen-certs:
|
||||
@docker run --rm -v $(shell pwd)/etc/ssl:/certificates -e "SERVER=$(NGINX_HOST)" jacoelho/generate-certificate
|
||||
|
||||
logs:
|
||||
@docker-compose logs -f
|
||||
|
||||
mysql-dump:
|
||||
@mkdir -p $(MYSQL_DUMPS_DIR)
|
||||
@docker exec $(shell docker-compose ps -q mysqldb) mysqldump --all-databases -u"$(MYSQL_ROOT_USER)" -p"$(MYSQL_ROOT_PASSWORD)" > $(MYSQL_DUMPS_DIR)/db.sql 2>/dev/null
|
||||
@make resetOwner
|
||||
|
||||
mysql-restore:
|
||||
@docker exec -i $(shell docker-compose ps -q mysqldb) mysql -u"$(MYSQL_ROOT_USER)" -p"$(MYSQL_ROOT_PASSWORD)" < $(MYSQL_DUMPS_DIR)/db.sql 2>/dev/null
|
||||
|
||||
phpmd:
|
||||
@docker-compose exec -T php \
|
||||
./app/vendor/bin/phpmd \
|
||||
./app/src \
|
||||
text cleancode,codesize,controversial,design,naming,unusedcode
|
||||
|
||||
test: code-sniff
|
||||
@docker-compose exec -T php ./app/vendor/bin/phpunit --colors=always --configuration ./app/
|
||||
@make resetOwner
|
||||
|
||||
resetOwner:
|
||||
@$(shell chown -Rf $(SUDO_USER):$(shell id -g -n $(SUDO_USER)) $(MYSQL_DUMPS_DIR) "$(shell pwd)/etc/ssl" "$(shell pwd)/web/app" 2> /dev/null)
|
||||
|
||||
.PHONY: clean test code-sniff init
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
# 用docker-compose 部署shopxo
|
||||
|
||||
## Nginx PHP MySQL
|
||||
|
||||
方案来源于 [nanoninja/docker-nginx-php-mysql](https://github.com/nanoninja/docker-nginx-php-mysql)涉及到php相关的内容,请参考该仓库
|
||||
|
||||
## 部署步骤
|
||||
|
||||
1. [安装docker](https://www.docker.com/)
|
||||
[国内用户安装docker](https://www.runoob.com/docker/ubuntu-docker-install.html)
|
||||
[docker从入门到实践](https://legacy.gitbook.com/book/yeasy/docker_practice/details)
|
||||
2. [安装docker-compose](https://docs.docker.com/compose/reference/overview/)
|
||||
|
||||
3. 克隆代码并且修改shopxo文件夹权限
|
||||
- git clone git@github.com:gongfuxiang/shopxo.git
|
||||
- sudo chmod -R 777 shopxo
|
||||
|
||||
4. 用docker-compose 运行项目包括数据库,如果不想用容器里面的数据库可以单独配置数据库
|
||||
- cd shopxo
|
||||
- docker-compose up
|
||||
- 访问 localhost:10000
|
||||
|
||||
5. 如果使用容器里面的数据库,可以将数据库的地址设置为容器名称 利用docker网络访问数据库
|
||||
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
version: '3'
|
||||
services:
|
||||
web:
|
||||
image: nginx
|
||||
volumes:
|
||||
- "./etc/nginx/default.conf:/etc/nginx/conf.d/default.conf"
|
||||
- "../:/var/www/html" # shopxo代码挂载在nginx里面
|
||||
- "./etc/nginx/default.template.conf:/etc/nginx/conf.d/default.template"
|
||||
ports:
|
||||
- "10000:80"
|
||||
- "3000:443"
|
||||
environment:
|
||||
- NGINX_HOST=${NGINX_HOST} # 可以设置nginx的域名
|
||||
command: /bin/sh -c "envsubst '$$NGINX_HOST' < /etc/nginx/conf.d/default.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"
|
||||
restart: always
|
||||
depends_on:
|
||||
- php
|
||||
- mysqldb
|
||||
php:
|
||||
image: nanoninja/php-fpm:7.4.4
|
||||
restart: always
|
||||
volumes:
|
||||
- "./etc/php/php.ini:/usr/local/etc/php/conf.d/php.ini"
|
||||
- "../:/var/www/html"
|
||||
|
||||
mysqldb:
|
||||
image: mysql:5.7
|
||||
container_name: mysql
|
||||
restart: always
|
||||
env_file:
|
||||
- ".env"
|
||||
environment:
|
||||
- MYSQL_DATABASE=yourdb
|
||||
- MYSQL_ROOT_PASSWORD=yourpasswd
|
||||
- MYSQL_USER=youruser
|
||||
- MYSQL_PASSWORD=yourpasswd
|
||||
ports:
|
||||
- "10001:3306"
|
||||
volumes:
|
||||
- "/data/shopxo_db:/var/lib/mysql" # mysql数据库持久化配置
|
||||
- "./etc/db/my.cnf:/etc/mysql/my.cnf" # 修改mysql配置,首页统计
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
#
|
||||
# The MySQL database server configuration file.
|
||||
#
|
||||
# You can copy this to one of:
|
||||
# - "/etc/mysql/my.cnf" to set global options,
|
||||
# - "~/.my.cnf" to set user-specific options.
|
||||
#
|
||||
# One can use all long options that the program supports.
|
||||
# Run program with --help to get a list of available options and with
|
||||
# --print-defaults to see which it would actually understand and use.
|
||||
#
|
||||
# For explanations see
|
||||
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
|
||||
|
||||
# This will be passed to all mysql clients
|
||||
# It has been reported that passwords should be enclosed with ticks/quotes
|
||||
# escpecially if they contain "#" chars...
|
||||
# Remember to edit /etc/mysql/debian.cnf when changing the socket location.
|
||||
|
||||
# Here is entries for some specific programs
|
||||
# The following values assume you have at least 32M ram
|
||||
[mysqld]
|
||||
sql_mode=STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
|
||||
|
||||
!includedir /etc/mysql/conf.d/
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
# Nginx configuration
|
||||
|
||||
server {
|
||||
listen 80 default_server;
|
||||
listen [::]:80 default_server;
|
||||
server_name localhost;
|
||||
|
||||
index index.php index.html;
|
||||
error_log /var/log/nginx/error.log;
|
||||
access_log /var/log/nginx/access.log;
|
||||
root /var/www/html/public;
|
||||
|
||||
location ~ \.php$ {
|
||||
try_files $uri =404;
|
||||
fastcgi_split_path_info ^(.+\.php)(/.+)$;
|
||||
fastcgi_pass php:9000;
|
||||
fastcgi_index index.php;
|
||||
include fastcgi_params;
|
||||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||
fastcgi_param PATH_INFO $fastcgi_path_info;
|
||||
}
|
||||
}
|
||||
|
||||
# server {
|
||||
# server_name localhost;
|
||||
|
||||
# listen 443 ssl;
|
||||
# fastcgi_param HTTPS on;
|
||||
|
||||
# ssl_certificate /etc/ssl/server.pem;
|
||||
# ssl_certificate_key /etc/ssl/server.key;
|
||||
# ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
|
||||
|
||||
# index index.php index.html;
|
||||
# error_log /var/log/nginx/error.log;
|
||||
# access_log /var/log/nginx/access.log;
|
||||
# root /var/www/html/public;
|
||||
|
||||
# location ~ \.php$ {
|
||||
# try_files $uri =404;
|
||||
# fastcgi_split_path_info ^(.+\.php)(/.+)$;
|
||||
# fastcgi_pass php:9000;
|
||||
# fastcgi_index index.php;
|
||||
# include fastcgi_params;
|
||||
# fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||
# fastcgi_param PATH_INFO $fastcgi_path_info;
|
||||
# }
|
||||
# }
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
# Nginx configuration
|
||||
|
||||
server {
|
||||
listen 80 default_server;
|
||||
listen [::]:80 default_server;
|
||||
server_name ${NGINX_HOST};
|
||||
|
||||
index index.php index.html;
|
||||
error_log /var/log/nginx/error.log;
|
||||
access_log /var/log/nginx/access.log;
|
||||
root /var/www/html/public;
|
||||
|
||||
location ~ \.php$ {
|
||||
try_files $uri =404;
|
||||
fastcgi_split_path_info ^(.+\.php)(/.+)$;
|
||||
fastcgi_pass php:9000;
|
||||
fastcgi_index index.php;
|
||||
include fastcgi_params;
|
||||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||
fastcgi_param PATH_INFO $fastcgi_path_info;
|
||||
}
|
||||
}
|
||||
|
||||
# server {
|
||||
# server_name ${NGINX_HOST};
|
||||
|
||||
# listen 443 ssl;
|
||||
# fastcgi_param HTTPS on;
|
||||
|
||||
# ssl_certificate /etc/ssl/server.pem;
|
||||
# ssl_certificate_key /etc/ssl/server.key;
|
||||
# ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
|
||||
|
||||
# index index.php index.html;
|
||||
# error_log /var/log/nginx/error.log;
|
||||
# access_log /var/log/nginx/access.log;
|
||||
# root /var/www/html/public;
|
||||
|
||||
# location ~ \.php$ {
|
||||
# try_files $uri =404;
|
||||
# fastcgi_split_path_info ^(.+\.php)(/.+)$;
|
||||
# fastcgi_pass php:9000;
|
||||
# fastcgi_index index.php;
|
||||
# include fastcgi_params;
|
||||
# fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||
# fastcgi_param PATH_INFO $fastcgi_path_info;
|
||||
# }
|
||||
# }
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
; PHP Configuration
|
||||
|
||||
;[Date]
|
||||
; Defines the default timezone used by the date functions
|
||||
; http://php.net/date.timezone
|
||||
;date.timezone =
|
||||
|
||||
; Error handling
|
||||
;display_errors = Off
|
||||
|
||||
; Xdebug
|
||||
; See https://xdebug.org/docs/all_settings
|
||||
|
||||
;PHPStorm
|
||||
[Xdebug]
|
||||
xdebug.remote_enable=1
|
||||
xdebug.idekey=PHPSTORM
|
||||
xdebug.profiler_enable=0
|
||||
xdebug.max_nesting_level=700
|
||||
xdebug.remote_host=192.168.0.1 # your ip
|
||||
xdebug.remote_port=9000
|
||||
|
||||
;Netbeans
|
||||
;[Xdebug]
|
||||
;xdebug.remote_enable=1
|
||||
;xdebug.remote_handler=dbgp
|
||||
;xdebug.remote_mode=req
|
||||
;xdebug.remote_host=192.168.0.1 # your ip
|
||||
;xdebug.remote_port=9000
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
"require": {
|
||||
|
||||
},
|
||||
"require-dev": {
|
||||
"apigen/apigen": "dev-master",
|
||||
"phpmd/phpmd": "@stable",
|
||||
"phpunit/phpunit": "^7.0",
|
||||
"roave/better-reflection": "dev-master",
|
||||
"squizlabs/php_codesniffer": "3.*"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"App\\Acme\\": "src/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"AppTest\\Acme\\": "test/"
|
||||
}
|
||||
},
|
||||
"minimum-stability": "stable",
|
||||
"prefer-stable": true
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd" bootstrap="test/bootstrap.php" colors="true">
|
||||
|
||||
<testsuites>
|
||||
<testsuite name="PHP Test suite">
|
||||
<directory>./test/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<filter>
|
||||
<whitelist addUncoveredFilesFromWhitelist="false">
|
||||
<directory suffix=".php">./src</directory>
|
||||
<exclude>
|
||||
<directory suffix=".php">./vendor</directory>
|
||||
</exclude>
|
||||
</whitelist>
|
||||
</filter>
|
||||
|
||||
<php>
|
||||
<ini name="date.timezone" value="UTC"/>
|
||||
</php>
|
||||
|
||||
<logging>
|
||||
<log type="coverage-html" target="./report/phpunit"/>
|
||||
<log type="coverage-text" target="php://stdout" showUncoveredFiles="false"/>
|
||||
</logging>
|
||||
</phpunit>
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace App\Acme;
|
||||
|
||||
class Foo
|
||||
{
|
||||
public function getName()
|
||||
{
|
||||
return 'Nginx PHP MySQL';
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
|
||||
namespace AppTest\Acme;
|
||||
|
||||
use App\Acme\Foo;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class FooTest extends TestCase
|
||||
{
|
||||
public function testGetName()
|
||||
{
|
||||
$foo = new Foo();
|
||||
$this->assertEquals($foo->getName(), 'Nginx PHP MySQL');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
error_reporting(E_ALL | E_STRICT);
|
||||
|
||||
/**
|
||||
* Setup autoloading
|
||||
*/
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
|
||||
include '../app/vendor/autoload.php';
|
||||
$foo = new App\Acme\Foo();
|
||||
|
||||
?><!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Docker <?php echo $foo->getName(); ?></title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Docker <?php echo $foo->getName(); ?></h1>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Reference in New Issue