Skip to content

Commit

Permalink
Add scheduler, queue worker and update app
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurpar06 committed Nov 17, 2024
1 parent cc3a059 commit 45da5a1
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 27 deletions.
109 changes: 95 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,104 @@
FROM dunglas/frankenphp
ARG PHP_VERSION=8.3
ARG FRANKENPHP_VERSION=latest

# Be sure to replace "demo.phpvms.net" by your domain name
ENV SERVER_NAME=demo.phpvms.net
FROM dunglas/frankenphp:${FRANKENPHP_VERSION}-php${PHP_VERSION}

# Enable PHP production settings
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
ARG TZ=UTC
ARG APP_DIR=/app

RUN install-php-extensions \
pdo_mysql \
gd \
intl \
opcache \
# IMPORTANT: If you're using a reverse proxy use :80, else set your domain name
ENV SERVER_NAME=:80 \
WITH_SCHEDULER=true \
WITH_HORIZON=true \
USER=www-data \
ROOT=${APP_DIR}

WORKDIR ${ROOT}

# INSTALL DEPS AND PHP EXTESIONS
RUN curl -sL https://deb.nodesource.com/setup_20.x | bash -

RUN apt-get update; \
apt-get upgrade -yqq; \
apt-get install -yqq --no-install-recommends --show-progress \
apt-utils \
curl \
wget \
nano \
git \
ncdu \
procps \
ca-certificates \
supervisor \
libsodium-dev \
unzip \
nodejs \
mariadb-client \
# Install PHP extensions (included with dunglas/frankenphp)
&& install-php-extensions \
@composer \
pcntl \
pdo_mysql \
gd \
intl \
opcache \
mbstring \
json \
bcmath \
gmp \
zip \
redis
redis \
&& apt-get -y autoremove \
&& apt-get clean \
&& docker-php-source delete \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
&& rm /var/log/lastlog /var/log/faillog


RUN arch="$(uname -m)" \
&& case "$arch" in \
armhf) _cronic_fname='supercronic-linux-arm' ;; \
aarch64) _cronic_fname='supercronic-linux-arm64' ;; \
x86_64) _cronic_fname='supercronic-linux-amd64' ;; \
x86) _cronic_fname='supercronic-linux-386' ;; \
*) echo >&2 "error: unsupported architecture: $arch"; exit 1 ;; \
esac \
&& wget -q "https://github.com/aptible/supercronic/releases/download/v0.2.29/${_cronic_fname}" \
-O /usr/bin/supercronic \
&& chmod +x /usr/bin/supercronic \
&& mkdir -p /etc/supercronic \
&& echo "*/1 * * * * php ${ROOT}/artisan schedule:run --no-interaction" > /etc/supercronic/laravel

RUN cp ${PHP_INI_DIR}/php.ini-production ${PHP_INI_DIR}/php.ini

COPY --link --chown=${USER}:${USER} composer.json composer.lock ./

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

COPY --link . .

RUN mkdir -p \
storage/framework/{sessions,views,cache,testing} \
storage/logs \
bootstrap/cache && chmod -R a+rw storage

COPY --link resources/docker/supervisord.conf /etc/supervisor/
COPY --link resources/docker/supervisord.*.conf /etc/supervisor/conf.d/

COPY --link resources/docker/php.ini ${PHP_INI_DIR}/conf.d/99-octane.ini

COPY --link resources/docker/start-task-runner /usr/local/bin/start-task-runner

RUN chmod +x /usr/local/bin/start-task-runner

# FrankenPHP embedded PHP configuration
COPY --link resources/docker/php.ini /lib/php.ini

RUN npm install --loglevel=error --no-audit
RUN npm run production

# Copy the PHP files of your project in the container
COPY . /app
RUN cat resources/docker/utilities.sh >> ~/.bashrc
41 changes: 28 additions & 13 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,25 @@ services:
volumes:
- caddy_data:/data
- caddy_config:/config
- ./modules:/app/modules
- ./public/uploads:/app/public/uploads
- ./storage:/app/storage
- ./.env:/app/.env
networks:
- internal
depends_on:
- mariadb
- redis
- task-runner
task-runner:
build: .
command: start-task-runner
restart: unless-stopped
volumes:
- ./modules:/app/modules
- ./public/uploads:/app/public/uploads
- ./storage:/app/storage
- ./.env:/app/.env
networks:
- internal
depends_on:
Expand All @@ -18,6 +37,7 @@ services:
mariadb:
image: 'mariadb:11'
restart: unless-stopped
# May be useful if someone wants to access the db remotely
ports:
- '${FORWARD_DB_PORT:-3306}:3306'
environment:
Expand All @@ -31,28 +51,23 @@ services:
networks:
- internal
healthcheck:
test:
- CMD
- mysqladmin
- ping
- '-p${DB_PASSWORD}'
retries: 3
test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
start_period: 10s
interval: 10s
timeout: 5s
retries: 3

redis:
image: 'redis:alpine'
restart: unless-stopped
ports:
- '${FORWARD_REDIS_PORT:-6379}:6379'
# ports:
# - '${FORWARD_REDIS_PORT:-6379}:6379'
volumes:
- redis:/data
networks:
- internal
healthcheck:
test:
- CMD
- redis-cli
- ping
test: ["CMD", "redis-cli", "ping"]
retries: 3
timeout: 5s

Expand All @@ -65,4 +80,4 @@ volumes:

networks:
internal:
driver: bridge
driver: bridge

0 comments on commit 45da5a1

Please sign in to comment.