Skip to content

Commit

Permalink
✨ 封装RedLock、Ssl、SwowHandler等等功能模块,具体如下:
Browse files Browse the repository at this point in the history
- 增加SwowHandler封装实现类。
  • Loading branch information
何平 authored and 何平 committed May 30, 2023
0 parents commit 1c278a1
Show file tree
Hide file tree
Showing 70 changed files with 3,016 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
APP_NAME=swow-skeleton
APP_DEBUG=true
ENABLE_SSL=true

# Mysql
DB_DRIVER=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=hyperf
DB_USERNAME=root
DB_PASSWORD=
DB_CHARSET=utf8mb4
DB_COLLATION=utf8mb4_unicode_ci
DB_PREFIX=

# Redis
REDIS_HOST=127.0.0.1
REDIS_AUTH=(null)
REDIS_PORT=6379
REDIS_DB=0
Empty file added .github/init.sql
Empty file.
17 changes: 17 additions & 0 deletions .github/swoole.install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
sudo apt-get update
sudo apt-get install libcurl4-openssl-dev libc-ares-dev libpq-dev
wget https://github.com/swoole/swoole-src/archive/${SW_VERSION}.tar.gz -O swoole.tar.gz
mkdir -p swoole
tar -xf swoole.tar.gz -C swoole --strip-components=1
rm swoole.tar.gz
cd swoole
phpize
./configure --enable-openssl --enable-swoole-curl --enable-cares --enable-swoole-pgsql
make -j$(nproc)
sudo make install
sudo sh -c "echo extension=swoole > /etc/php/${PHP_VERSION}/cli/conf.d/swoole.ini"
sudo sh -c "echo swoole.use_shortname='Off' >> /etc/php/${PHP_VERSION}/cli/conf.d/swoole.ini"
php --ri swoole
cd ..
rm -rf swoole
12 changes: 12 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Build Docker

on: [ push, pull_request ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Build
run: docker build -t swow-skeleton .
25 changes: 25 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
on:
push:
# Sequence of patterns matched against refs/tags
tags:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10

name: Release

jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false
205 changes: 205 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
name: PHPUnit for Hyperf

on: [ push, pull_request ]

env:
SW_VERSION: 'develop'

jobs:
unix-tests:
name: Test on ${{ matrix.os }} with PHP ${{ matrix.php-version }}
runs-on: '${{ matrix.os }}'
strategy:
matrix:
os: [ 'ubuntu-latest', 'macos-latest' ]
php-version: [ '8.0', '8.1' ]
max-parallel: 4
fail-fast: false
env:
setupphp_exts: igbinary, msgpack, redis
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup cache environment
id: extcache
uses: shivammathur/cache-extensions@v1
with:
php-version: ${{ matrix.php-version }}
extensions: ${{ env.setupphp_exts }}
key: ${{ runner.os }}-setupphpext-v1-

- name: Cache extensions
uses: actions/cache@v2
with:
path: ${{ steps.extcache.outputs.dir }}
key: ${{ steps.extcache.outputs.key }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
tools: phpize, php-config
extensions: ${{ env.setupphp_exts }}
ini-values: extension=swow, opcache.enable_cli=0
coverage: none

- name: Setup Valgrind
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y valgrind
- name: Fetch Swow revison
id: swow-getref
shell: php {0}
run: |
<?php
$context = stream_context_create([
'http'=>[
'header'=>
"User-Agent: not-curl/0.1\r\n".
"Accept: application/vnd.github.v3+json\r\n".
"Authorization: Bearer ${{ github.token }}\r\n"
]]);
$uri = 'https://api.github.com/repos/swow/swow/git/ref/heads/${{ env.SW_VERSION }}';
$ref = json_decode(file_get_contents($uri, false, $context))->object->sha;
echo "::set-output name=swowref::" . $ref . PHP_EOL;
- name: Cache Swow
uses: actions/cache@v2
id: swow-cache
with:
path: swow
key: ${{ runner.os }}-swowext-${{ matrix.php-version }}-${{ steps.swow-getref.outputs.swowref }}

- name: Checkout Swow
if: steps.swow-cache.outputs.cache-hit != 'true'
uses: actions/checkout@v2
with:
repository: swow/swow
ref: ${{ steps.swow-getref.outputs.swowref }}
path: swow

- name: Setup Swow
run: |
if [ x${{ steps.swow-cache.outputs.cache-hit }} != 'xtrue' ]
then
echo "::group::Build swow"
cd swow/ext
phpize
./configure --enable-swow-debug
make -j `${{ runner.os == 'Linux' && 'nproc' || 'sysctl -n hw.logicalcpu' }}`
echo "::endgroup::"
else
cd swow/ext || exit 1
fi
echo "::group::Install swow"
sudo make install || exit 1
echo "::endgroup::"
- name: Setup Packages
run: composer update -o
- name: Run Test Cases
run: |
composer analyse
composer test
win-tests:
name: Test on ${{ matrix.os }} with PHP ${{ matrix.php-version }}
runs-on: '${{ matrix.os }}'
strategy:
matrix:
os: [ 'windows-2019' ]
php-version: [ '8.0', '8.1' ]
max-parallel: 2
fail-fast: false
env:
setupphp_exts: igbinary, msgpack, redis
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup cache environment
id: extcache
uses: shivammathur/cache-extensions@v1
with:
php-version: ${{ matrix.php-version }}
extensions: ${{ env.setupphp_exts }}
key: ${{ runner.os }}-setupphpext-v1-

- name: Cache extensions
uses: actions/cache@v2
with:
path: ${{ steps.extcache.outputs.dir }}
key: ${{ steps.extcache.outputs.key }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: ${{ env.setupphp_exts }},pdo_mysql
coverage: none

- name: Fetch Swow revison
id: swow-getref
shell: php {0}
run: |
<?php
$context = stream_context_create([
'http'=>[
'header'=>
"User-Agent: not-curl/0.1\r\n".
"Accept: application/vnd.github.v3+json\r\n".
"Authorization: Bearer ${{ github.token }}\r\n"
]]);
$uri = 'https://api.github.com/repos/swow/swow/git/ref/heads/${{ env.SW_VERSION }}';
$ref = json_decode(file_get_contents($uri, false, $context))->object->sha;
echo "::set-output name=swowref::" . $ref . PHP_EOL;
- name: Cache Swow
uses: actions/cache@v2
id: swow-cache
with:
path: swow
key: ${{ runner.os }}-swowext-${{ matrix.php-version }}-${{ steps.swow-getref.outputs.swowref }}

- name: Checkout Swow
if: steps.swow-cache.outputs.cache-hit != 'true'
uses: actions/checkout@v2
with:
repository: swow/swow
ref: ${{ steps.swow-getref.outputs.swowref }}
path: swow

- name: Build Swow
if: steps.swow-cache.outputs.cache-hit != 'true'
uses: ./swow/.github/workflows/winext
with:
ext-path: ./swow/ext
tools-path: C:\tools\phpdev
conf-args: --enable-swow-debug --enable-swow-ssl --enable-swow-curl
ext-name: swow
deps: openssl,libcurl,libssh2,zlib,nghttp2
install: 0

- name: Install Swow
shell: powershell
env:
BUILD_DIR: 'x64\Release'
UNIX_COLOR: '1'
run: |
Write-Host "::group::Installing Swow"
.\swow\.github\workflows\winext\install.ps1 `
-ExtPath swow\ext `
-ExtName swow `
-Enable 1
if ($lastexitcode -Ne 0) {
exit 1
}
- name: Setup Packages
run: composer update -o
- name: Run Test Cases
run: |
composer analyse
composer test
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.buildpath
.settings/
.project
*.patch
.idea/
.git/
runtime/
vendor/
.phpintel/
.env
.DS_Store
*.cache
*.lock
swow-test/
swow-examples/
ssl/
73 changes: 73 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# usermod -aG docker gitlab-runner

stages:
- unit
- build
- deploy

variables:
PROJECT_NAME: hyperf
REGISTRY_URL: registry-docker.org
GIT_SUBMODULE_STRATEGY: recursive

unit:
stage: unit
image: hyperf/docker-ci:latest
resource_group: $CI_PROJECT_NAME
variables:
DOCKER_TLS_CERTDIR: ""
DOCKER_DRIVER: overlay2
before_script:
- cp .env.example .env
script:
- APP_ENV=test docker-compose up -d --remove-orphans --build
- docker exec $(basename $(pwd))_hyperf_1 composer install
- docker exec $(basename $(pwd))_hyperf_1 composer analyse
- docker exec $(basename $(pwd))_hyperf_1 vendor/bin/php-cs-fixer fix --dry-run
- docker exec $(basename $(pwd))_hyperf_1 composer test
after_script:
- docker-compose down
tags:
- unit

build_test_docker:
stage: build
script:
- docker build . -t $PROJECT_NAME
- docker tag $PROJECT_NAME $REGISTRY_URL/$PROJECT_NAME:test
- docker push $REGISTRY_URL/$PROJECT_NAME:test
only:
- test
tags:
- builder

deploy_test_docker:
stage: deploy
script:
- docker stack deploy -c deploy.test.yml --with-registry-auth $PROJECT_NAME
only:
- test
tags:
- test

build_docker:
stage: build
script:
- docker build . -t $PROJECT_NAME
- docker tag $PROJECT_NAME $REGISTRY_URL/$PROJECT_NAME:$CI_COMMIT_REF_NAME
- docker tag $PROJECT_NAME $REGISTRY_URL/$PROJECT_NAME:latest
- docker push $REGISTRY_URL/$PROJECT_NAME:$CI_COMMIT_REF_NAME
- docker push $REGISTRY_URL/$PROJECT_NAME:latest
only:
- tags
tags:
- builder

deploy_docker:
stage: deploy
script:
- echo SUCCESS
only:
- tags
tags:
- builder
Loading

0 comments on commit 1c278a1

Please sign in to comment.