Skip to content

Commit

Permalink
feat: improve demo (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
priyadi authored Sep 7, 2024
1 parent 3285771 commit 3f6ddb7
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 28 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# 0.17.1

* fix: LIMIT & OFFSET are not supported with replacing select count(*)
* feat: improve demo

# 0.17.0

Expand Down
22 changes: 15 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Use an official PHP runtime as a parent image
FROM php:8.3-apache
ENV APACHE_DOCUMENT_ROOT /var/www/html/tests/public
ENV TERM xterm-256color
ENV APACHE_DOCUMENT_ROOT=/var/www/html/tests/public
ENV TERM=xterm-256color
ENV TTYD_VERSION=1.7.7

# Set the working directory in the container
WORKDIR /var/www/html
Expand All @@ -10,23 +11,30 @@ WORKDIR /var/www/html
RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf
RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf

# Enable Apache mod_rewrite
RUN a2enmod rewrite

# Install PHP extensions and other dependencies
RUN apt-get update && \
apt-get install -y libicu-dev && \
apt-get install -y supervisor libicu-dev && \
docker-php-ext-install intl && \
docker-php-ext-install pcntl

# Enable Apache mod_rewrite
RUN a2enmod rewrite proxy proxy_wstunnel proxy_http

# install ttyd
RUN curl -fsSL https://github.com/tsl0922/ttyd/releases/download/1.7.7/ttyd.x86_64 -o /usr/local/bin/ttyd && \
chmod +x /usr/local/bin/ttyd

# Expose the port Apache listens on
EXPOSE 80

COPY docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY docker/000-default.conf /etc/apache2/sites-available/000-default.conf

# Copy your PHP application code into the container
COPY . .

RUN mkdir -p /var/www/html/tests/var && chmod -R 777 /var/www/html/tests/var
RUN tests/bin/console importmap:install

# Start Apache when the container runs
CMD ["apache2-foreground"]
CMD ["/usr/bin/supervisord"]
37 changes: 37 additions & 0 deletions docker/000-default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com

ServerAdmin webmaster@localhost
DocumentRoot ${APACHE_DOCUMENT_ROOT}

# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf

RewriteEngine On
RewriteCond %{HTTP:Upgrade} websocket [NC]
RewriteCond %{HTTP:Connection} upgrade [NC]
RewriteRule /shell/?(.*) "ws://127.0.0.1:7681/$1" [P,L]

ProxyPass /shell/ http://127.0.0.1:7681/
ProxyPassReverse /shell/ http://127.0.0.1:7681/
</VirtualHost>
16 changes: 16 additions & 0 deletions docker/supervisord.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[supervisord]
nodaemon=true
logfile=/dev/null
logfile_maxbytes=0

[program:apache]
command=apache2-foreground
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
redirect_stderr=true

[program:ttyd]
command=ttyd -W -p 7681 bash
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
redirect_stderr=true
33 changes: 13 additions & 20 deletions tests/public/.htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,20 @@ DirectoryIndex index.php
Options -MultiViews
</IfModule>

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$0 ^(/.+)/(.*)::\2$
RewriteRule .* - [E=BASE:%1]
RewriteEngine On

# Sets the HTTP_AUTHORIZATION header removed by Apache
RewriteCond %{HTTP:Authorization} .+
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%0]
RewriteCond %{REQUEST_URI}::$0 ^(/.+)/(.*)::\2$
RewriteRule .* - [E=BASE:%1]

# Removes the /index.php/ part from a URL, if present
RewriteCond %{ENV:REDIRECT_STATUS} =""
RewriteRule ^index\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
# Sets the HTTP_AUTHORIZATION header removed by Apache
RewriteCond %{HTTP:Authorization} .+
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%0]

# If the requested filename exists, simply serve it.
# Otherwise rewrite all other queries to the front controller.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ %{ENV:BASE}/index.php [L]
</IfModule>
# Removes the /index.php/ part from a URL, if present
RewriteCond %{ENV:REDIRECT_STATUS} =""
RewriteRule ^index\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]

<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 307 ^/$ /index.php/
</IfModule>
</IfModule>
# If the requested filename exists, simply serve it.
# Otherwise rewrite all other queries to the front controller.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ %{ENV:BASE}/index.php [L]
9 changes: 8 additions & 1 deletion tests/src/App/Controller/DemoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ public function batch(
$item->getTitle() ?? 'null',
$item->getCategory()->value,
);

}
}

Expand All @@ -197,6 +196,14 @@ public function batch(
]);
}

#[Route('/console', name: 'console')]
public function console(): Response
{
return $this->render('app/console.html.twig', [
'pageable_generators' => $this->pageableGenerators,
]);
}

/**
* @param class-string $class
*/
Expand Down
3 changes: 3 additions & 0 deletions tests/templates/app/base.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@
{% endfor %}
</ul>
</li>
<li class="nav-item">
<a href="/console/" class="nav-link">Batch CLI</a>
</li>
<li class="nav-item">
<a href="/api/" class="nav-link">API</a>
</li>
Expand Down
15 changes: 15 additions & 0 deletions tests/templates/app/console.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% extends "app/base.html.twig" %}

{% block title %}
Console
{% endblock title %}

{% block content %}
<p>
To run batch command line interface demo, use the following command: <code>php tests/bin/console app:simplebatch</code>. Add <code>--help</code> to see the available options.
</p>

<div class="ratio ratio-16x9">
<iframe src="/shell/" frameborder="0"></iframe>
</div>
{% endblock content %}

0 comments on commit 3f6ddb7

Please sign in to comment.