feature: support packagist

This commit is contained in:
kriss 2022-05-26 19:24:09 +08:00
parent 65bb536d49
commit 3734c45884
6 changed files with 151 additions and 5 deletions

1
.gitattributes vendored Normal file
View File

@ -0,0 +1 @@
/.github export-ignore

View File

@ -1,21 +1,37 @@
# webman docker
## 简介
将 docker 用于 webman 的开发和生产部署
### 镜像地址和 tag
[docker hub](https://hub.docker.com/r/krisss/docker-webman)
- krisss/docker-webman:7.4-cli-alpine
- krisss/docker-webman:8.0-cli-alpine
- krisss/docker-webman:8.1-cli-alpine
会通过 github actions 动态更新 php 的小版本,镜像 tag 名不变
> 此镜像会通过 github actions 动态更新 php 的小版本,镜像 tag 名不变
## 镜像中的组件
### 镜像中的组件
- [php](https://hub.docker.com/_/php): extension 包含bcmath、event、gd、mysqli、pdo_mysql、opcache、pcntl、redis、sockets、zip
- [composer](https://getcomposer.org/)
- [install-php-extensions](https://github.com/mlocati/docker-php-extension-installer)
- [supervisor](http://supervisord.org/)
## 当开发环境使用:目前代码未建立
## 安装
```bash
composer require kriss/webman-docker
```
会在项目根目录下提供 `Dockerfile` 用于构建镜像,提供 `docker-compose.yml` 用于开发
## 使用
### 当开发环境使用:目前代码未建立
启动镜像
@ -44,7 +60,7 @@ php start.php start
访问 http://localhost:8787 即可
## 当开发环境使用:已有 webman 代码
### 当开发环境使用:已有 webman 代码
在项目下自建 `docker-compose.yml`,参考例子如下:
@ -69,7 +85,7 @@ docker-compose up
访问 http://localhost:8787 即可
## 打包项目成镜像
### 打包项目成镜像
在项目下自建 `Dockerfile`,参考例子如下:

13
composer.json Normal file
View File

@ -0,0 +1,13 @@
{
"name": "kriss/webman-docker",
"type": "library",
"license": "MIT",
"description": "docker for webman app",
"require": {
},
"autoload": {
"psr-4": {
"Kriss\\WebmanDocker\\": "src"
}
}
}

75
src/Install.php Normal file
View File

@ -0,0 +1,75 @@
<?php
namespace Kriss\WebmanDocker;
class Install
{
const WEBMAN_PLUGIN = true;
/**
* @var array
*/
protected static $pathRelation = array (
'copy/Dockerfile' => 'Dockerfile',
'copy/docker-compose.yml' => 'docker-compose.yml',
);
/**
* Install
* @return void
*/
public static function install()
{
static::installByRelation();
}
/**
* Uninstall
* @return void
*/
public static function uninstall()
{
self::uninstallByRelation();
}
/**
* installByRelation
* @return void
*/
public static function installByRelation()
{
foreach (static::$pathRelation as $source => $dest) {
if ($pos = strrpos($dest, '/')) {
$parent_dir = base_path().'/'.substr($dest, 0, $pos);
if (!is_dir($parent_dir)) {
mkdir($parent_dir, 0777, true);
}
}
//symlink(__DIR__ . "/$source", base_path()."/$dest");
copy_dir(__DIR__ . "/$source", base_path()."/$dest");
echo "Create $dest
";
}
}
/**
* uninstallByRelation
* @return void
*/
public static function uninstallByRelation()
{
foreach (static::$pathRelation as $source => $dest) {
$path = base_path()."/$dest";
if (!is_dir($path) && !is_file($path)) {
continue;
}
echo "Remove $dest
";
if (is_file($path) || is_link($path)) {
unlink($path);
continue;
}
remove_dir($path);
}
}
}

31
src/copy/Dockerfile Normal file
View File

@ -0,0 +1,31 @@
# 用于将项目构建成镜像
ARG WEBMAN_DOCKER_VERSION=7.4-cli-alpine
# https://github.com/krissss/docker-webman
FROM krisss/docker-webman:$WEBMAN_DOCKER_VERSION
# 增加额外的扩展
#RUN install-php-extensions imagick
# 设置配置文件
# 自定义 php 配置文件,如果需要的话
# 覆盖镜像自带的
#COPY environments/docker/php.ini "$PHP_INI_DIR/conf.d/app.ini"
# 扩展额外的
#COPY environments/docker/my_php.ini "$PHP_INI_DIR/conf.d/my_php.ini"
# 自定义 supervisor 配置,如果需要的话
# 覆盖镜像自带的
#COPY environments/docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
# 扩展额外的
#COPY environments/docker/my_supervisord.conf /etc/supervisor/conf.d/my_supervisord.conf
# 预先加载 Composer 包依赖,优化 Docker 构建镜像的速度
COPY ./composer.json /app/
COPY ./composer.lock /app/
RUN composer install --no-interaction --no-dev --no-autoloader --no-scripts
# 复制项目代码
COPY . /app
# 执行 Composer 自动加载和相关脚本
RUN composer install --no-interaction --no-dev && composer dump-autoload

View File

@ -0,0 +1,10 @@
# 用于开发环境
version: "3.7"
services:
webman:
image: krisss/docker-webman:${DOCKER_WEBMAN_VERSION:-7.4-cli-alpine}
ports:
- "${DOCKER_WEBMAN_PORT:-8787}:8787"
volumes:
- .:/app