Skip to content

Instantly share code, notes, and snippets.

@lotharthesavior
Last active May 16, 2022 04:37
Show Gist options
  • Save lotharthesavior/11da78708560e601651b3a227bce21c8 to your computer and use it in GitHub Desktop.
Save lotharthesavior/11da78708560e601651b3a227bce21c8 to your computer and use it in GitHub Desktop.
OpenSwoole Docker Dev Environment
FROM ubuntu:20.04
ARG WWWGROUP
ARG SUPERVISOR_CONF
WORKDIR /var/www/html
ENV DEBIAN_FRONTEND noninteractive
ENV TZ=UTC
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN apt-get update \
&& apt-get install -y gnupg gosu curl ca-certificates zip unzip git supervisor sqlite3 libcap2-bin libpng-dev python2 libcurl4-openssl-dev \
&& mkdir -p ~/.gnupg \
&& chmod 600 ~/.gnupg \
&& echo "disable-ipv6" >> ~/.gnupg/dirmngr.conf \
&& apt-key adv --homedir ~/.gnupg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys E5267A6C \
&& apt-key adv --homedir ~/.gnupg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C300EE8C \
&& echo "deb http://ppa.launchpad.net/ondrej/php/ubuntu focal main" > /etc/apt/sources.list.d/ppa_ondrej_php.list \
&& apt-get update \
&& apt-get install -y php8.1-cli php8.1-dev \
php8.1-pgsql php8.1-sqlite3 php8.1-gd \
php8.1-curl php8.1-memcached \
php8.1-imap php8.1-mysql php8.1-mbstring \
php8.1-xml php8.1-zip php8.1-bcmath php8.1-soap \
php8.1-intl php8.1-readline \
php8.1-msgpack php8.1-igbinary php8.1-ldap \
php8.1-redis \
&& php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer \
&& curl -sL https://deb.nodesource.com/setup_15.x | bash - \
&& apt-get install -y nodejs \
&& curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list \
&& apt-get update \
&& apt-get install -y yarn \
&& apt-get install -y mysql-client \
&& apt-get install -y postgresql-client \
&& apt-get -y autoremove \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN pecl channel-update https://pecl.php.net/channel.xml \
&& pecl install --configureoptions 'enable-sockets="yes" enable-openssl="yes" enable-http2="yes" enable-mysqlnd="yes" enable-swoole-json="yes" enable-swoole-curl="yes"' openswoole
RUN apt update
RUN apt install inotify-tools -y
RUN pecl install inotify
RUN touch /etc/php/8.1/cli/conf.d/inotify.ini
RUN echo "extension=inotify.so" > /etc/php/8.1/cli/conf.d/inotify.ini
RUN setcap "cap_net_bind_service=+ep" /usr/bin/php8.1
COPY start-container /usr/local/bin/start-container
COPY $SUPERVISOR_CONF /etc/supervisor/conf.d/supervisord.conf
COPY php.ini /etc/php/8.1/cli/conf.d/99-wt.ini
RUN chmod +x /usr/local/bin/start-container
COPY inotify.sh /inotify.sh
RUN chmod +x /inotify.sh
EXPOSE 8001
EXPOSE 8002
ENTRYPOINT ["start-container"]
#!/usr/bin/env bash
WORK_DIR=$1
if [ ! -n "${WORK_DIR}" ] ;then
WORK_DIR="."
fi
echo "Starting inotifywait..."
LOCKING=0
inotifywait --event modify --event create --event move --event delete -mrq ${WORK_DIR} | while read file
do
if [[ ! ${file} =~ .php$ ]] ;then
continue
fi
if [ ${LOCKING} -eq 1 ] ;then
echo "Reloading, skipped."
continue
fi
echo "File ${file} has been modified."
LOCKING=1
kill -9 $(cat ./http-server-pid)
kill -9 $(cat ./ws-server-pid)
rm -f ./http-server-pid
rm -f ./ws-server-pid
LOCKING=0
done
exit 0
[PHP]
post_max_size = 100M
upload_max_filesize = 100M
variables_order = EGPCS
# Extensions...
extension=openswoole.so
#!/usr/bin/env bash
if [ ! -d "/var/www/html/vendor" ]; then
composer install
fi
rm -f /var/www/html/http-server-pid
if [ $# -gt 0 ];then
exec gosu $WWWUSER "$@"
else
/usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
fi
[supervisord]
nodaemon=true
user=root
logfile=/var/log/supervisor/supervisord.log
pidfile=/var/run/supervisord.pid
[program:php]
command = /usr/bin/php /var/www/html/index.php
directory = /var/www/html
user = root
autostart = true
autorestart = true
numprocs = 1
loglevel = debug
stdout_logfile = /var/www/html/output.log
stderr_logfile = /var/www/html/error.log
[program:inotify]
command=/usr/bin/bash /inotify.sh /var/www/html
user=root
autostart = true
autorestart = true
numprocs = 1
loglevel = debug
stdout_logfile = /var/www/html/inotify-output.log
stderr_logfile = /var/www/html/inotify-error.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment