Skip to content

Commit

Permalink
Release 4.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
roquie committed Jan 3, 2021
1 parent 40c2425 commit 20fcf70
Show file tree
Hide file tree
Showing 106 changed files with 4,030 additions and 5,071 deletions.
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ jobs:
test_deps:
docker:
# specify the version you desire here
- image: roquie/composer-parallel
- image: composer/composer:2

working_directory: ~/repo

Expand All @@ -26,7 +26,7 @@ jobs:
test_run:
docker:
# specify the version you desire here
- image: spacetabio/static-server-php:2.1.0-xdebug
- image: spacetabio/static-server-php:4.0.0-xdebug

working_directory: ~/repo

Expand All @@ -37,7 +37,7 @@ jobs:
- v1-dependencies-{{ checksum "composer.lock" }}
- v1-dependencies-

- run: vendor/bin/phpstan analyse src --level 6
- run: vendor/bin/phpstan analyse src --level 4
- run: vendor/bin/phpunit --coverage-clover=coverage.xml
- run: apk add bash
- run: bash -c "bash <(curl -s https://codecov.io/bash)"
Expand Down
36 changes: 34 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,36 @@
## [4.0.0] - 2020-01-03

### Added

None.

### Changed

* Upgrades Composer to `2.0` version.
* Upgrades NGINX to `1.19.6` version.
* Upgrades NGINX Brotli Module to `1.0.9` version.
* Upgrades PHP to `8.0` version.
* Upgrades PHPUNIT configuration file to new schema.
* Update LICENSE and README year from 2020 to 2021 🎇
* Completely rewritten sources code and now it became more simplified.
* PHP performs the role of "template engine" to generate NGINX configuration
and read/forward the `Spacetab` configuration. Does not control the NGINX process.
* 99% backward compatibility.
* Using asynchronous non-blocking i/o.
* Web-server configuration files separated to easily configuring.

### Removed

* Removed `box-project/box` from project dependencies. Now uses separated docker image to build a phar-archive.
* Removed code which is responsible for dist-code modification. Because is too hard for understanding and this project
is too small for such an abstraction layer. Now dist-code modification is enabled by default and no option to
disable it.
* A lot of many composer packages that no need anymore...

### Fixed

* A potential fix of bug when web-server spawn zombie processes.

## [3.2.1] - 2020-06-03

### Added
Expand Down Expand Up @@ -107,11 +140,10 @@ cloud-services or local instances.

- Option `server.prerender.token`. Use `server.prerender.headers` option.


## [2.0.0] - 2020-01-09

Released new version of SPA-webserver.
Full backward compatibility with previous 1.0.0 version except
compression options (it not configurable more). From this version
compression options (it is not configurable more). From this version
changelog will be started.

2 changes: 1 addition & 1 deletion CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ further defined and clarified by project maintainers.
## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at bip@teamc.io. All
reported by contacting the project team at bip@spacetab.io. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Expand Down
39 changes: 28 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,36 @@
FROM roquie/composer-parallel:1
FROM composer/composer:2 AS deps

COPY . /app

RUN composer install --no-ansi --no-interaction --no-progress --no-scripts --ignore-platform-reqs \
&& vendor/bin/box compile
RUN composer install --no-ansi --no-interaction --no-progress --no-scripts --ignore-platform-reqs

FROM php:7.4-cli-alpine
FROM spacetabio/box-php:1.0.0 AS build

ENV NGINX_VERSION 1.16.1
ENV NGX_BROTLI_COMMIT e505dce68acc190cc5a1e780a3b0275e39f160ca
WORKDIR /app
COPY --from=deps /app /app
RUN box compile

FROM php:8.0-cli-alpine

ENV NGINX_VERSION 1.19.6
ENV NGX_BROTLI_COMMIT 9aec15e2aa6feea2113119ba06460af70ab3ea62

RUN set -xe \
apk update --no-cache \
&& apk add --no-cache ca-certificates \
&& docker-php-ext-install pcntl \
&& mkdir /run/nginx

# ERROR: In UvDriver.php line 531: Could not create directory
#
# && apk add --no-cache autoconf g++ libtool pcre make libuv libuv-dev git ca-certificates \
# && docker-php-ext-configure opcache --enable-opcache \
# && docker-php-ext-install -j $(nproc) opcache \
# && git clone https://github.com/bwoebi/php-uv.git \
# && cd php-uv \
# && git checkout -b $PHP_UV_COMMIT $PHP_UV_COMMIT \
# && phpize && ./configure && make -j $(nproc) && make install \
# && docker-php-ext-enable uv

RUN GPG_KEYS=B0F4253373F8F6F510D42178520A9993A1C052F8 \
&& CONFIG="\
--prefix=/etc/nginx \
Expand Down Expand Up @@ -156,12 +171,14 @@ RUN GPG_KEYS=B0F4253373F8F6F510D42178520A9993A1C052F8 \
&& ln -sf /dev/stdout /var/log/nginx/access.log \
&& ln -sf /dev/stderr /var/log/nginx/error.log

COPY --from=0 /app/bin/server.phar /usr/bin/server
COPY --from=0 /app/dist /app
COPY --from=0 /app/configuration /app/configuration
COPY --from=build /app/bin/template.phar /usr/bin/template
COPY --from=build /app/bin/server /usr/bin/server
COPY --from=build /app/dist /app
COPY --from=build /app/configuration /app/configuration

ENV SERVER_VERSION "{{ version }}"
RUN chmod +x /usr/bin/server
RUN chmod +x /usr/bin/server \
&& chmod +x /usr/bin/template

EXPOSE 8080
WORKDIR /app
Expand Down
15 changes: 12 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
IMAGE = spacetabio/static-server-php
VERSION = 3.2.1
VERSION = 4.0.0
FILE = Dockerfile

image:
Expand All @@ -13,5 +13,14 @@ run:
docker run --rm -it --init -p 8088:8080 $(IMAGE):$(VERSION)

test:
docker run -w /app --entrypoint bash --rm -it --init -v `pwd`/:/app \
spacetabio/static-server-php:3.1.0-xdebug -c "vendor/bin/phpunit"
docker run -w /app --entrypoint sh --rm -it --init -v `pwd`/:/app \
$(IMAGE):4.0.0-xdebug -c "vendor/bin/phpunit"

image_test:
docker build -t $(IMAGE):4.0.0-xdebug -f test.dockerfile .

image_box:
docker build -t spacetabio/box-php:1.0.0 -f box.dockerfile .

push_box:
docker push spacetabio/box-php:1.0.0
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Compatible with: Vue, React, Angular, etc.

### Dockerfile sample
```Dockerfile
FROM spacetabio/static-server-php:3.2.1
FROM spacetabio/static-server-php:4.0.0

ARG VCS_SHA1
ARG STAGE
Expand Down
76 changes: 37 additions & 39 deletions bin/server
Original file line number Diff line number Diff line change
@@ -1,46 +1,44 @@
#!/usr/bin/env php
<?php
#!/bin/sh

use Spacetab\Logger\Logger;
use StaticServer\Application as Server;
use StaticServer\Console\DumpConfigCommand;
use StaticServer\Console\ReloadServerCommand;
use StaticServer\Console\RunServerCommand;
use StaticServer\Console\SignalHandler;
use StaticServer\Console\StopServerCommand;
use Symfony\Component\Console\Application;
set -e

$locations = [
__DIR__ . '/../../../autoload.php',
__DIR__ . '/../vendor/autoload.php',
__DIR__ . '/vendor/autoload.php'
];
# export PATH="$PATH:$(pwd)/bin"

foreach ($locations as $file) {
if (file_exists($file)) {
require_once $file;
break;
}
}
SERVER_CONFIG_PATH="$(template handler --dump config)"

$logger = Logger::default('Fatal');
CLEAR='\033[0m'
RED='\033[0;31m'

pcntl_async_signals(true);
usage() {
echo "Static webserver. Version: $SERVER_VERSION"
if [ -n "$1" ]; then
echo "${RED}👉 $1${CLEAR}\n";
fi
echo "Usage: $0 [ run | reload | stop | dump ]"
echo ""
echo "Example: $0 run or STAGE=local $0 run"
exit 1
}

$sig = new SignalHandler();
pcntl_signal(SIGTERM, [$sig, 'handle']);
pcntl_signal(SIGINT, [$sig, 'handle']);
pcntl_signal(SIGQUIT, [$sig, 'handle']);
pcntl_signal(SIGUSR1, [$sig, 'handle']);
while [ "$#" -gt 0 ]; do
case $1 in
run) run=1; ;;
reload) reload=1; ;;
stop) stop=1; ;;
dump) dump=1; ;;
*) usage "Unknown parameter passed: $1" ;;
esac
shift
done

try {
$app = new Application('Static server', getenv('SERVER_VERSION'));
$app->add(new RunServerCommand());
$app->add(new StopServerCommand());
$app->add(new DumpConfigCommand());
$app->add(new ReloadServerCommand());
$app->run();
} catch (Throwable $e) {
$logger->critical($e->getMessage(), ['trace' => $e->getTraceAsString()]);
exit(1);
}
if [ "$run" = "1" ]; then
template generate && nginx -c "$SERVER_CONFIG_PATH"
elif [ "$reload" = "1" ]; then
template generate && nginx -c "$SERVER_CONFIG_PATH" -s reload
elif [ "$stop" = "1" ]; then
template generate && nginx -c "$SERVER_CONFIG_PATH" -s stop
elif [ "$dump" = "1" ]; then
template dump
else
usage
fi
34 changes: 34 additions & 0 deletions bin/template
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env php
<?php

use Spacetab\Logger\Logger;
use Spacetab\Server\Console\DumpCommand;
use Spacetab\Server\Console\GenerateCommand;
use Spacetab\Server\Console\HandlerCommand;
use Symfony\Component\Console\Application;

$locations = [
__DIR__ . '/../../../autoload.php',
__DIR__ . '/../vendor/autoload.php',
__DIR__ . '/vendor/autoload.php'
];

foreach ($locations as $file) {
if (file_exists($file)) {
require_once $file;
break;
}
}

$logger = Logger::default('Fatal');

try {
$app = new Application('Static server', getenv('SERVER_VERSION'));
$app->add(new DumpCommand());
$app->add(new GenerateCommand());
$app->add(new HandlerCommand());
$app->run();
} catch (Throwable $e) {
$logger->critical($e->getMessage(), ['trace' => $e->getTraceAsString()]);
exit(1);
}
17 changes: 17 additions & 0 deletions box.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM php:8.0-cli-alpine

RUN wget https://github.com/box-project/box/releases/download/3.11.1/box.phar \
&& mv box.phar /usr/local/bin/box \
&& chmod +x /usr/local/bin/box

RUN set -xe \
apk update --no-cache \
&& apk add --no-cache icu icu-dev ca-certificates \
&& docker-php-ext-install intl

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# It validates requirements first, then print command list.
RUN box

ENTRYPOINT ["box"]
4 changes: 2 additions & 2 deletions box.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"output": "bin/server.phar",
"main": "bin/server"
"output": "bin/template.phar",
"main": "bin/template"
}
42 changes: 23 additions & 19 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,45 @@
}
],
"require": {
"php": ">=7.4",
"ext-json": "*",
"php": "^8.0",
"ext-dom": "*",
"ext-pcntl": "*",
"ext-posix": "*",
"spacetab-io/configuration": "3.*",
"masterminds/html5": "^2.5",
"symfony/console": "^4 || ^5",
"spacetab-io/logger": "^2.0",
"symfony/filesystem": "^4 || ^5",
"symfony/process": "^4 || ^5",
"ext-json": "*",
"ext-simplexml": "*",
"amphp/amp": "^2.5",
"amphp/file": "dev-master#7abe3d5f27a55613b248cc365d5691ccd343591e",
"amphp/http-client": "^4.5",
"amphp/process": "^1.1",
"league/plates": "^3.3",
"geerlingguy/ping": "^1.2"
"spacetab-io/configuration": "3.*",
"spacetab-io/logger": "^2",
"symfony/console": "^5"
},
"require-dev": {
"roave/security-advisories": "dev-master",
"symfony/var-dumper": "^4 || ^5",
"amphp/phpunit-util": "^1.4",
"jetbrains/phpstorm-attributes": "^1.0",
"phpstan/phpstan": "^0.12",
"phpunit/phpunit": "^9",
"humbug/box": "^3.8",
"phpstan/phpstan": "^0.12"
"roave/security-advisories": "dev-master",
"symfony/var-dumper": "^5"
},
"autoload": {
"psr-4": {
"StaticServer\\": "src"
"Spacetab\\Server\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"StaticServer\\Tests\\": "tests"
"Spacetab\\Tests\\Server\\": "tests"
}
},
"scripts": {
"test": [
"phpstan analyse src --level 6",
"phpunit"
"phpstan analyse src --level 4",
"XDEBUG_MODE=coverage phpunit --coverage-text"
]
},
"config": {
"sort-packages": true,
"optimize-autoloader": true
}
}
Loading

0 comments on commit 20fcf70

Please sign in to comment.