Skip to content

Commit

Permalink
Add cron containers to support running regular crontab
Browse files Browse the repository at this point in the history
  • Loading branch information
derschatta committed Nov 23, 2018
1 parent c51a5a4 commit af76d4b
Show file tree
Hide file tree
Showing 21 changed files with 293 additions and 5 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.docker-sync
.env
.env
!.gitkeep
/cron.d/*.cron
27 changes: 23 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,10 @@ Make sure your config file contains the PHPUnit configuration needed and the dat
Log into one of the PHP containers:
```bash
tbash php-5.6
tbash php-7.1
tbash php-7.2
# or if you need xdebug support
tbash php-5.6-debug
tbash php-7.1-debug
tbash php-7.2-debug
```

If your project is in a subfolder:
Expand All @@ -294,10 +294,10 @@ Make sure your config file contains the Behat configuration needed and the datab
Log into one of the PHP containers:
```bash
tbash php-5.6
tbash php-7.1
tbash php-7.2
# or if you need xdebug support
tbash php-5.6-debug
tbash php-7.1-debug
tbash php-7.2-debug
```

If your project is in a subfolder:
Expand Down Expand Up @@ -329,6 +329,25 @@ tbuild
tbuild php-7.2
```

## Running Cron

You can run the cron manually by logging into a php container and run `php admin/cli/cron.php` from your source root.

You can also use the cron containers to run the cron automatically using crontab. Just create your own crontab files within the `cron.d` folder and start a cron container like:

```bash
tdocker run php-7.2-cron

# or daemonized in the background
tdocker run -d php-7.2-cron

# you can access the logs anytime with
docker logs -f [name/id of container]

# to stop a daemonized cron container
docker kill [name/id of container]
```

## Mailcatcher

The setup comes with mailcatcher support. Just add the following to your config and all mails will be sent to it:
Expand Down
1 change: 1 addition & 0 deletions cron.d/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Add any .cron file or multiple .cron fils with your crontabs here in this folder
7 changes: 7 additions & 0 deletions cron.d/mycrontab.cron.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# You can use this crontab as a template just copy it to mycrontab.cron and run the container
# The part "> /proc/1/fd/1 2>/proc/1/fd/2" makes sure the output goes to the docker logs

# keep this line for ensuring the correct bin paths for all containers
PATH=$PATH:/usr/bin:/usr/local/bin

* * * * * cd /var/www/totara/src && php admin/cli/cron.php > /proc/1/fd/1 2>/proc/1/fd/2
21 changes: 21 additions & 0 deletions docker-compose-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ services:
php-5.4-debug:
build: ./php/php54-debug

php-5.4-cron:
build: ./php/php54-cron

php-5.5:
build:
context: ./php/php55
Expand All @@ -25,6 +28,9 @@ services:
php-5.5-debug:
build: ./php/php55-debug

php-5.5-cron:
build: ./php/php55-cron

php-5.6:
build:
context: ./php/php56
Expand All @@ -34,6 +40,9 @@ services:
php-5.6-debug:
build: ./php/php56-debug

php-5.6-cron:
build: ./php/php56-cron

php-7.0:
build:
context: ./php/php70
Expand All @@ -43,6 +52,9 @@ services:
php-7.0-debug:
build: ./php/php70-debug

php-7.0-cron:
build: ./php/php70-cron

php-7.1:
build:
context: ./php/php71
Expand All @@ -52,6 +64,9 @@ services:
php-7.1-debug:
build: ./php/php71-debug

php-7.1-cron:
build: ./php/php71-cron

php-7.2:
build:
context: ./php/php72
Expand All @@ -61,6 +76,9 @@ services:
php-7.2-debug:
build: ./php/php72-debug

php-7.2-cron:
build: ./php/php72-cron

php-7.3:
build:
context: ./php/php73
Expand All @@ -69,3 +87,6 @@ services:

php-7.3-debug:
build: ./php/php73-debug

php-7.3-cron:
build: ./php/php73-cron
28 changes: 28 additions & 0 deletions docker-compose-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ services:
volumes:
- totara-www-sync:${REMOTE_SRC}:nocopy

php-5.4-cron:
volumes:
- totara-www-sync:${REMOTE_SRC}:nocopy

php-5.5:
volumes:
- totara-www-sync:${REMOTE_SRC}:nocopy
Expand All @@ -21,6 +25,10 @@ services:
volumes:
- totara-www-sync:${REMOTE_SRC}:nocopy

php-5.5-cron:
volumes:
- totara-www-sync:${REMOTE_SRC}:nocopy

php-5.6:
volumes:
- totara-www-sync:${REMOTE_SRC}:nocopy
Expand All @@ -29,6 +37,10 @@ services:
volumes:
- totara-www-sync:${REMOTE_SRC}:nocopy

php-5.6-cron:
volumes:
- totara-www-sync:${REMOTE_SRC}:nocopy

php-7.0:
volumes:
- totara-www-sync:${REMOTE_SRC}:nocopy
Expand All @@ -37,6 +49,10 @@ services:
volumes:
- totara-www-sync:${REMOTE_SRC}:nocopy

php-7.0-cron:
volumes:
- totara-www-sync:${REMOTE_SRC}:nocopy

php-7.1:
volumes:
- totara-www-sync:${REMOTE_SRC}:nocopy
Expand All @@ -45,6 +61,10 @@ services:
volumes:
- totara-www-sync:${REMOTE_SRC}:nocopy

php-7.1-cron:
volumes:
- totara-www-sync:${REMOTE_SRC}:nocopy

php-7.2:
volumes:
- totara-www-sync:${REMOTE_SRC}:nocopy
Expand All @@ -53,6 +73,10 @@ services:
volumes:
- totara-www-sync:${REMOTE_SRC}:nocopy

php-7.2-cron:
volumes:
- totara-www-sync:${REMOTE_SRC}:nocopy

php-7.3:
volumes:
- totara-www-sync:${REMOTE_SRC}:nocopy
Expand All @@ -61,6 +85,10 @@ services:
volumes:
- totara-www-sync:${REMOTE_SRC}:nocopy

php-7.3-cron:
volumes:
- totara-www-sync:${REMOTE_SRC}:nocopy

nodejs:
volumes:
- totara-www-sync:${REMOTE_SRC}:nocopy
Expand Down
70 changes: 70 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ services:
networks:
- totara

php-5.4-cron:
image: totara/docker-dev-php54-cron
container_name: totara_php54_cron
volumes:
- ${LOCAL_SRC}:${REMOTE_SRC}
- totara-data:${REMOTE_DATA}
- ./cron.d:/etc/cron.d
networks:
- totara

php-5.5:
image: totara/docker-dev-php55
container_name: totara_php55
Expand Down Expand Up @@ -94,6 +104,16 @@ services:
networks:
- totara

php-5.5-cron:
image: totara/docker-dev-php55-cron
container_name: totara_php55_cron
volumes:
- ${LOCAL_SRC}:${REMOTE_SRC}
- totara-data:${REMOTE_DATA}
- ./cron.d:/etc/cron.d
networks:
- totara

php-5.6:
image: totara/docker-dev-php56
container_name: totara_php56
Expand Down Expand Up @@ -124,6 +144,16 @@ services:
networks:
- totara

php-5.6-cron:
image: totara/docker-dev-php56-cron
container_name: totara_php56_cron
volumes:
- ${LOCAL_SRC}:${REMOTE_SRC}
- totara-data:${REMOTE_DATA}
- ./cron.d:/etc/cron.d
networks:
- totara

php-7.0:
image: totara/docker-dev-php70
container_name: totara_php70
Expand Down Expand Up @@ -154,6 +184,16 @@ services:
networks:
- totara

php-7.0-cron:
image: totara/docker-dev-php70-cron
container_name: totara_php70_cron
volumes:
- ${LOCAL_SRC}:${REMOTE_SRC}
- totara-data:${REMOTE_DATA}
- ./cron.d:/etc/cron.d
networks:
- totara

php-7.1:
image: totara/docker-dev-php71
container_name: totara_php71
Expand Down Expand Up @@ -184,6 +224,16 @@ services:
networks:
- totara

php-7.1-cron:
image: totara/docker-dev-php71-cron
container_name: totara_php71_cron
volumes:
- ${LOCAL_SRC}:${REMOTE_SRC}
- totara-data:${REMOTE_DATA}
- ./cron.d:/etc/cron.d
networks:
- totara

php-7.2:
image: totara/docker-dev-php72
container_name: totara_php72
Expand Down Expand Up @@ -214,6 +264,16 @@ services:
networks:
- totara

php-7.2-cron:
image: totara/docker-dev-php72-cron
container_name: totara_php72_cron
volumes:
- ${LOCAL_SRC}:${REMOTE_SRC}
- totara-data:${REMOTE_DATA}
- ./cron.d:/etc/cron.d
networks:
- totara

php-7.3:
image: totara/docker-dev-php73
container_name: totara_php73
Expand Down Expand Up @@ -244,6 +304,16 @@ services:
networks:
- totara

php-7.3-cron:
image: totara/docker-dev-php73-cron
container_name: totara_php73_cron
volumes:
- ${LOCAL_SRC}:${REMOTE_SRC}
- totara-data:${REMOTE_DATA}
- ./cron.d:/etc/cron.d
networks:
- totara

nodejs:
image: node:8.11
container_name: totara_nodejs
Expand Down
9 changes: 9 additions & 0 deletions php/php54-cron/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM totara/docker-dev-php54:latest

RUN apt-get update && apt-get install -y cron

COPY entrypoint.sh /entrypoint.sh

RUN chmod +x /entrypoint.sh

CMD /entrypoint.sh
11 changes: 11 additions & 0 deletions php/php54-cron/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

if [ -e /etc/cron.d/*.cron ]
then
# Install new crontab using all .cron files
cat /etc/cron.d/*.cron | crontab - \
&& crontab -l \
&& cron -f
else
echo "No .cron files found in cron.d folder"
fi
9 changes: 9 additions & 0 deletions php/php55-cron/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM totara/docker-dev-php55:latest

RUN apt-get update && apt-get install -y cron

COPY entrypoint.sh /entrypoint.sh

RUN chmod +x /entrypoint.sh

CMD /entrypoint.sh
11 changes: 11 additions & 0 deletions php/php55-cron/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

if [ -e /etc/cron.d/*.cron ]
then
# Install new crontab using all .cron files
cat /etc/cron.d/*.cron | crontab - \
&& crontab -l \
&& cron -f
else
echo "No .cron files found in cron.d folder"
fi
9 changes: 9 additions & 0 deletions php/php56-cron/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM totara/docker-dev-php56:latest

RUN apt-get update && apt-get install -y cron

COPY entrypoint.sh /entrypoint.sh

RUN chmod +x /entrypoint.sh

CMD /entrypoint.sh
Loading

0 comments on commit af76d4b

Please sign in to comment.