From 59b5cc1998dcc0f44a5777db92119f465b398311 Mon Sep 17 00:00:00 2001 From: Pezhvak Date: Mon, 16 Jan 2023 20:45:07 +0330 Subject: [PATCH] Merge for v1.0.1 (#4) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Create LICENSE * added dockerfile * added gitginore * removed node-yarn from scripts * added start-container * fixed user and group add * updated readme, removed unnecessary deps * add deployer to sudoers * adding wheel to deployer group * adding wheel to deployer group * adding sudo * adding sudo * adding deployer to wheel * adding deployer to wheel * adding deployer to wheel * adding deployer to wheel * adding deployer to wheel * adding deployer to wheel * adding deployer to wheel * adding deployer to wheel * added exif to the php extensions * Proofread (#1) ✍️ Fixed some typos * updated readme.md to migrate to laramatics/container * Updated readme for cron jobs * Renamed cron settings and executable file * changed scripts path from local to global * Changed nginx-php supervisor configuration name. * Added start-worker script * Added start-worker script to Dockerfile * we won't cleanup install-php-extensions for CI to be able to add more extensions * Update README.md Added FAQ section * Updated PHP to 8.2.1 Co-authored-by: A.Ansari <38251019+ardavan-ansari@users.noreply.github.com> Co-authored-by: root --- Dockerfile | 15 +++++++++++---- README.md | 8 ++++++++ configs/crontab.txt | 1 + scripts/cleanup.sh | 5 +++-- scripts/start-cron | 2 ++ scripts/start-worker | 7 +++++++ 6 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 configs/crontab.txt create mode 100644 scripts/start-cron create mode 100644 scripts/start-worker diff --git a/Dockerfile b/Dockerfile index b1bfbba..690c88c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -ARG PHP_VERSION=8.1.1 +ARG PHP_VERSION=8.2.1 FROM php:${PHP_VERSION}-fpm-alpine LABEL maintainer="Pezhvak " # NOTE: ARGs before FROM cannot be accessed during build time (https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact) @@ -12,8 +12,12 @@ RUN chmod +x /usr/local/bin/install-php-extensions # Copy Scripts COPY scripts /tmp RUN chmod +x /tmp/*.sh -COPY scripts/start-container /usr/local/bin -RUN chmod +x /usr/local/bin/start-container +COPY scripts/start-container /usr/bin +COPY scripts/start-cron /usr/bin +COPY scripts/start-worker /usr/bin +RUN chmod +x /usr/bin/start-container +RUN chmod +x /usr/bin/start-cron +RUN chmod +x /usr/bin/start-worker # Install RUN ash /tmp/install-packages.sh @@ -32,10 +36,13 @@ RUN rm -rf /tmp/* EXPOSE 80 # Services supervisor config -COPY ./configs/supervisord.conf /etc/supervisor.d/supervisord.conf +COPY ./configs/supervisord.conf /etc/supervisor.d/php-nginx.conf # Override nginx's default config COPY ./configs/nginx.conf /etc/nginx/http.d/default.conf +# Set crontab configurations +COPY ./configs/crontab.txt /etc/crontabs/root + CMD ["/usr/bin/supervisord", "-n","-c", "/etc/supervisord.conf"] ENTRYPOINT ["start-container"] diff --git a/README.md b/README.md index f0e4fa6..74b951f 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,7 @@ Although folder structure is self-explanatory, description is below: ``` . ├── configs +│   ├── crontab.txt # crontab configuration file. │   ├── nginx.conf # default nginx configuration file. │   └── supervisord.conf # php/nginx supervisor configuration file. ├── Dockerfile @@ -72,6 +73,7 @@ Although folder structure is self-explanatory, description is below: │   ├── install-packages.sh # OS packages will be installed by this file. │   ├── install-php.sh # PHP extensions and installation. │   └── start-container # Container entry-point script. +│   └── start-cron # Running container with cron job role. └── tests └── goss.yaml # See "testing" section. ``` @@ -136,3 +138,9 @@ modifying source files and building your own image, run: ```shell GOSS_FILES_PATH=tests dgoss run -it /bin/ash -l ``` + +### FAQ + +*Q:* How can i change php-fpm port? + +*A:* Sometimes you need to change default php-fpm port which is 9000 in order to serve multiple containers under same pod. to do that modify the port in `/usr/local/etc/php-fpm.d/zz-docker.conf`. diff --git a/configs/crontab.txt b/configs/crontab.txt new file mode 100644 index 0000000..4855dbc --- /dev/null +++ b/configs/crontab.txt @@ -0,0 +1 @@ +* * * * * cd /var/www/html && php artisan schedule:run >> /dev/stdout 2>&1 \ No newline at end of file diff --git a/scripts/cleanup.sh b/scripts/cleanup.sh index 1bc0d50..d693b80 100644 --- a/scripts/cleanup.sh +++ b/scripts/cleanup.sh @@ -2,5 +2,6 @@ # Remove Build Dependencies apk del -f .build-deps -rm /usr/local/bin/install-php-extensions -rm /usr/local/bin/docker-php-* +# we need these for adding extra extensions in CI +# rm /usr/local/bin/install-php-extensions +# rm /usr/local/bin/docker-php-* diff --git a/scripts/start-cron b/scripts/start-cron new file mode 100644 index 0000000..d56a8c3 --- /dev/null +++ b/scripts/start-cron @@ -0,0 +1,2 @@ +#!/usr/bin/env ash +crond -f \ No newline at end of file diff --git a/scripts/start-worker b/scripts/start-worker new file mode 100644 index 0000000..b670822 --- /dev/null +++ b/scripts/start-worker @@ -0,0 +1,7 @@ +#!/usr/bin/env ash + +if [ $# -gt 0 ]; then + exec exec /usr/local/bin/php /var/www/html/artisan queue:work "$@" +else + exec /usr/local/bin/php /var/www/html/artisan queue:work --timeout=3600 --tries=3 --no-interaction +fi