File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -707,25 +707,34 @@ RUN apt-get update \
707707
708708COPY --link cron/crontab /etc/cron.d/crontab
709709COPY --link cron/entrypoint.sh /entrypoint.sh
710- RUN crontab /etc/cron.d/crontab
711-
712- ENTRYPOINT [ "/entrypoint.sh" ]
710+ ENTRYPOINT ["/entrypoint.sh"]
713711
714712CMD ["cron", "-f"]
715713` ` `
716714
717715And you can add all your crons in the `services/php/crontab` file :
718716` ` ` crontab
719- * * * * * su app -c "/usr/local/bin/ php -r 'echo time().PHP_EOL;'" > /proc/1/fd/1 2>&1
717+ * * * * * php -r 'echo time().PHP_EOL;' > /tmp/cron-stdout 2>&1
720718` ` `
721719
722720And you can add the following content to the `services/php/entrypoint.sh` file :
723721` ` ` bash
724- #!/usr/bin/env bash
722+ #!/bin/bash
723+ set -e
724+
725+ groupadd -g $USER_ID app
726+ useradd -M -u $USER_ID -g $USER_ID -s /bin/bash app
725727
726- if ! id -u ${USER_ID} &>/dev/null; then
727- useradd -u ${USER_ID} -o -m -s /bin/bash ${USER_ID}
728- fi
728+ crontab -u app /etc/cron.d/crontab
729+
730+ # Wrapper for logs
731+ FIFO=/tmp/cron-stdout
732+ rm -f $FIFO
733+ mkfifo $FIFO
734+ chmod 0666 $FIFO
735+ while true; do
736+ cat /tmp/cron-stdout
737+ done &
729738
730739exec "$@"
731740` ` `
@@ -737,10 +746,17 @@ services:
737746 build:
738747 context: services/php
739748 target: cron
749+ cache_from:
750+ - "type=registry,ref=${REGISTRY:-}/cron:cache"
751+ # depends_on:
752+ # postgres:
753+ # condition: service_healthy
754+ env_file: .env
740755 environment:
741- - " USER_ID= ${USER_ID}"
756+ USER_ID: ${USER_ID}
742757 volumes:
743758 - "../..:/var/www:cached"
759+ - "../../.home:/home/app:cached"
744760 profiles:
745761 - default
746762` ` `
You can’t perform that action at this time.
0 commit comments