Skip to content

Commit 270fdb3

Browse files
authored
Merge pull request #371 from jolicode/cron
Fix cookbook for cron
2 parents 0c24032 + 527abe2 commit 270fdb3

1 file changed

Lines changed: 25 additions & 9 deletions

File tree

README.md

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -707,25 +707,34 @@ RUN apt-get update \
707707
708708
COPY --link cron/crontab /etc/cron.d/crontab
709709
COPY --link cron/entrypoint.sh /entrypoint.sh
710-
RUN crontab /etc/cron.d/crontab
711-
712-
ENTRYPOINT [ "/entrypoint.sh" ]
710+
ENTRYPOINT ["/entrypoint.sh"]
713711
714712
CMD ["cron", "-f"]
715713
```
716714

717715
And 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

722720
And 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
730739
exec "$@"
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
```

0 commit comments

Comments
 (0)