Skip to content

Instantly share code, notes, and snippets.

@kiddtang
Last active July 11, 2022 11:34
Show Gist options
  • Save kiddtang/1ceefed044278a3c7aa0ff4533803fd5 to your computer and use it in GitHub Desktop.
Save kiddtang/1ceefed044278a3c7aa0ff4533803fd5 to your computer and use it in GitHub Desktop.
Laravel Sail with HTTPS Swoole
OCTANE_SERVER=swoole
OCTANE_HTTPS=true
SWOOLE_SOCK_TCP | ((bool) $config['swoole']['ssl'] ?? 0) * SWOOLE_SSL,
ports:
- '${APP_PORT:-80}:80'
- 8000:8000
FROM ubuntu:21.04
LABEL maintainer="Taylor Otwell"
ARG WWWGROUP
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 \
&& 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 hirsute main" > /etc/apt/sources.list.d/ppa_ondrej_php.list \
&& apt-get update \
&& apt-get install -y php8.0-cli php8.0-dev \
php8.0-pgsql php8.0-sqlite3 php8.0-gd \
php8.0-curl php8.0-memcached \
php8.0-imap php8.0-mysql php8.0-mbstring \
php8.0-xml php8.0-zip php8.0-bcmath php8.0-soap \
php8.0-intl php8.0-readline php8.0-pcov \
php8.0-msgpack php8.0-igbinary php8.0-ldap \
php8.0-redis php8.0-swoole \
&& php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer \
&& curl -sL https://deb.nodesource.com/setup_16.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 setcap "cap_net_bind_service=+ep" /usr/bin/php8.0
RUN groupadd --force -g $WWWGROUP sail
RUN useradd -ms /bin/bash --no-user-group -g $WWWGROUP -u 1337 sail
RUN mkdir -p /etc/swoole/ssl/certs/ /etc/swoole/ssl/private/
RUN openssl req -x509 -nodes -days 365 -subj "/C=CA/ST=QC/O=Artisan, Inc./CN=localhost" \
-addext "subjectAltName=DNS:localhost" -newkey rsa:2048 \
-keyout /etc/swoole/ssl/private/sail-selfsigned.key \
-out /etc/swoole/ssl/certs/sail-selfsigned.crt;
RUN chmod 644 /etc/swoole/ssl/certs/*.crt
RUN chown -R root:sail /etc/swoole/ssl/private/
RUN chmod 640 /etc/swoole/ssl/private/*.key
COPY start-container /usr/local/bin/start-container
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY php.ini /etc/php/8.0/cli/conf.d/99-sail.ini
RUN chmod +x /usr/local/bin/start-container
EXPOSE 8000
ENTRYPOINT ["start-container"]
RUN mkdir -p /etc/swoole/ssl/certs/ /etc/swoole/ssl/private/
RUN openssl req -x509 -nodes -days 365 -subj "/C=CA/ST=QC/O=Artisan, Inc./CN=localhost" \
-addext "subjectAltName=DNS:localhost" -newkey rsa:2048 \
-keyout /etc/swoole/ssl/private/sail-selfsigned.key \
-out /etc/swoole/ssl/certs/sail-selfsigned.crt;
RUN chmod 644 /etc/swoole/ssl/certs/*.crt
RUN chown -R root:sail /etc/swoole/ssl/private/
RUN chmod 640 /etc/swoole/ssl/private/*.key
/*
|--------------------------------------------------------------------------
| Octane Swoole Configuration Options
|--------------------------------------------------------------------------
|
| While using Swoole, you may define additional configuration options as
| required by the application. You maycheck which options you need from:
| https://www.swoole.co.uk/docs/modules/swoole-server/configuration
|
*/
'swoole' => [
'ssl' => true,
'options' => [
'ssl_cert_file' => '/etc/swoole/ssl/certs/sail-selfsigned.crt',
'ssl_key_file' => '/etc/swoole/ssl/private/sail-selfsigned.key',
]
],
command=/usr/bin/php -d variables_order=EGPCS /var/www/html/artisan octane:start --server=swoole --host=0.0.0.0 --port=8000 --watch
@kodmanyagha
Copy link

kodmanyagha commented Jul 11, 2022

This is causing swoole ssl error becouse swoole can not access to /etc/swoole/ssl/certs/sail-selfsigned.crt file. Because of permissions. I changed these lines to that and everything is working perfect now:

Dockerfile  line 54 must be changed like that:

RUN chmod 655 /etc/swoole/ssl/certs/*.crt
RUN chown -R root:sail /etc/swoole/ssl/
RUN chmod 655 /etc/swoole/ssl/private/*.key

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment