Skip to content

Commit

Permalink
Restructure (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
smortexa authored Jan 13, 2024
1 parent 5197b58 commit 94812f7
Show file tree
Hide file tree
Showing 13 changed files with 301 additions and 112 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/roadrunner-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,18 @@ jobs:
working-directory: /var/www/app

- name: Copy required content to dockerize the app
run: sudo cp -R Dockerfile .dockerignore deployment/ /var/www/app/
run: sudo cp -R Dockerfile.RoadRunner .dockerignore deployment/ /var/www/app/

- name: Build image
run: docker build --build-arg OCTANE_SERVER=roadrunner -t app:local -f Dockerfile .
run: docker build -t app:local -f Dockerfile.RoadRunner .
working-directory: /var/www/app

- name: Run the Docker image
run: docker run -d --rm -p 9000:9000 app:local
- name: Run the Docker container
run: docker run -d --rm -p 80:80 app:local
working-directory: /var/www/app

- name: Wait for the container
run: sleep 10s

- name: Check application health
run: curl -f -s -o /dev/null -w "%{http_code}" http://localhost:9000
run: curl -f -s -o /dev/null -w "%{http_code}" http://localhost
10 changes: 5 additions & 5 deletions .github/workflows/swoole-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,18 @@ jobs:
working-directory: /var/www/app

- name: Copy required content to dockerize the app
run: sudo cp -R Dockerfile .dockerignore deployment/ /var/www/app/
run: sudo cp -R Dockerfile.Swoole .dockerignore deployment/ /var/www/app/

- name: Build image
run: docker build -t app:local -f Dockerfile .
run: docker build -t app:local -f Dockerfile.Swoole .
working-directory: /var/www/app

- name: Run the Docker image
run: docker run -d --rm -p 9000:9000 app:local
- name: Run the Docker container
run: docker run -d --rm -p 80:80 app:local
working-directory: /var/www/app

- name: Wait for the container
run: sleep 10s

- name: Check application health
run: curl -f -s -o /dev/null -w "%{http_code}" http://localhost:9000
run: curl -f -s -o /dev/null -w "%{http_code}" http://localhost
205 changes: 205 additions & 0 deletions Dockerfile.RoadRunner
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
# Accepted values: 8.2 - 8.1
ARG PHP_VERSION=8.2

ARG COMPOSER_VERSION=latest

###########################################
# Build frontend assets with NPM
###########################################

ARG NODE_VERSION=20-alpine

FROM node:${NODE_VERSION} as build

ENV ROOT=/var/www/html

WORKDIR ${ROOT}

RUN npm config set update-notifier false && npm set progress=false

COPY package*.json ./

RUN if [ -f $ROOT/package-lock.json ]; \
then \
npm ci --no-optional --loglevel=error --no-audit; \
else \
npm install --no-optional --loglevel=error --no-audit; \
fi

COPY . .

RUN npm run build

###########################################

FROM composer:${COMPOSER_VERSION} AS vendor

FROM php:${PHP_VERSION}-cli-bookworm

LABEL maintainer="Seyed Morteza Ebadi <[email protected]>"

ARG WWWUSER=1000
ARG WWWGROUP=1000
ARG TZ=UTC

ENV DEBIAN_FRONTEND=noninteractive \
TERM=xterm-color \
WITH_HORIZON=false \
WITH_SCHEDULER=false \
OCTANE_SERVER=roadrunner \
NON_ROOT_USER=octane \
ROOT=/var/www/html

WORKDIR ${ROOT}

SHELL ["/bin/bash", "-eou", "pipefail", "-c"]

RUN ln -snf /usr/share/zoneinfo/${TZ} /etc/localtime \
&& echo ${TZ} > /etc/timezone

RUN apt-get update; \
apt-get upgrade -yqq; \
pecl -q channel-update pecl.php.net; \
apt-get install -yqq --no-install-recommends --show-progress \
apt-utils \
gnupg \
git \
curl \
wget \
nano \
rsync \
ncdu \
sqlite3 \
libcurl4-openssl-dev \
ca-certificates \
supervisor \
libmemcached-dev \
libz-dev \
libbrotli-dev \
libpq-dev \
libjpeg-dev \
libpng-dev \
librsvg2-bin \
libfreetype6-dev \
libssl-dev \
libwebp-dev \
libmcrypt-dev \
libldap2-dev \
libonig-dev \
libmagickwand-dev \
libzip-dev zip unzip \
libargon2-1 \
libidn2-0 \
libpcre2-8-0 \
librdkafka-dev \
libpcre3 \
libxml2 \
libxslt-dev \
libzstd1 \
libc-ares-dev \
procps \
postgresql-client \
postgis \
default-mysql-client \
libbz2-dev \
zlib1g-dev \
libicu-dev \
g++ \
# Install PHP extensions
&& docker-php-ext-install \
bz2 \
pcntl \
mbstring \
bcmath \
sockets \
pgsql \
pdo_pgsql \
opcache \
exif \
&& docker-php-ext-configure pdo_mysql && docker-php-ext-install pdo_mysql \
&& docker-php-ext-configure zip && docker-php-ext-install zip \
&& docker-php-ext-configure intl && docker-php-ext-install intl \
&& docker-php-ext-configure gd \
--prefix=/usr \
--with-jpeg \
--with-webp \
--with-freetype && docker-php-ext-install gd \
&& pecl -q install -o -f redis && docker-php-ext-enable redis \
&& pecl -q install -o -f imagick && docker-php-ext-enable imagick \
&& pecl -q install -o -f rdkafka && docker-php-ext-enable rdkafka \
&& pecl -q install -o -f memcached && docker-php-ext-enable memcached \
&& pecl -q install -o -f igbinary && docker-php-ext-enable igbinary \
&& docker-php-ext-configure ldap --with-libdir=lib/$(gcc -dumpmachine) && docker-php-ext-install ldap \
&& apt-get -y autoremove \
&& apt-get clean \
&& docker-php-source delete \
&& pecl clear-cache \
&& rm -R /tmp/pear \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
&& rm /var/log/lastlog /var/log/faillog

RUN wget -q "https://github.com/aptible/supercronic/releases/download/v0.2.29/supercronic-linux-amd64" \
-O /usr/bin/supercronic \
&& chmod +x /usr/bin/supercronic \
&& mkdir -p /etc/supercronic \
&& echo "*/1 * * * * php ${ROOT}/artisan schedule:run --verbose --no-interaction" > /etc/supercronic/laravel

RUN userdel --remove --force www-data \
&& groupadd --force -g ${WWWGROUP} ${NON_ROOT_USER} \
&& useradd -ms /bin/bash --no-log-init --no-user-group -g ${WWWGROUP} -u ${WWWUSER} ${NON_ROOT_USER}

RUN chown -R ${NON_ROOT_USER}:${NON_ROOT_USER} ${ROOT} /var/{log,run}

RUN chmod -R ug+rw /var/{log,run}

USER ${NON_ROOT_USER}

COPY --chown=${NON_ROOT_USER}:${NON_ROOT_USER} --from=vendor /usr/bin/composer /usr/bin/composer
COPY --chown=${NON_ROOT_USER}:${NON_ROOT_USER} composer* ./

RUN composer install \
--no-dev \
--no-interaction \
--no-autoloader \
--no-ansi \
--no-scripts \
--audit

COPY --chown=${NON_ROOT_USER}:${NON_ROOT_USER} . .
COPY --chown=${NON_ROOT_USER}:${NON_ROOT_USER} --from=build ${ROOT}/public public

RUN mkdir -p \
storage/framework/{sessions,views,cache,testing} \
storage/logs \
bootstrap/cache

COPY --chown=${NON_ROOT_USER}:${NON_ROOT_USER} deployment/octane/RoadRunner/supervisord.roadrunner.conf /etc/supervisor/conf.d
COPY --chown=${NON_ROOT_USER}:${NON_ROOT_USER} deployment/supervisord.scheduler.conf /etc/supervisor/conf.d/
COPY --chown=${NON_ROOT_USER}:${NON_ROOT_USER} deployment/supervisord.horizon.conf /etc/supervisor/conf.d/
COPY --chown=${NON_ROOT_USER}:${NON_ROOT_USER} deployment/php.ini /usr/local/etc/php/conf.d/99-octane.ini
COPY --chown=${NON_ROOT_USER}:${NON_ROOT_USER} deployment/octane/RoadRunner/.rr.prod.yaml ./.rr.yaml
COPY --chown=${NON_ROOT_USER}:${NON_ROOT_USER} deployment/start-container /usr/local/bin/start-container

RUN composer install \
--classmap-authoritative \
--no-interaction \
--no-ansi \
--no-dev \
&& composer clear-cache \
&& php artisan storage:link

RUN if composer show | grep spiral/roadrunner-cli >/dev/null; then \
./vendor/bin/rr get-binary; else \
echo "`spiral/roadrunner-cli` package is not installed. Exiting..."; exit 1; \
fi

RUN chmod +x rr /usr/local/bin/start-container

RUN cat deployment/utilities.sh >> ~/.bashrc

EXPOSE 80
EXPOSE 6001

ENTRYPOINT ["start-container"]

HEALTHCHECK --start-period=5s --interval=2s --timeout=5s --retries=8 CMD php artisan octane:status || exit 1
64 changes: 16 additions & 48 deletions Dockerfile → Dockerfile.Swoole
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,14 @@ ARG WWWUSER=1000
ARG WWWGROUP=1000
ARG TZ=UTC

# Accepted values: swoole - roadrunner
ARG OCTANE_SERVER="swoole"

# Accepted values: app - horizon - scheduler
ARG CONTAINER_MODE=app

ARG APP_WITH_HORIZON=false
ARG APP_WITH_SCHEDULER=false

ENV DEBIAN_FRONTEND=noninteractive \
TERM=xterm-color \
CONTAINER_MODE=${CONTAINER_MODE} \
APP_WITH_HORIZON=${APP_WITH_HORIZON} \
APP_WITH_SCHEDULER=${APP_WITH_SCHEDULER} \
OCTANE_SERVER=${OCTANE_SERVER} \
NON_ROOT_USER=octane
WITH_HORIZON=false \
WITH_SCHEDULER=false \
OCTANE_SERVER=swoole \
NON_ROOT_USER=octane \
ROOT=/var/www/html

ENV ROOT=/var/www/html
WORKDIR ${ROOT}

SHELL ["/bin/bash", "-eou", "pipefail", "-c"]
Expand All @@ -78,6 +68,7 @@ RUN apt-get update; \
wget \
nano \
rsync \
ncdu \
sqlite3 \
libcurl4-openssl-dev \
ca-certificates \
Expand Down Expand Up @@ -138,11 +129,8 @@ RUN apt-get update; \
&& pecl -q install -o -f rdkafka && docker-php-ext-enable rdkafka \
&& pecl -q install -o -f memcached && docker-php-ext-enable memcached \
&& pecl -q install -o -f igbinary && docker-php-ext-enable igbinary \
&& pecl -q install -o -f swoole && docker-php-ext-enable swoole \
&& docker-php-ext-configure ldap --with-libdir=lib/$(gcc -dumpmachine) && docker-php-ext-install ldap \
&& if [ ${OCTANE_SERVER} = "swoole" ]; then \
printf "\n" | pecl -q install -o -f -D 'enable-openssl="yes" enable-http2="yes" enable-swoole-curl="yes" enable-mysqlnd="yes" enable-cares="yes"' swoole \
&& docker-php-ext-enable swoole; \
fi \
&& apt-get -y autoremove \
&& apt-get clean \
&& docker-php-source delete \
Expand All @@ -151,20 +139,11 @@ RUN apt-get update; \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
&& rm /var/log/lastlog /var/log/faillog


###########################################
# Laravel scheduler
###########################################

RUN if [ ${CONTAINER_MODE} = 'scheduler' ] || [ ${APP_WITH_SCHEDULER} = true ]; then \
wget -q "https://github.com/aptible/supercronic/releases/download/v0.2.26/supercronic-linux-amd64" \
RUN wget -q "https://github.com/aptible/supercronic/releases/download/v0.2.29/supercronic-linux-amd64" \
-O /usr/bin/supercronic \
&& chmod +x /usr/bin/supercronic \
&& mkdir -p /etc/supercronic \
&& echo "*/1 * * * * php ${ROOT}/artisan schedule:run --verbose --no-interaction" > /etc/supercronic/laravel; \
fi

###########################################
&& echo "*/1 * * * * php ${ROOT}/artisan schedule:run --verbose --no-interaction" > /etc/supercronic/laravel

RUN userdel --remove --force www-data \
&& groupadd --force -g ${WWWGROUP} ${NON_ROOT_USER} \
Expand Down Expand Up @@ -195,10 +174,11 @@ RUN mkdir -p \
storage/logs \
bootstrap/cache

COPY --chown=${NON_ROOT_USER}:${NON_ROOT_USER} deployment/octane/supervisord* /etc/supervisor/conf.d/
COPY --chown=${NON_ROOT_USER}:${NON_ROOT_USER} deployment/octane/php.ini /usr/local/etc/php/conf.d/99-octane.ini
COPY --chown=${NON_ROOT_USER}:${NON_ROOT_USER} deployment/octane/.rr.prod.yaml ./.rr.yaml
COPY --chown=${NON_ROOT_USER}:${NON_ROOT_USER} deployment/octane/start-container /usr/local/bin/start-container
COPY --chown=${NON_ROOT_USER}:${NON_ROOT_USER} deployment/octane/Swoole/supervisord.swoole.conf /etc/supervisor/conf.d/
COPY --chown=${NON_ROOT_USER}:${NON_ROOT_USER} deployment/supervisord.scheduler.conf /etc/supervisor/conf.d/
COPY --chown=${NON_ROOT_USER}:${NON_ROOT_USER} deployment/supervisord.horizon.conf /etc/supervisor/conf.d/
COPY --chown=${NON_ROOT_USER}:${NON_ROOT_USER} deployment/php.ini /usr/local/etc/php/conf.d/99-octane.ini
COPY --chown=${NON_ROOT_USER}:${NON_ROOT_USER} deployment/start-container /usr/local/bin/start-container

RUN composer install \
--classmap-authoritative \
Expand All @@ -208,23 +188,11 @@ RUN composer install \
&& composer clear-cache \
&& php artisan storage:link

RUN if [ ${OCTANE_SERVER} = "roadrunner" ]; then \
if composer show | grep spiral/roadrunner-cli >/dev/null; then \
./vendor/bin/rr get-binary; else \
echo "spiral/roadrunner-cli package is not installed. exiting..."; exit 1; \
fi \
fi

RUN if [ -f "rr" ]; then \
chmod +x rr; \
fi

RUN chmod +x /usr/local/bin/start-container

RUN cat deployment/octane/utilities.sh >> ~/.bashrc
RUN cat deployment/utilities.sh >> ~/.bashrc

EXPOSE 9000
EXPOSE 6001
EXPOSE 80

ENTRYPOINT ["start-container"]

Expand Down
Loading

0 comments on commit 94812f7

Please sign in to comment.