[FEAT] Run in a Docker container
This commit is contained in:
12
Dockerfile
Normal file
12
Dockerfile
Normal file
@@ -0,0 +1,12 @@
|
||||
FROM php:latest
|
||||
RUN apt-get update && apt-get install cron -y
|
||||
COPY autosave.php /srv/autosave.php
|
||||
COPY autosave.cron /srv/autosave.cron
|
||||
COPY entrypoint.sh /srv/entrypoint.sh
|
||||
RUN chmod 0600 /srv/autosave.cron
|
||||
RUN chmod 0700 /srv/entrypoint.sh
|
||||
RUN crontab /srv/autosave.cron
|
||||
WORKDIR /srv
|
||||
RUN docker-php-ext-install bcmath
|
||||
RUN printenv | grep -v "no_proxy" >> /etc/environment
|
||||
ENTRYPOINT /srv/entrypoint.sh
|
||||
3
autosave.cron
Normal file
3
autosave.cron
Normal file
@@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
|
||||
0 * * * * /usr/local/bin/php /srv/autosave.php --account=$SRC_ACCOUNT --destination=$DST_ACCOUNT --amount=$AMOUNT --days=$DAYS > /proc/1/fd/1 2>/proc/1/fd/2
|
||||
@@ -29,8 +29,9 @@ bcscale(12);
|
||||
* Keep in mind that running this script is entirely AT YOUR OWN RISK with ZERO GUARANTEES.
|
||||
*/
|
||||
|
||||
const EXCLUDED_TAGS = 'Direct debit';
|
||||
const FIREFLY_III_TOKEN = 'ey...';
|
||||
define('EXCLUDED_TAGS', (string)((getenv('EXCLUDED_TAGS') !== false) ? getenv('EXCLUDED_TAGS') : ''));
|
||||
define('FIREFLY_III_TOKEN', (string)((getenv('FIREFLY_III_TOKEN') !== false) ? getenv('FIREFLY_III_TOKEN') : 'ey...'));
|
||||
define('FIREFLY_III_URL', (string)((getenv('FIREFLY_III_URL') !== false) ? getenv('FIREFLY_III_URL') : 'https://firefly-iii.org'));
|
||||
|
||||
/*
|
||||
* HERE BE MONSTERS
|
||||
@@ -136,6 +137,7 @@ function createAutoSaveTransaction(array $group, array $arguments): void
|
||||
));
|
||||
return;
|
||||
}
|
||||
|
||||
// create transaction:
|
||||
$submission = [
|
||||
'transactions' => [
|
||||
@@ -151,6 +153,7 @@ function createAutoSaveTransaction(array $group, array $arguments): void
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
// submit:
|
||||
$result = postCurlRequest('/api/v1/transactions', $submission);
|
||||
$groupId = $result['data']['id'];
|
||||
@@ -285,7 +288,7 @@ function getTransactions(int $accountId): array
|
||||
$tags = $transaction['tags'];
|
||||
$noExcludedTags = true;
|
||||
foreach (explode(";", EXCLUDED_TAGS) as $excludedTag) {
|
||||
if (in_array($tags, $excludedTag)) {
|
||||
if (in_array($excludedTag, $tags)) {
|
||||
$noExcludedTags = false;
|
||||
}
|
||||
}
|
||||
|
||||
13
docker-compose.yml
Normal file
13
docker-compose.yml
Normal file
@@ -0,0 +1,13 @@
|
||||
version: '3.3'
|
||||
services:
|
||||
php-cron:
|
||||
image: fireflyiii-autosave-cron
|
||||
build: .
|
||||
environment:
|
||||
FIREFLY_III_TOKEN: 'ey...'
|
||||
FIREFLY_III_URL: 'https://firefly-iii.org'
|
||||
EXCLUDED_TAGS:
|
||||
SRC_ACCOUNT: 1
|
||||
DST_ACCOUNT: 2
|
||||
AMOUNT: 1
|
||||
DAYS: 1
|
||||
4
entrypoint.sh
Normal file
4
entrypoint.sh
Normal file
@@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
|
||||
printenv | grep -v "no_proxy" >> /etc/environment
|
||||
cron -f
|
||||
Reference in New Issue
Block a user