-
-
Save AlexSJ/825f52d26556ab434fd3acb4b3825d1a to your computer and use it in GitHub Desktop.
Hyperf Proxy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DOCKER_USER=1000 | |
DOCKER_UID=1000 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services: | |
app: | |
build: | |
context: . | |
dockerfile: ./Dockerfile.dev | |
target: app | |
args: | |
user: ${DOCKER_USER} | |
uid: ${DOCKER_UID} | |
image: hyperf-massacote | |
container_name: hyperf_massacote | |
entrypoint: ["php", "bin/hyperf.php", "server:watch"] | |
tty: true | |
ports: | |
- '9501:9501' | |
volumes: | |
- ./:/app | |
composer: | |
build: | |
context: . | |
dockerfile: ./Dockerfile.dev | |
target: composer | |
args: | |
user: ${DOCKER_USER} | |
uid: ${DOCKER_UID} | |
volumes: | |
- ./:/app | |
working_dir: /app | |
profiles: | |
- setup |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################################ | |
# | |
# base php | |
# | |
############################################################ | |
FROM php:8.2-cli as base-php | |
ENV TZ="America/Sao_Paulo" | |
ARG user | |
ARG uid | |
WORKDIR /app | |
# Create system user to run Composer and Hyperf Commands | |
RUN useradd -G www-data,root -u $uid -d /home/$user $user | |
RUN mkdir -p /home/$user/.composer && \ | |
chown -R $user:$user /home/$user | |
############################################################ | |
# | |
# composer build | |
# | |
############################################################ | |
FROM base-php as composer | |
COPY ./ /app | |
# update apt and install base packages | |
RUN apt-get update -qq \ | |
&& apt-get upgrade -qq -y \ | |
&& apt-get install -qq -y \ | |
libzip-dev | |
# install ext required by phpoffice/phpspreadsheet | |
RUN docker-php-ext-install zip | |
# install composer | |
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer | |
USER $user | |
############################################################ | |
# | |
# app build | |
# | |
############################################################ | |
FROM base-php as app | |
# update apt and install base packages | |
RUN apt-get update -qq \ | |
&& apt-get upgrade -qq -y \ | |
&& apt-get install -qq -y \ | |
libfreetype6-dev \ | |
libjpeg62-turbo-dev \ | |
libwebp-dev \ | |
libpng-dev \ | |
libzip-dev \ | |
libssl-dev \ | |
nano | |
# install php modules | |
RUN docker-php-ext-install -j$(nproc) pdo_mysql pcntl | |
# install swoole | |
RUN printf "no\nyes\nno\nno\n" | pecl install swoole | |
RUN docker-php-ext-enable swoole | |
# cleanup apt files | |
RUN apt-get clean -qq -y \ | |
&& apt-get autoremove -qq -y \ | |
&& rm -rf /var/lib/apt/lists/* | |
USER $user | |
EXPOSE 9501 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace App\Controller; | |
use Hyperf\Guzzle\ClientFactory; | |
use function Hyperf\Config\config; | |
class ProxyController extends AbstractController | |
{ | |
public function process(ClientFactory $clientFactory, $endpoint) | |
{ | |
$vindiClient = $clientFactory->create([ | |
'base_uri' => config('vindi_base_url'), | |
'auth' => [config('vindi_api_key'), '', 'BASIC'], | |
'http_errors' => false, | |
]); | |
$request = $vindiClient->request($this->request->getMethod(), $endpoint, [ | |
'form_params' => $this->request->all(), | |
]); | |
return $this->response->raw($request->getBody()->getContents())->withStatus($request->getStatusCode()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
use App\Controller\ProxyController; | |
Router::addRoute(['GET', 'POST', 'PUT', 'DELETE'], '/proxy/{endpoint:.+}', [ProxyController::class, 'process']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment